-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_beta.js
140 lines (113 loc) · 4.09 KB
/
server_beta.js
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
var restify = require('restify');
var builder = require('botbuilder');
// Get secrets from server environment
var botConnectorOptions = {
appId: process.env.BOTFRAMEWORK_APPID,
appPassword: process.env.BOTFRAMEWORK_APPSECRET
};
// Create bot
var connector = new builder.ChatConnector(botConnectorOptions);
// var bot = new builder.UniversalBot(connector);
// bot.dialog('/', function (session) {
// //respond with user's message
// session.send("You said " + session.message.text);
// });
// Setup Restify Server
var server = restify.createServer();
// Handle Bot Framework messages
server.post('/api/messages', connector.listen());
// // Serve a static web page
// server.get(/.*/, restify.serveStatic({
// 'directory': '.',
// 'default': 'index.html'
// }));
server.listen(process.env.port || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
var bot = new builder.UniversalBot(connector, [
function (session) {
session.send("Hello... I'm a decision bot.");
session.send("You said: '%s'. Try asking for 'help'.", session.message.text);
},
function (session, results) {
session.endConversation("Goodbye until next time...");
}
]);
bot.dialog('rootMenu', [
function (session) {
var action = createRootMenu(session);
var msg = new builder.Message(session).addAttachment(action);
session.send(msg);
}
]).triggerAction({matches: /^help$/i});
bot.dialog('Call', [
function (session) {
builder.Prompts.text(session, "Please add your phone number");
},
function (session, results) {
var a = results.response
// some actions
session.endDialog("We are call to you");
}
]).triggerAction({matches: /^call$/i});
bot.dialog('Buy', [
function (session) {
var action = serviceList(session);
var msg = new builder.Message(session).addAttachment(action);
session.send(msg);
},
]).triggerAction({matches: /^buy/i});
bot.dialog('Support', [
function (session) {
builder.Prompts.text(session, "What is your question?");
}
]).triggerAction({matches: /^support$/i});
// Buy
DomainServices = ['By', 'RU', "Com"];
bot.dialog('Domain', [
function (session) {
builder.Prompts.text(session, "dfsdfdsfnfmbsdfhdkslfjhkjdshjfkh");
}
]).triggerAction({matches: /^domain/i});
function createRootMenu(session) {
const card = new builder.ThumbnailCard(session);
card.buttons([
new builder.CardAction(session).title('Buy service').value('Buy').type('imBack'),
new builder.CardAction(session).title('Support').value('Support').type('imBack'),
new builder.CardAction(session).title('Call').value('Call').type('imBack'),
]).text(`What would you like to do?`);
return card;
}
function serviceList(session) {
const card = new builder.ThumbnailCard(session);
card.buttons([
new builder.CardAction(session).title('Hosting').value('Hosting').type('imBack'),
new builder.CardAction(session).title('Domain').value('Domain').type('imBack'),
new builder.CardAction(session).title('Mail').value('Mail').type('imBack'),
]).text(`What would you like to buy?`);
return card;
}
var model = process.env.model || 'https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/b8ac99e4-3e42-4bb4-8fa3-eec10e4de189?subscription-key=88ec7ba1fb364eb590fdb5764bf73f7f&timezoneOffset=0.0&verbose=true&q=';
var recognizer = new builder.LuisRecognizer(model);
var intents = new builder.IntentDialog({ recognizers: [recognizer] });
intents.onDefault(builder.DialogAction.send("I'm sorry. I didn't understand."));
// bot.dialog('/', intents);
intents.matches('buy', [
function (session, args, next) {
debugger;
var e = builder.EntityRecognizer.findEntity(args.entities, 'hosting');
if (!e) {
builder.Prompts.text(session, "Which hosting do you want?");
} else {
next({ response: e.entity });
}
},
function (session, results) {
if (results.response) {
// ... save task
session.send("ok, there is list of %s", results.response);
} else {
session.send("no response");
}
}
]);