-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscenes.js
250 lines (224 loc) · 7.52 KB
/
scenes.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
const Config = require('./config');
const Func = require('./functions');
const Commands = require('./commands');
var scene = function () {
var self = this;
this.id = '';
this.response = Func.make_response;
this.fallback = Func.make_fallback;
this.reply = function defaultReply(req, obj) {
return self.fallback(req, obj);
}
this.handle_local_intents = function handleLocalIntents(req, intents) {
return false;
}
this.handle_global_intents = function handleGlobalIntents(req) {
let intents = Config.GLOBAL_INTENTS;
let hge = this.handle_intents(req, intents);
if (hge === "YANDEX.WHAT_CAN_YOU_DO") {
hge = "help";
}
if (!Func.is_null(hge)) {
let cmd = hge.toLocaleLowerCase().replace(/yandex\./, '');
if (typeof Commands[cmd] === "object") {
return { func: Commands[cmd], type: 'reply' };
}
}
return false;
}
this.handle_intents = function processIntents(req, intents) {
if (typeof intents === "object") {
for (let i = 0; i < intents.length; i++) {
if (!Func.is_null(req?.request?.nlu?.intents[intents[i]])) {
console.log('Handle intent [' + intents[i] + ']');
return intents[i];
}
}
}
return false;
}
}
get_place = function Place(req, place, self) {
if (place === "tell_about_place") {
let intent = req.request.nlu.intents.tell_about_place;
if (typeof intent.slots?.place?.value !== "undefined") {
place = intent.slots.place.value;
}
}
if (place === "tower") {
return { func: tower };
} else if (place === "cathedral") {
return { func: cathedral };
} else {
console.error('Unknown place [' + place + ']');
return {
func: self,
type: 'fallback',
argv: {
text: "Сожалею, но мне пока неизвестно это место.",
buttons: [
Func.makeButton("Расскажи про башню"),
Func.makeButton("Расскажи про собор")
]
}
};
}
}
var welcome = new scene();
welcome.reply = function Welcome(req) {
let text = 'Добро пожаловать на экскурсию по кремлю Великого Новгорода. Начинаем?';
if (req.session.new === false) {
text = 'Начнём экскурсию?';
}
return this.response(
req,
{
text: text,
buttons: [
Func.makeButton({ title: "Начинай" })
],
}
);
}
welcome.handle_local_intents = function WelcomeIntents(req) {
let local_intents = ['start_tour', 'YANDEX.CONFIRM'];
let intent = this.handle_intents(req, local_intents);
if (intent !== false) {
return { func: start_tour, type: 'reply' };
}
local_intents = ['YANDEX.REJECT'];
intent = this.handle_intents(req, local_intents);
if (intent !== false) {
return {
func: Commands.exit
};
}
intent = this.handle_global_intents(req);
if (intent !== false) {
return intent;
}
return {
func: this,
type: 'reply'
};
}
var start_tour = new scene();
start_tour.id = 'start_tour';
start_tour.reply = function StartTour(req) {
let res = {
text: 'Возле какого места вы находитесь?',
tts: 'Возле какого места вы находитесь?',
buttons: [Func.makeButton("Башня"), Func.makeButton("Собор")],
};
if (typeof req?.meta?.interfaces?.screen === "object") {
res.images = [
'965417/48f0d72fa8cdf775fb45',
'965417/af9d0a49d10becbd70d4'
];
}
return this.response(req, res);
}
start_tour.fallback = function StartTourallback(req, obj) {
if (Func.is_null(obj)) {
obj = {
text: Func.randomPhrase([
"Сожалею, но я Вас не поняла. Попробуйте уточнить свой вопрос.",
"Простите, но я Вас не смогла понять. Пожалуйста, уточните Ваш вопрос.",
]) + ' Так возле какого места вы находитесь?',
buttons: [
Func.makeButton("Около башни"),
Func.makeButton("Около собора")
],
};
}
return Func.make_fallback(req, obj);
}
start_tour.handle_local_intents = function StartTourIntents(req) {
let local_intents = ['tell_about_place', 'tower', 'cathedral'];
let intent = this.handle_intents(req, local_intents);
if (intent !== false) {
return get_place(req, intent, this);
}
return false;
}
var tower = new scene();
tower.id = 'tower';
tower.reply = function Tower(req) {
return this.response(
req,
{
text: 'Спасская башня — проездная башня Новгородского детинца, строение конца XV века. ' +
'Башня шестиярусная, в плане представляет собой вытянутый прямоугольник 15 × 8,3 м.' +
'Ширина проезда — 3 м. Высота стен — 19 м, а толщина стен на уровне второго яруса — 2 м.',
tts: 'Спасская башня sil <[200]> проездная башня Новгородского дет+инца,строение конца пятнадцатого века.' +
'Башня шестиярусная, в плане представляет собой вытянутый прямоугольник пятнадцать на восемь целых три десятых метра.' +
'Ширина проезда sil <[100]> три метра. Высота стен sil <[100]> девятнадцать метров, а толщина стен на уровне второго яруса sil <[100]> 2 метра.',
image: '965417/48f0d72fa8cdf775fb45',
title: 'Спасская башня',
buttons: [
Func.makeButton("Расскажи про собор")
],
}
);
}
tower.fallback = function TowerFallback(req, obj) {
if (Func.is_null(obj)) {
obj = {
buttons: [
Func.makeButton("Расскажи про башню"),
Func.makeButton("Расскажи про собор")
],
};
}
return Func.make_fallback(req, obj);
}
tower.handle_local_intents = function TowerIntents(req) {
let local_intents = ['tell_about_place', 'tower', 'cathedral'];
let intent = this.handle_intents(req, local_intents);
if (intent !== false) {
return get_place(req, intent, this);
}
return false;
}
var cathedral = new scene();
cathedral.id = "cathedral";
cathedral.reply = function Cathedral(req) {
return this.response(
req,
{
text: 'Софийский собор представляет собой пятинефный крестово-купольный храм.' +
'У храма имеется три апсиды — центральная пятигранная, и боковые — округлые. С трёх сторон центральное строение окружают широкие двухэтажные галереи.',
sound: '<speaker audio="alice-sounds-things-bell-1.opus">',
image: '965417/af9d0a49d10becbd70d4',
title: 'Софийский собор',
buttons: [
Func.makeButton("Расскажи про башню")
],
}
);
}
cathedral.fallback = function CathedralFallback(req, obj) {
if (Func.is_null(obj)) {
obj = {
buttons: [
Func.makeButton("Расскажи про собор"),
Func.makeButton("Расскажи про башню")
],
};
}
return Func.make_fallback(req, obj);
}
cathedral.handle_local_intents = function CathedralIntents(req) {
let local_intents = ['tell_about_place', 'tower', 'cathedral'];
let intent = this.handle_intents(req, local_intents);
if (intent !== false) {
return get_place(req, intent, this);
}
return false;
}
module.exports = {
welcome: welcome,
start_tour: start_tour,
tower: tower,
cathedral: cathedral,
}