1
1
require ( 'dotenv' ) . config ( ) ;
2
2
3
+ import * as dl from "../../node_modules/botframework-directlinejs/built/directLine" ;
3
4
import * as express from 'express' ;
4
5
import bodyParser = require( 'body-parser' ) ;
5
6
import * as path from 'path' ;
6
7
import * as fs from 'fs' ;
7
8
9
+ export var MockBot : dl . User = {
10
+ id : "mockbot" ,
11
+ name : "MockBot"
12
+ }
13
+
8
14
const app = express ( ) ;
9
15
10
16
app . use ( bodyParser . json ( ) ) ; // for parsing application/json
@@ -47,7 +53,8 @@ app.post('/mock/tokens/generate', (req, res) => {
47
53
res . send ( {
48
54
conversationId,
49
55
token,
50
- expires_in
56
+ expires_in,
57
+ timestamp : new Date ( ) . toUTCString ( ) ,
51
58
} ) ;
52
59
} ) ;
53
60
@@ -57,13 +64,14 @@ app.post('/mock/tokens/refresh', (req, res) => {
57
64
res . send ( {
58
65
conversationId,
59
66
token,
60
- expires_in
67
+ expires_in,
68
+ timestamp : new Date ( ) . toUTCString ( )
61
69
} ) ;
62
70
} ) ;
63
71
64
72
let counter : number ;
65
73
let messageId : number ;
66
- let queue : Activity [ ] ;
74
+ let queue : dl . Activity [ ] ;
67
75
68
76
app . post ( '/mock/conversations' , ( req , res ) => {
69
77
counter = 0 ;
@@ -91,35 +99,18 @@ const startConversation = (req: express.Request, res: express.Response) => {
91
99
conversationId,
92
100
token,
93
101
expires_in,
94
- streamUrl
102
+ streamUrl,
103
+ timestamp : new Date ( ) . toUTCString ( )
95
104
} ) ;
96
- sendMessage ( res , `Welcome to MockBot! Here is test ${ test } on area ${ area } ` ) ;
97
- }
98
-
99
- interface Activity {
100
- type : string ,
101
- timestamp ?: string ,
102
- textFormat ?: string ,
103
- text ?: string ,
104
- channelId ?: string ,
105
- attachmentLayout ?: string ,
106
- attachments ?: Attachment ,
107
- id ?: string ,
108
- from ?: { id ?: string , name ?: string }
109
- }
110
-
111
- interface Attachment {
112
-
113
- }
114
-
115
- const sendMessage = ( res : express . Response , text : string ) => {
116
- queue . push ( {
105
+ sendActivity ( res , {
117
106
type : "message" ,
118
- text
119
- } )
107
+ text : "Welcome to MockBot!" ,
108
+ timestamp : new Date ( ) . toUTCString ( ) ,
109
+ from : MockBot
110
+ } ) ;
120
111
}
121
112
122
- const sendActivity = ( res : express . Response , activity : Activity ) => {
113
+ const sendActivity = ( res : express . Response , activity : dl . Activity ) => {
123
114
queue . push ( activity )
124
115
}
125
116
@@ -146,13 +137,14 @@ const postMessage = (req: express.Request, res: express.Response) => {
146
137
const id = messageId ++ ;
147
138
res . send ( {
148
139
id,
140
+ timestamp : new Date ( ) . toUTCString ( )
149
141
} ) ;
150
142
processCommand ( req , res , req . body . text , id ) ;
151
143
}
152
144
153
145
const printCommands = ( ) => {
154
146
let cmds = "### Commands\r\n\r\n" ;
155
- for ( var command in commands ) {
147
+ for ( var command in commands ) {
156
148
cmds += `* ${ command } \r\n` ;
157
149
}
158
150
return cmds ;
@@ -187,7 +179,8 @@ const processCommand = (req: express.Request, res: express.Response, cmd: string
187
179
type : "message" ,
188
180
timestamp : new Date ( ) . toUTCString ( ) ,
189
181
channelId : "webchat" ,
190
- text : printCommands ( )
182
+ text : printCommands ( ) ,
183
+ from : MockBot
191
184
} ) ;
192
185
return ;
193
186
case 'end' :
@@ -204,7 +197,8 @@ const processCommand = (req: express.Request, res: express.Response, cmd: string
204
197
type : "message" ,
205
198
timestamp : new Date ( ) . toUTCString ( ) ,
206
199
channelId : "webchat" ,
207
- text : "echo: " + req . body . text
200
+ text : "echo: " + req . body . text ,
201
+ from : MockBot
208
202
} ) ;
209
203
}
210
204
return ;
@@ -213,7 +207,8 @@ const processCommand = (req: express.Request, res: express.Response, cmd: string
213
207
type : "message" ,
214
208
timestamp : new Date ( ) . toUTCString ( ) ,
215
209
channelId : "webchat" ,
216
- text : "echo: " + req . body . text
210
+ text : "echo: " + req . body . text ,
211
+ from : MockBot
217
212
} ) ;
218
213
return ;
219
214
}
@@ -244,6 +239,7 @@ const upload = (req: express.Request, res: express.Response) => {
244
239
const id = messageId ++ ;
245
240
res . send ( {
246
241
id,
242
+ timestamp : new Date ( ) . toUTCString ( )
247
243
} ) ;
248
244
}
249
245
@@ -275,12 +271,14 @@ const getMessages = (req: express.Request, res: express.Response) => {
275
271
msg . from = { id : "id" , name : "name" } ;
276
272
res . send ( {
277
273
activities : [ msg ] ,
278
- watermark : id
274
+ watermark : id ,
275
+ timestamp : new Date ( ) . toUTCString ( )
279
276
} ) ;
280
277
} else {
281
278
res . send ( {
282
279
activities : [ ] ,
283
- watermark : messageId
280
+ watermark : messageId ,
281
+ timestamp : new Date ( ) . toUTCString ( )
284
282
} )
285
283
}
286
284
}
0 commit comments