@@ -72,116 +72,3 @@ app.post("/talkjs", async (req, res) => {
72
72
73
73
res . status ( 200 ) . end ( ) ;
74
74
} ) ;
75
-
76
- // EVERYTHING BELOW IS SETUP CODE FOR THIS EXAMPLE
77
- // You won't need any of it in your live app!
78
- //
79
- // It's just here so that you can play around with this example more easily
80
- // Whenever you start the server, we make sure the two example users are created
81
- // recreate the two conversations, and send messages from the example users
82
-
83
- async function setupConversation ( i ) {
84
- const conversationId = `autoReplyExample${ i } ` ;
85
- const userId = `autoReplyExampleUser${ i } ` ;
86
-
87
- // Delete the conversation (if it exists)
88
- await fetch ( `${ basePath } /v1/${ appId } /conversations/${ conversationId } ` , {
89
- method : "delete" ,
90
- headers : {
91
- Authorization : `Bearer ${ secretKey } ` ,
92
- } ,
93
- } ) ;
94
-
95
- // Create a new conversation
96
- await fetch ( `${ basePath } /v1/${ appId } /conversations/${ conversationId } ` , {
97
- method : "put" ,
98
- headers : {
99
- "Content-Type" : "application/json" ,
100
- Authorization : `Bearer ${ secretKey } ` ,
101
- } ,
102
- body : JSON . stringify ( {
103
- participants : [ "autoReplyExampleSupportAgent" , userId ] ,
104
- } ) ,
105
- } ) ;
106
-
107
- // Send a message from the user to make sure it will show up in the conversation list
108
- await fetch (
109
- `${ basePath } /v1/${ appId } /conversations/${ conversationId } /messages` ,
110
- {
111
- method : "post" ,
112
- headers : {
113
- "Content-Type" : "application/json" ,
114
- Authorization : `Bearer ${ secretKey } ` ,
115
- } ,
116
- body : JSON . stringify ( [
117
- {
118
- text : "Everything is broken again!" ,
119
- sender : userId ,
120
- type : "UserMessage" ,
121
- } ,
122
- ] ) ,
123
- }
124
- ) ;
125
- }
126
-
127
- async function setup ( ) {
128
- const supportAgent = fetch (
129
- `${ basePath } /v1/${ appId } /users/autoReplyExampleSupportAgent` ,
130
- {
131
- method : "put" ,
132
- headers : {
133
- "Content-Type" : "application/json" ,
134
- Authorization : `Bearer ${ secretKey } ` ,
135
- } ,
136
- body : JSON . stringify ( {
137
- name : "Alice" ,
138
-
139
- photoUrl : "https://talkjs.com/images/avatar-1.jpg" ,
140
- role : "support" ,
141
- welcomeMessage : "Hey there! How can I help?" ,
142
- } ) ,
143
- }
144
- ) ;
145
-
146
- const user1 = fetch ( `${ basePath } /v1/${ appId } /users/autoReplyExampleUser1` , {
147
- method : "put" ,
148
- headers : {
149
- "Content-Type" : "application/json" ,
150
- Authorization : `Bearer ${ secretKey } ` ,
151
- } ,
152
- body : JSON . stringify ( {
153
- name : "Sebastian" ,
154
-
155
- photoUrl : "https://talkjs.com/images/avatar-5.jpg" ,
156
- role : "customer" ,
157
- welcomeMessage : "Hi!" ,
158
- } ) ,
159
- } ) ;
160
-
161
- const user2 = fetch ( `${ basePath } /v1/${ appId } /users/autoReplyExampleUser2` , {
162
- method : "put" ,
163
- headers : {
164
- "Content-Type" : "application/json" ,
165
- Authorization : `Bearer ${ secretKey } ` ,
166
- } ,
167
- body : JSON . stringify ( {
168
- name : "Bob" ,
169
-
170
- photoUrl : "https://talkjs.com/images/avatar-4.jpg" ,
171
- role : "customer" ,
172
- welcomeMessage : "Hello!" ,
173
- } ) ,
174
- } ) ;
175
-
176
- await supportAgent ;
177
- await user1 ;
178
- await user2 ;
179
-
180
- const conv1 = setupConversation ( 1 ) ;
181
- const conv2 = setupConversation ( 2 ) ;
182
-
183
- await conv1 ;
184
- await conv2 ;
185
- }
186
-
187
- setup ( ) ;
0 commit comments