-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
65 lines (54 loc) · 2.1 KB
/
Copy pathserver.js
File metadata and controls
65 lines (54 loc) · 2.1 KB
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
const config = require('./config.js')
const restify = require('restify')
const builder = require('botbuilder')
const recast = require('recastai')
const getFeelings = require('./intents/feelings.js')
const getGoodbyes = require('./intents/goodbyes.js')
const getGreetings = require('./intents/greetings.js')
const getHelp = require('./intents/help.js')
const getReqStatus = require('./intents/reqstatus.js')
const getReqNew = require('./intents/reqnew.js')
// Connection to Recast.ai
const recastClient = new recast.Client(config.recast)
// Connection to Microsoft Bot Framework
const connector = new builder.ChatConnector({
appId: config.appId,
appPassword: config.appPassword
})
const bot = new builder.UniversalBot(connector)
// Intents based on definitions on recast
const INTENTS = {
feelings: getFeelings,
goodbyes: getGoodbyes,
greetings: getGreetings,
reqstatus: getReqStatus,
reqnew: getReqNew,
help: getHelp,
}
// Event when Message received
bot.dialog('/', (session) => {
recastClient.textRequest(session.message.text)
.then(res => {
const intent = res.intent()
const entity = res.get('request_number')
console.log(`UserName: ${session.message.user.name}`)
console.log(`UserMsg: ${session.message.text}`)
console.log(`Intent: ${intent.slug}`)
console.log(entity)
if (intent) {
if (intent.slug == 'reqstatus' && entity === undefined) {
console.log ("BotResp(reqstatus): Entity request_number not defined.")
session.send('Sure I can help you with that. Please provide the RQ Number as well, should be should be something like RQ0123456')
}
INTENTS[intent.slug](entity)
.then(res => session.send(res))
.catch(err => session.send(err))
// console.log(res)
}
})
.catch(() => session.send('Sorry I didn\'t get that. \n\nI can provide you information regarding your ongoing Requests or help you to create a new one.\n\nPS: I only speak English for now.'))
})
// Server Init
const server = restify.createServer()
server.listen(process.env.PORT,process.env.IP)
server.post('/', connector.listen())