wingbot 3.32.0-alpha.1 → 3.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -6
- package/src/Ai.js +2 -2
- package/src/BotApp.js +21 -6
- package/src/BuildRouter.js +55 -326
- package/src/ConversationTester.js +2 -2
- package/src/Processor.js +1 -7
- package/src/Request.js +13 -3
- package/src/Responder.js +5 -1
- package/src/ReturnSender.js +66 -20
- package/src/Router.js +8 -22
- package/src/Tester.js +42 -5
- package/src/features.js +6 -0
- package/src/notifications/Notifications.js +1 -1
- package/src/resolvers/bounce.js +3 -6
- package/src/resolvers/button.js +11 -16
- package/src/resolvers/carousel.js +10 -8
- package/src/resolvers/expected.js +10 -1
- package/src/resolvers/media.js +7 -13
- package/src/resolvers/message.js +10 -24
- package/src/resolvers/postback.js +3 -13
- package/src/resolvers/setState.js +3 -12
- package/src/resolvers/subscribtions.js +3 -13
- package/src/resolvers/utils.js +6 -6
- package/src/utils/customCondition.js +2 -3
- package/src/utils/customFn.js +0 -8
- package/src/utils/getCondition.js +2 -15
- package/src/utils/getUpdate.js +3 -3
- package/src/utils/quickReplies.js +3 -2
- package/src/utils/stateData.js +2 -5
- package/src/utils/wrapPluginFunction.js +1 -1
package/src/resolvers/message.js
CHANGED
|
@@ -44,10 +44,10 @@ function getVoiceControlFromParams (params, lang = null) {
|
|
|
44
44
|
return Object.keys(voiceControl).length > 0 ? voiceControl : null;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
function parseReplies (replies, linksMap,
|
|
47
|
+
function parseReplies (replies, linksMap, allowForbiddenSnippetWords) {
|
|
48
48
|
return replies.map((reply) => {
|
|
49
49
|
|
|
50
|
-
const condition = getCondition(reply,
|
|
50
|
+
const condition = getCondition(reply, 'Quick reply condition', allowForbiddenSnippetWords);
|
|
51
51
|
|
|
52
52
|
if (reply.isLocation) {
|
|
53
53
|
return {
|
|
@@ -78,10 +78,6 @@ function parseReplies (replies, linksMap, context) {
|
|
|
78
78
|
}
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
-
if (!action) {
|
|
82
|
-
return null;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
81
|
const ret = {
|
|
86
82
|
action,
|
|
87
83
|
condition,
|
|
@@ -108,8 +104,7 @@ function parseReplies (replies, linksMap, context) {
|
|
|
108
104
|
}
|
|
109
105
|
|
|
110
106
|
return ret;
|
|
111
|
-
})
|
|
112
|
-
.filter((r) => r !== null);
|
|
107
|
+
});
|
|
113
108
|
}
|
|
114
109
|
|
|
115
110
|
/**
|
|
@@ -159,20 +154,11 @@ function findSupportedMessages (text, features, lang = null) {
|
|
|
159
154
|
};
|
|
160
155
|
}
|
|
161
156
|
|
|
162
|
-
|
|
163
|
-
|
|
157
|
+
function message (params, {
|
|
158
|
+
// @ts-ignore
|
|
159
|
+
isLastIndex, isLastMessage, linksMap, allowForbiddenSnippetWords
|
|
160
|
+
} = {}) {
|
|
164
161
|
|
|
165
|
-
/**
|
|
166
|
-
*
|
|
167
|
-
* @param {object} params
|
|
168
|
-
* @param {BotContext} context
|
|
169
|
-
* @returns {Resolver}
|
|
170
|
-
*/
|
|
171
|
-
function message (params, context = {}) {
|
|
172
|
-
const {
|
|
173
|
-
// @ts-ignore
|
|
174
|
-
isLastIndex, isLastMessage, linksMap, configuration
|
|
175
|
-
} = context;
|
|
176
162
|
if (typeof params.text !== 'string' && !Array.isArray(params.text)) {
|
|
177
163
|
throw new Error('Message should be a text!');
|
|
178
164
|
}
|
|
@@ -182,11 +168,11 @@ function message (params, context = {}) {
|
|
|
182
168
|
if (params.replies && !Array.isArray(params.replies)) {
|
|
183
169
|
throw new Error('Replies should be an array');
|
|
184
170
|
} else if (params.replies && params.replies.length > 0) {
|
|
185
|
-
quickReplies = parseReplies(params.replies, linksMap,
|
|
171
|
+
quickReplies = parseReplies(params.replies, linksMap, allowForbiddenSnippetWords);
|
|
186
172
|
}
|
|
187
173
|
|
|
188
174
|
// compile condition
|
|
189
|
-
const condition = getCondition(params,
|
|
175
|
+
const condition = getCondition(params, 'Message condition', allowForbiddenSnippetWords);
|
|
190
176
|
|
|
191
177
|
const ret = isLastIndex ? Router.END : Router.CONTINUE;
|
|
192
178
|
|
|
@@ -198,7 +184,7 @@ function message (params, context = {}) {
|
|
|
198
184
|
if (condition && !condition(req, res)) {
|
|
199
185
|
return ret;
|
|
200
186
|
}
|
|
201
|
-
const data = stateData(req, res
|
|
187
|
+
const data = stateData(req, res);
|
|
202
188
|
|
|
203
189
|
// filter supported messages
|
|
204
190
|
const supportedText = findSupportedMessages(
|
|
@@ -7,17 +7,7 @@ const Router = require('../Router');
|
|
|
7
7
|
const getCondition = require('../utils/getCondition');
|
|
8
8
|
const { shouldExecuteResolver } = require('./resolverTags');
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
/** @typedef {import('../Router').Resolver} Resolver */
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
* @param {object} params
|
|
16
|
-
* @param {BotContext} context
|
|
17
|
-
* @returns {Resolver}
|
|
18
|
-
*/
|
|
19
|
-
function postback (params, context) {
|
|
20
|
-
const { linksMap, isLastIndex } = context;
|
|
10
|
+
function postback (params, { linksMap, isLastIndex, allowForbiddenSnippetWords }) {
|
|
21
11
|
const {
|
|
22
12
|
routeId,
|
|
23
13
|
postBack: staticAction
|
|
@@ -32,12 +22,12 @@ function postback (params, context) {
|
|
|
32
22
|
}
|
|
33
23
|
}
|
|
34
24
|
|
|
35
|
-
const condition = getCondition(params,
|
|
25
|
+
const condition = getCondition(params, '', allowForbiddenSnippetWords);
|
|
36
26
|
|
|
37
27
|
const ret = isLastIndex ? Router.END : Router.CONTINUE;
|
|
38
28
|
|
|
39
29
|
return (req, res, postBack) => {
|
|
40
|
-
if (!
|
|
30
|
+
if (!shouldExecuteResolver(req, params)) {
|
|
41
31
|
return ret;
|
|
42
32
|
}
|
|
43
33
|
|
|
@@ -8,20 +8,11 @@ const Ai = require('../Ai');
|
|
|
8
8
|
const { getSetState } = require('../utils/getUpdate');
|
|
9
9
|
const getCondition = require('../utils/getCondition');
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
/** @typedef {import('../Router').Resolver} Resolver */
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
* @param {object} params
|
|
17
|
-
* @param {BotContext} context
|
|
18
|
-
* @returns {Resolver}
|
|
19
|
-
*/
|
|
20
|
-
function setState (params, context) {
|
|
11
|
+
function setState (params, { isLastIndex, allowForbiddenSnippetWords }) {
|
|
21
12
|
|
|
22
|
-
const condition = getCondition(params,
|
|
13
|
+
const condition = getCondition(params, '', allowForbiddenSnippetWords);
|
|
23
14
|
|
|
24
|
-
const ret =
|
|
15
|
+
const ret = isLastIndex ? Router.END : Router.CONTINUE;
|
|
25
16
|
|
|
26
17
|
return async (req, res) => {
|
|
27
18
|
if (condition !== null) {
|
|
@@ -6,24 +6,15 @@
|
|
|
6
6
|
const Router = require('../Router');
|
|
7
7
|
const getCondition = require('../utils/getCondition');
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
/** @typedef {import('../Router').Resolver} Resolver */
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* @param {object} params
|
|
15
|
-
* @param {BotContext} context
|
|
16
|
-
* @returns {Resolver}
|
|
17
|
-
*/
|
|
18
|
-
function subscribtions (params, context) {
|
|
9
|
+
function subscribtions (params, { isLastIndex, allowForbiddenSnippetWords }) {
|
|
19
10
|
const {
|
|
20
11
|
tags = [],
|
|
21
12
|
unsetTag = false
|
|
22
13
|
} = params;
|
|
23
14
|
|
|
24
|
-
const condition = getCondition(params,
|
|
15
|
+
const condition = getCondition(params, '', allowForbiddenSnippetWords);
|
|
25
16
|
|
|
26
|
-
const ret =
|
|
17
|
+
const ret = isLastIndex ? Router.END : Router.CONTINUE;
|
|
27
18
|
const method = unsetTag ? 'unsubscribe' : 'subscribe';
|
|
28
19
|
|
|
29
20
|
return async (req, res) => {
|
|
@@ -44,7 +35,6 @@ function subscribtions (params, context) {
|
|
|
44
35
|
}
|
|
45
36
|
|
|
46
37
|
if (tags.length === 0 && unsetTag) {
|
|
47
|
-
// @ts-ignore
|
|
48
38
|
res.unsubscribe();
|
|
49
39
|
}
|
|
50
40
|
|
package/src/resolvers/utils.js
CHANGED
|
@@ -205,18 +205,18 @@ function getText (text, state) {
|
|
|
205
205
|
// eslint-disable-next-line no-unused-vars
|
|
206
206
|
const DEFAULT_LINK_TRANSLATOR = (senderId, defaultText, urlText, isExtUrl, reqState) => urlText;
|
|
207
207
|
|
|
208
|
-
/** @typedef {import('../BuildRouter').BotContext} BotContext */
|
|
209
|
-
|
|
210
208
|
function processButtons (
|
|
211
209
|
buttons,
|
|
212
210
|
state,
|
|
213
211
|
elem,
|
|
212
|
+
linksMap,
|
|
214
213
|
senderId,
|
|
215
|
-
|
|
214
|
+
linksTranslator,
|
|
215
|
+
allowForbiddenSnippetWords,
|
|
216
216
|
req,
|
|
217
217
|
res
|
|
218
218
|
) {
|
|
219
|
-
const translateLinks =
|
|
219
|
+
const translateLinks = linksTranslator || DEFAULT_LINK_TRANSLATOR;
|
|
220
220
|
|
|
221
221
|
buttons.forEach(({
|
|
222
222
|
title: btnTitle,
|
|
@@ -230,7 +230,7 @@ function processButtons (
|
|
|
230
230
|
if (hasCondition) {
|
|
231
231
|
const condition = getCondition({
|
|
232
232
|
hasCondition, conditionFn, hasEditableCondition, editableCondition
|
|
233
|
-
},
|
|
233
|
+
}, 'Quick reply condition', allowForbiddenSnippetWords);
|
|
234
234
|
|
|
235
235
|
if (!condition(req, res)) {
|
|
236
236
|
return;
|
|
@@ -259,7 +259,7 @@ function processButtons (
|
|
|
259
259
|
break;
|
|
260
260
|
}
|
|
261
261
|
case TYPE_POSTBACK: {
|
|
262
|
-
let postbackAction =
|
|
262
|
+
let postbackAction = linksMap.get(targetRouteId) || action;
|
|
263
263
|
|
|
264
264
|
if (postbackAction === '/') {
|
|
265
265
|
postbackAction = './';
|
|
@@ -148,16 +148,15 @@ const compare = (variable, operator, value = undefined) => {
|
|
|
148
148
|
/**
|
|
149
149
|
*
|
|
150
150
|
* @param {{value:string, operator:string, variable:string}[][]} condition
|
|
151
|
-
* @param {object} configuration
|
|
152
151
|
* @param {string} description
|
|
153
152
|
*/
|
|
154
|
-
function customCondition (condition,
|
|
153
|
+
function customCondition (condition, description = '') {
|
|
155
154
|
if (typeof condition !== 'object' || !Array.isArray(condition)) {
|
|
156
155
|
throw new Error(`Invalid condition (${description}) type`);
|
|
157
156
|
}
|
|
158
157
|
|
|
159
158
|
const resolver = (req, res) => condition.some((condList) => condList.every((cond) => {
|
|
160
|
-
const data = stateData(req, res
|
|
159
|
+
const data = stateData(req, res);
|
|
161
160
|
const variableValue = getValue(cond.variable, data);
|
|
162
161
|
const isRegExp = [
|
|
163
162
|
ConditionOperators['matches regexp'],
|
package/src/utils/customFn.js
CHANGED
|
@@ -6,14 +6,6 @@
|
|
|
6
6
|
const Router = require('../Router'); // eslint-disable-line
|
|
7
7
|
const ai = require('../Ai'); // eslint-disable-line
|
|
8
8
|
const fetch = require('node-fetch'); // eslint-disable-line
|
|
9
|
-
let request;
|
|
10
|
-
try {
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
request = module.require('request-promise-native');
|
|
13
|
-
} catch (e) {
|
|
14
|
-
// eslint-disable-next-line no-unused-vars
|
|
15
|
-
request = () => { throw new Error('To use request, you have to manually install request-promise-native into your bot.'); };
|
|
16
|
-
}
|
|
17
9
|
let axios;
|
|
18
10
|
try {
|
|
19
11
|
// @ts-ignore
|
|
@@ -6,20 +6,7 @@
|
|
|
6
6
|
const customCondition = require('./customCondition');
|
|
7
7
|
const customFn = require('./customFn');
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
* @param {object} params
|
|
14
|
-
* @param {BotContext} context
|
|
15
|
-
* @param {string} description
|
|
16
|
-
* @returns {Function}
|
|
17
|
-
*/
|
|
18
|
-
module.exports = function getCondition (params, context, description = '') {
|
|
19
|
-
const {
|
|
20
|
-
allowForbiddenSnippetWords = false,
|
|
21
|
-
configuration
|
|
22
|
-
} = context;
|
|
9
|
+
module.exports = (params, description = '', allowForbiddenSnippetWords = false) => {
|
|
23
10
|
const {
|
|
24
11
|
hasCondition = false,
|
|
25
12
|
conditionFn = '() => true',
|
|
@@ -31,7 +18,7 @@ module.exports = function getCondition (params, context, description = '') {
|
|
|
31
18
|
|
|
32
19
|
if (hasCondition) {
|
|
33
20
|
if (hasEditableCondition) {
|
|
34
|
-
condition = customCondition(editableCondition
|
|
21
|
+
condition = customCondition(editableCondition);
|
|
35
22
|
} else {
|
|
36
23
|
condition = customFn(conditionFn, description, allowForbiddenSnippetWords);
|
|
37
24
|
}
|
package/src/utils/getUpdate.js
CHANGED
|
@@ -88,7 +88,7 @@ function toArray (previousValue) {
|
|
|
88
88
|
const ENTITY_HBS_REGEXP = /^\s*\{\{\[?@([^@[\]{}\s]+)(\])?\}\}\s*$/;
|
|
89
89
|
const VARIABLE_HBS_REGEXP = /^\s*\{\{\[?([^@[\]{}\s]+)\]?\}\}\s*$/;
|
|
90
90
|
|
|
91
|
-
function getSetState (setState, req, res = null, useState = null
|
|
91
|
+
function getSetState (setState, req, res = null, useState = null) {
|
|
92
92
|
if (!setState) {
|
|
93
93
|
return {};
|
|
94
94
|
}
|
|
@@ -179,7 +179,7 @@ function getSetState (setState, req, res = null, useState = null, configuration
|
|
|
179
179
|
values = [];
|
|
180
180
|
} else {
|
|
181
181
|
const useValue = typeof value === 'string'
|
|
182
|
-
? handlebars.compile(value)(stateData(req, res
|
|
182
|
+
? handlebars.compile(value)(stateData(req, res))
|
|
183
183
|
.split(/(?<!\\),/g)
|
|
184
184
|
.map((v) => v.replace(/\\,/g, ',').trim())
|
|
185
185
|
: value;
|
|
@@ -205,7 +205,7 @@ function getSetState (setState, req, res = null, useState = null, configuration
|
|
|
205
205
|
set = val;
|
|
206
206
|
}
|
|
207
207
|
} else if (typeof val === 'string') {
|
|
208
|
-
set = handlebars.compile(val)(stateData(req, res
|
|
208
|
+
set = handlebars.compile(val)(stateData(req, res));
|
|
209
209
|
} else if (val === null
|
|
210
210
|
|| SCALAR_TYPES.includes(typeof val)) {
|
|
211
211
|
set = val;
|
|
@@ -133,7 +133,8 @@ function makeQuickReplies (replies, path = '', translate = (w) => w, quickReplyC
|
|
|
133
133
|
data = {},
|
|
134
134
|
isLocation = false,
|
|
135
135
|
isEmail = false,
|
|
136
|
-
isPhone = false
|
|
136
|
+
isPhone = false,
|
|
137
|
+
useCa = currentAction
|
|
137
138
|
} = reply;
|
|
138
139
|
let {
|
|
139
140
|
setState = null
|
|
@@ -219,7 +220,7 @@ function makeQuickReplies (replies, path = '', translate = (w) => w, quickReplyC
|
|
|
219
220
|
payload = {
|
|
220
221
|
action: absoluteAction,
|
|
221
222
|
data: {
|
|
222
|
-
_ca:
|
|
223
|
+
_ca: useCa,
|
|
223
224
|
...data
|
|
224
225
|
}
|
|
225
226
|
};
|
package/src/utils/stateData.js
CHANGED
|
@@ -3,14 +3,11 @@
|
|
|
3
3
|
*/
|
|
4
4
|
'use strict';
|
|
5
5
|
|
|
6
|
-
module.exports = function stateData (req, res = null
|
|
7
|
-
const c = configuration || req.configuration;
|
|
6
|
+
module.exports = function stateData (req, res = null) {
|
|
8
7
|
return {
|
|
9
8
|
...req.state,
|
|
10
9
|
...(res ? res.newState : {}),
|
|
11
10
|
...req.actionData(),
|
|
12
|
-
...(res ? res.data : {})
|
|
13
|
-
c,
|
|
14
|
-
configuration: c
|
|
11
|
+
...(res ? res.data : {})
|
|
15
12
|
};
|
|
16
13
|
};
|
|
@@ -41,7 +41,7 @@ function wrapPluginFunction (
|
|
|
41
41
|
return true;
|
|
42
42
|
}
|
|
43
43
|
const reducers = preprocessedItems.get(codeBlockName);
|
|
44
|
-
return router.processReducers(reducers, req, res, postBack,
|
|
44
|
+
return router.processReducers(reducers, req, res, postBack, action, true);
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
47
|
|