Skip to content

Commit e573a74

Browse files
committed
share MockBot and DirectLine interfaces
1 parent 18a01ee commit e573a74

File tree

3 files changed

+36
-40
lines changed

3 files changed

+36
-40
lines changed

test/commands_map.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import * as server_content from './server_content';
22
import * as dl from "../node_modules/botframework-directlinejs/built/directLine";
33
import * as Nightmare from 'nightmare';
44
import * as express from 'express';
5+
import { MockBot } from "./mock_dl/index";
6+
57
declare let module: any;
68

79
interface ISendActivity {
@@ -219,7 +221,7 @@ var commands_map: CommandValuesMap = {
219221
server: function (res, sendActivity) {
220222
sendActivity(res, {
221223
type: "message",
222-
from: server_content.bot,
224+
from: MockBot,
223225
timestamp: new Date().toUTCString(),
224226
channelId: "webchat",
225227
textFormat: "markdown",

test/mock_dl/index.ts

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
11
require('dotenv').config();
22

3+
import * as dl from "../../node_modules/botframework-directlinejs/built/directLine";
34
import * as express from 'express';
45
import bodyParser = require('body-parser');
56
import * as path from 'path';
67
import * as fs from 'fs';
78

9+
export var MockBot: dl.User = {
10+
id: "mockbot",
11+
name: "MockBot"
12+
}
13+
814
const app = express();
915

1016
app.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

6472
let counter: number;
6573
let messageId: number;
66-
let queue: Activity[];
74+
let queue: dl.Activity[];
6775

6876
app.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

153145
const 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
}

test/server_content.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import * as dl from "../node_modules/botframework-directlinejs/built/directLine";
2+
import { MockBot as bot } from "./mock_dl/index";
23
const config = require('./mock_dl_server_config');
34
const asset_url = "http://localhost:" + config["port"] + "/assets/";
45

5-
export var bot: dl.User = {
6-
id: "bot",
7-
name: "botname"
8-
}
9-
106
/*
117
* Function that renders Adaptive Cards
128
*

0 commit comments

Comments
 (0)