wingbot 3.33.2 → 3.35.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
CHANGED
package/src/BotApp.js
CHANGED
|
@@ -46,6 +46,15 @@ const DEFAULT_API_URL = 'https://orchestrator-api.wingbot.ai';
|
|
|
46
46
|
* @prop {object} headers
|
|
47
47
|
*/
|
|
48
48
|
|
|
49
|
+
function defaultMsg (senderId, pageId) {
|
|
50
|
+
return {
|
|
51
|
+
sender: { id: senderId },
|
|
52
|
+
recipient: { id: pageId },
|
|
53
|
+
mid: null,
|
|
54
|
+
timestamp: Date.now()
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
49
58
|
/**
|
|
50
59
|
* Adapter for Wingbot flight director
|
|
51
60
|
*
|
|
@@ -239,32 +248,53 @@ class BotApp {
|
|
|
239
248
|
};
|
|
240
249
|
}
|
|
241
250
|
|
|
251
|
+
const sender = await this.createSender(senderId, pageId, message);
|
|
252
|
+
const res = await this._processor.processMessage(message, pageId, sender, { appId });
|
|
253
|
+
await this._processSenderResponses(sender, senderId, pageId, headers);
|
|
254
|
+
|
|
255
|
+
return {
|
|
256
|
+
status: res.status,
|
|
257
|
+
response_to_mid: message.mid,
|
|
258
|
+
messaging: []
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Creates a Sender to be able, for example, to upload files
|
|
264
|
+
*
|
|
265
|
+
* @param {string} senderId
|
|
266
|
+
* @param {string} pageId
|
|
267
|
+
* @param {object} [message]
|
|
268
|
+
* @param {string|Promise<string>} [secret]
|
|
269
|
+
* @returns {Promise<BotAppSender>}
|
|
270
|
+
*/
|
|
271
|
+
async createSender (
|
|
272
|
+
senderId,
|
|
273
|
+
pageId,
|
|
274
|
+
message = defaultMsg(senderId, pageId),
|
|
275
|
+
secret = this._secret
|
|
276
|
+
) {
|
|
277
|
+
const useSecret = await Promise.resolve(secret);
|
|
278
|
+
|
|
279
|
+
const setResponseToMid = message.response_to_mid || message.mid;
|
|
280
|
+
|
|
242
281
|
const options = {
|
|
243
282
|
...this._returnSenderOptions,
|
|
244
283
|
apiUrl: this._apiUrl,
|
|
245
284
|
pageId,
|
|
246
|
-
appId,
|
|
247
|
-
secret,
|
|
285
|
+
appId: this._appId,
|
|
286
|
+
secret: useSecret,
|
|
248
287
|
mid: setResponseToMid,
|
|
249
288
|
fetch: this._fetch,
|
|
250
289
|
tls: this._tls
|
|
251
290
|
};
|
|
252
291
|
|
|
253
|
-
|
|
254
|
-
const res = await this._processor.processMessage(message, pageId, sender, { appId });
|
|
255
|
-
await this._processSenderResponses(sender, senderId, pageId, headers);
|
|
256
|
-
|
|
257
|
-
return {
|
|
258
|
-
status: res.status,
|
|
259
|
-
response_to_mid: message.mid,
|
|
260
|
-
messaging: []
|
|
261
|
-
};
|
|
292
|
+
return new BotAppSender(options, senderId, message, this._senderLogger);
|
|
262
293
|
}
|
|
263
294
|
|
|
264
295
|
/**
|
|
265
296
|
* Compatibility method for Notification engine
|
|
266
297
|
*
|
|
267
|
-
* @deprecated
|
|
268
298
|
* @param {object} message - wingbot chat event
|
|
269
299
|
* @param {string} senderId - chat event sender identifier
|
|
270
300
|
* @param {string} pageId - channel/page identifier
|
package/src/resolvers/utils.js
CHANGED
|
@@ -14,6 +14,7 @@ const TYPE_SHARE = 'element_share';
|
|
|
14
14
|
const TYPE_URL = 'web_url';
|
|
15
15
|
const TYPE_URL_WITH_EXT = 'web_url_extension';
|
|
16
16
|
const TYPE_POSTBACK = 'postback';
|
|
17
|
+
const TYPE_ATTACHMENT = 'attachment';
|
|
17
18
|
|
|
18
19
|
const WEBVIEW_FULL = 'full';
|
|
19
20
|
const WEBVIEW_TALL = 'tall';
|
|
@@ -227,10 +228,11 @@ function processButtons (
|
|
|
227
228
|
editableCondition,
|
|
228
229
|
setState
|
|
229
230
|
}) => {
|
|
231
|
+
|
|
230
232
|
if (hasCondition) {
|
|
231
233
|
const condition = getCondition({
|
|
232
234
|
hasCondition, conditionFn, hasEditableCondition, editableCondition
|
|
233
|
-
}, context, '
|
|
235
|
+
}, context, 'Button condition');
|
|
234
236
|
|
|
235
237
|
if (!condition(req, res)) {
|
|
236
238
|
return;
|
|
@@ -244,7 +246,8 @@ function processButtons (
|
|
|
244
246
|
url,
|
|
245
247
|
webviewHeight = WEBVIEW_TALL,
|
|
246
248
|
targetRouteId,
|
|
247
|
-
action
|
|
249
|
+
action,
|
|
250
|
+
payload
|
|
248
251
|
} = btnAction;
|
|
249
252
|
|
|
250
253
|
const isExtUrl = type === TYPE_URL_WITH_EXT;
|
|
@@ -273,6 +276,9 @@ function processButtons (
|
|
|
273
276
|
case TYPE_SHARE:
|
|
274
277
|
elem.shareButton(btnTitleText);
|
|
275
278
|
break;
|
|
279
|
+
case TYPE_ATTACHMENT:
|
|
280
|
+
elem.attachmentButton(btnTitleText, payload);
|
|
281
|
+
break;
|
|
276
282
|
default:
|
|
277
283
|
}
|
|
278
284
|
});
|
|
@@ -6,6 +6,38 @@
|
|
|
6
6
|
const BaseTemplate = require('./BaseTemplate');
|
|
7
7
|
const { makeAbsolute } = require('../utils');
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @typedef MarkdownPayload
|
|
11
|
+
* @prop {"text/markdown"} contentType
|
|
12
|
+
* @prop {string} content
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Designer payload type
|
|
17
|
+
*
|
|
18
|
+
* @typedef {MarkdownPayload} Payload
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @typedef EncodedPayload
|
|
23
|
+
* @prop {string} content
|
|
24
|
+
* @prop {"text/markdown"} content_type
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Encodes different types of payloads from designer snapshot to payload for chat
|
|
29
|
+
* Content is Base64 encoded.
|
|
30
|
+
*
|
|
31
|
+
* @param {Payload} payload
|
|
32
|
+
* @returns {EncodedPayload}
|
|
33
|
+
*/
|
|
34
|
+
function encodePayload ({ content, contentType }) {
|
|
35
|
+
return {
|
|
36
|
+
content: Buffer.from(content).toString('base64'),
|
|
37
|
+
content_type: contentType
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
9
41
|
/**
|
|
10
42
|
* Helps with creating of button template
|
|
11
43
|
* Instance of button template is returned by {Responder}
|
|
@@ -92,6 +124,31 @@ class ButtonTemplate extends BaseTemplate {
|
|
|
92
124
|
return this;
|
|
93
125
|
}
|
|
94
126
|
|
|
127
|
+
/**
|
|
128
|
+
* Adds button, which opens a popup with content on click.
|
|
129
|
+
*
|
|
130
|
+
* @param {string} title
|
|
131
|
+
* @param {Payload} payload
|
|
132
|
+
* @returns {this}
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* res.button('text')
|
|
136
|
+
* .attachmentButton('button title', {
|
|
137
|
+
* content: '# Heading 1',
|
|
138
|
+
* contentType: 'text/markdown'
|
|
139
|
+
* })
|
|
140
|
+
* .send();
|
|
141
|
+
*
|
|
142
|
+
*/
|
|
143
|
+
attachmentButton (title, payload) {
|
|
144
|
+
this.buttons.push({
|
|
145
|
+
type: 'attachment',
|
|
146
|
+
title: this._t(title),
|
|
147
|
+
payload: encodePayload(payload)
|
|
148
|
+
});
|
|
149
|
+
return this;
|
|
150
|
+
}
|
|
151
|
+
|
|
95
152
|
/**
|
|
96
153
|
*
|
|
97
154
|
* @returns {this}
|
|
@@ -468,6 +468,7 @@ class CustomEntityDetectionModel {
|
|
|
468
468
|
return {
|
|
469
469
|
text: cleanText,
|
|
470
470
|
intents: [],
|
|
471
|
+
// @ts-ignore
|
|
471
472
|
entities
|
|
472
473
|
};
|
|
473
474
|
}
|
|
@@ -615,6 +616,28 @@ class CustomEntityDetectionModel {
|
|
|
615
616
|
return this;
|
|
616
617
|
}
|
|
617
618
|
|
|
619
|
+
/**
|
|
620
|
+
* Sets options to entity detector.
|
|
621
|
+
* Useful for disabling anonymization of local system entities.
|
|
622
|
+
*
|
|
623
|
+
* @param {string} name
|
|
624
|
+
* @param {object} options
|
|
625
|
+
* @param {boolean} [options.anonymize]
|
|
626
|
+
* @returns {this}
|
|
627
|
+
* @example
|
|
628
|
+
*
|
|
629
|
+
* ai.register('wingbot-model-name')
|
|
630
|
+
* .setDetectorOptions('phone', { anonymize: false })
|
|
631
|
+
* .setDetectorOptions('email', { anonymize: false })
|
|
632
|
+
*/
|
|
633
|
+
setDetectorOptions (name, options) {
|
|
634
|
+
if (!this._entityDetectors.has(name)) {
|
|
635
|
+
throw new Error('Can\'t set entity detector options. Entity "name" does not exist.');
|
|
636
|
+
}
|
|
637
|
+
Object.assign(this._entityDetectors.get(name), options);
|
|
638
|
+
return this;
|
|
639
|
+
}
|
|
640
|
+
|
|
618
641
|
async getPhrases () {
|
|
619
642
|
return this._getPhrases();
|
|
620
643
|
}
|