wingbot 3.73.2 → 3.73.3
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 +1 -1
- package/src/OrchestratorClient.js +43 -0
package/package.json
CHANGED
|
@@ -18,6 +18,7 @@ const extractText = require('./transcript/extractText');
|
|
|
18
18
|
* @property {string} [pageId]
|
|
19
19
|
* @property {string} [appId]
|
|
20
20
|
* @property {Function} [fetch]
|
|
21
|
+
* @property {boolean} [mock]
|
|
21
22
|
*/
|
|
22
23
|
|
|
23
24
|
class OrchestratorClient {
|
|
@@ -32,6 +33,7 @@ class OrchestratorClient {
|
|
|
32
33
|
this._senderId = options.senderId;
|
|
33
34
|
this._pageId = options.pageId;
|
|
34
35
|
this._fetch = options.fetch || fetch;
|
|
36
|
+
this._mock = !!options.mock;
|
|
35
37
|
}
|
|
36
38
|
|
|
37
39
|
/**
|
|
@@ -214,6 +216,47 @@ class OrchestratorClient {
|
|
|
214
216
|
* @param {object} payload
|
|
215
217
|
*/
|
|
216
218
|
async _send (payload) {
|
|
219
|
+
if (this._mock) {
|
|
220
|
+
const [, queryName] = payload.query.match(/^[a-z]+\s+([a-z]+)/i);
|
|
221
|
+
|
|
222
|
+
switch (queryName) {
|
|
223
|
+
case 'GetConversationToken':
|
|
224
|
+
return {
|
|
225
|
+
data: {
|
|
226
|
+
chat: {
|
|
227
|
+
conversationToken: 'mock-token'
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
};
|
|
231
|
+
case 'FetchHistory':
|
|
232
|
+
return {
|
|
233
|
+
data: {
|
|
234
|
+
chat: {
|
|
235
|
+
history: {
|
|
236
|
+
events: [
|
|
237
|
+
{
|
|
238
|
+
sender: {
|
|
239
|
+
id: this._senderId || 'sender'
|
|
240
|
+
},
|
|
241
|
+
recipient: {
|
|
242
|
+
id: this._pageId || 'sender'
|
|
243
|
+
},
|
|
244
|
+
message: {
|
|
245
|
+
text: 'Hello'
|
|
246
|
+
},
|
|
247
|
+
timestamp: 1234567890123
|
|
248
|
+
}
|
|
249
|
+
]
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
default:
|
|
256
|
+
return {};
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
217
260
|
const body = JSON.stringify(payload);
|
|
218
261
|
|
|
219
262
|
const token = await BotAppSender.signBody(
|