forked from palindromed/Bot-HandOff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.ts
47 lines (37 loc) · 1.35 KB
/
app.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import * as express from 'express';
import * as builder from 'botbuilder';
import { Handoff } from './handoff';
import { commandsMiddleware } from './commands';
//=========================================================
// Bot Setup
//=========================================================
const app = express();
// Setup Express Server
app.listen(process.env.port || process.env.PORT || 3978, '::', () => {
console.log('Server Up');
});
// Create chat bot
const connector = new builder.ChatConnector({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
const bot = new builder.UniversalBot(connector, [
function (session, args, next) {
session.send('Echo ' + session.message.text);
}
]);
app.post('/api/messages', connector.listen());
// Create endpoint for agent / call center
app.use('/webchat', express.static('public'));
// replace this function with custom login/verification for agents
const isAgent = (session: builder.Session) =>
session.message.user.name.startsWith("Agent");
const handoff = new Handoff(bot, isAgent);
//========================================================
// Bot Middleware
//========================================================
bot.use(
commandsMiddleware(handoff),
handoff.routingMiddleware(),
/* other bot middlware should probably go here */
);