11require ( 'dotenv' ) . config ( ) ;
22
3+ import * as dl from "../../node_modules/botframework-directlinejs/built/directLine" ;
34import * as express from 'express' ;
45import bodyParser = require( 'body-parser' ) ;
56import * as path from 'path' ;
67import * as fs from 'fs' ;
78
9+ export var MockBot : dl . User = {
10+ id : "mockbot" ,
11+ name : "MockBot"
12+ }
13+
814const app = express ( ) ;
915
1016app . use ( bodyParser . json ( ) ) ; // for parsing application/json
@@ -47,7 +53,8 @@ app.post('/mock/tokens/generate', (req, res) => {
4753 res . send ( {
4854 conversationId,
4955 token,
50- expires_in
56+ expires_in,
57+ timestamp : new Date ( ) . toUTCString ( ) ,
5158 } ) ;
5259} ) ;
5360
@@ -57,13 +64,14 @@ app.post('/mock/tokens/refresh', (req, res) => {
5764 res . send ( {
5865 conversationId,
5966 token,
60- expires_in
67+ expires_in,
68+ timestamp : new Date ( ) . toUTCString ( )
6169 } ) ;
6270} ) ;
6371
6472let counter : number ;
6573let messageId : number ;
66- let queue : Activity [ ] ;
74+ let queue : dl . Activity [ ] ;
6775
6876app . post ( '/mock/conversations' , ( req , res ) => {
6977 counter = 0 ;
@@ -91,35 +99,18 @@ const startConversation = (req: express.Request, res: express.Response) => {
9199 conversationId,
92100 token,
93101 expires_in,
94- streamUrl
102+ streamUrl,
103+ timestamp : new Date ( ) . toUTCString ( )
95104 } ) ;
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 , {
117106 type : "message" ,
118- text
119- } )
107+ text : "Welcome to MockBot!" ,
108+ timestamp : new Date ( ) . toUTCString ( ) ,
109+ from : MockBot
110+ } ) ;
120111}
121112
122- const sendActivity = ( res : express . Response , activity : Activity ) => {
113+ const sendActivity = ( res : express . Response , activity : dl . Activity ) => {
123114 queue . push ( activity )
124115}
125116
@@ -146,13 +137,14 @@ const postMessage = (req: express.Request, res: express.Response) => {
146137 const id = messageId ++ ;
147138 res . send ( {
148139 id,
140+ timestamp : new Date ( ) . toUTCString ( )
149141 } ) ;
150142 processCommand ( req , res , req . body . text , id ) ;
151143}
152144
153145const printCommands = ( ) => {
154146 let cmds = "### Commands\r\n\r\n" ;
155- for ( var command in commands ) {
147+ for ( var command in commands ) {
156148 cmds += `* ${ command } \r\n` ;
157149 }
158150 return cmds ;
@@ -187,7 +179,8 @@ const processCommand = (req: express.Request, res: express.Response, cmd: string
187179 type : "message" ,
188180 timestamp : new Date ( ) . toUTCString ( ) ,
189181 channelId : "webchat" ,
190- text : printCommands ( )
182+ text : printCommands ( ) ,
183+ from : MockBot
191184 } ) ;
192185 return ;
193186 case 'end' :
@@ -204,7 +197,8 @@ const processCommand = (req: express.Request, res: express.Response, cmd: string
204197 type : "message" ,
205198 timestamp : new Date ( ) . toUTCString ( ) ,
206199 channelId : "webchat" ,
207- text : "echo: " + req . body . text
200+ text : "echo: " + req . body . text ,
201+ from : MockBot
208202 } ) ;
209203 }
210204 return ;
@@ -213,7 +207,8 @@ const processCommand = (req: express.Request, res: express.Response, cmd: string
213207 type : "message" ,
214208 timestamp : new Date ( ) . toUTCString ( ) ,
215209 channelId : "webchat" ,
216- text : "echo: " + req . body . text
210+ text : "echo: " + req . body . text ,
211+ from : MockBot
217212 } ) ;
218213 return ;
219214 }
@@ -244,6 +239,7 @@ const upload = (req: express.Request, res: express.Response) => {
244239 const id = messageId ++ ;
245240 res . send ( {
246241 id,
242+ timestamp : new Date ( ) . toUTCString ( )
247243 } ) ;
248244}
249245
@@ -275,12 +271,14 @@ const getMessages = (req: express.Request, res: express.Response) => {
275271 msg . from = { id : "id" , name : "name" } ;
276272 res . send ( {
277273 activities : [ msg ] ,
278- watermark : id
274+ watermark : id ,
275+ timestamp : new Date ( ) . toUTCString ( )
279276 } ) ;
280277 } else {
281278 res . send ( {
282279 activities : [ ] ,
283- watermark : messageId
280+ watermark : messageId ,
281+ timestamp : new Date ( ) . toUTCString ( )
284282 } )
285283 }
286284 }
0 commit comments