wingbot 3.67.17 → 3.67.19
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/ReturnSender.js +45 -0
- package/src/Tester.js +1 -1
- package/src/testTools/AnyResponseAssert.js +29 -0
package/package.json
CHANGED
package/src/ReturnSender.js
CHANGED
|
@@ -465,6 +465,28 @@ class ReturnSender {
|
|
|
465
465
|
throw new Error('#upload() not supported by this channel');
|
|
466
466
|
}
|
|
467
467
|
|
|
468
|
+
_isVisibleMessage (event, needTitle = true) {
|
|
469
|
+
// @todo is also in orchestrator
|
|
470
|
+
|
|
471
|
+
if (event.message) {
|
|
472
|
+
return !!(event.message.text
|
|
473
|
+
|| event.message.attachment
|
|
474
|
+
|| event.message.attachments);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
if (event.sender_action) {
|
|
478
|
+
return true;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
if (event.postback
|
|
482
|
+
&& (!needTitle || event.postback.title)) {
|
|
483
|
+
|
|
484
|
+
return true;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
return false;
|
|
488
|
+
}
|
|
489
|
+
|
|
468
490
|
send (payload) {
|
|
469
491
|
if (this._finished) {
|
|
470
492
|
throw new Error('Cannot send message after sender is finished');
|
|
@@ -483,6 +505,29 @@ class ReturnSender {
|
|
|
483
505
|
return;
|
|
484
506
|
}
|
|
485
507
|
|
|
508
|
+
const lastInQueue = this._queue[this._queue.length - 1];
|
|
509
|
+
|
|
510
|
+
if (payload.set_context
|
|
511
|
+
&& !this._isVisibleMessage(payload, false)
|
|
512
|
+
&& lastInQueue
|
|
513
|
+
&& this._isVisibleMessage(lastInQueue)) {
|
|
514
|
+
|
|
515
|
+
const { set_context: setContext, ...rest } = payload;
|
|
516
|
+
|
|
517
|
+
Object.assign(
|
|
518
|
+
lastInQueue,
|
|
519
|
+
rest,
|
|
520
|
+
lastInQueue,
|
|
521
|
+
{
|
|
522
|
+
set_context: {
|
|
523
|
+
...lastInQueue.set_context,
|
|
524
|
+
...setContext
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
);
|
|
528
|
+
return;
|
|
529
|
+
}
|
|
530
|
+
|
|
486
531
|
const text = extractText(payload);
|
|
487
532
|
if (text) {
|
|
488
533
|
this._responseTexts.push(text);
|
package/src/Tester.js
CHANGED
|
@@ -19,7 +19,7 @@ const Router = require('./Router'); // eslint-disable-line no-unused-vars
|
|
|
19
19
|
const ReducerWrapper = require('./ReducerWrapper'); // eslint-disable-line no-unused-vars
|
|
20
20
|
const { FEATURE_TEXT } = require('./features');
|
|
21
21
|
|
|
22
|
-
/** @typedef {import('./Processor').ProcessorOptions} ProcessorOptions */
|
|
22
|
+
/** @typedef {import('./Processor').ProcessorOptions<Router>} ProcessorOptions */
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* Utility for testing requests
|
|
@@ -116,6 +116,35 @@ class AnyResponseAssert {
|
|
|
116
116
|
return this;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
+
/**
|
|
120
|
+
* Checks for missing quick response text
|
|
121
|
+
*
|
|
122
|
+
* @param {string} search
|
|
123
|
+
* @returns {this}
|
|
124
|
+
*
|
|
125
|
+
* @memberOf ResponseAssert
|
|
126
|
+
*/
|
|
127
|
+
quickReplyTextNotContains (search) {
|
|
128
|
+
const ok = this.responses
|
|
129
|
+
.every((res) => !asserts.quickReplyText(res, search, false));
|
|
130
|
+
|
|
131
|
+
if (!ok) {
|
|
132
|
+
const actual = this.responses
|
|
133
|
+
.map((res) => asserts.getQuickReplies(res))
|
|
134
|
+
.filter((replies) => !!replies)
|
|
135
|
+
.reduce((a, replies) => {
|
|
136
|
+
for (const { title } of replies) {
|
|
137
|
+
if (title) {
|
|
138
|
+
a.push(title);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return a;
|
|
142
|
+
}, []);
|
|
143
|
+
assert.fail(m('Quick reply should not be found', search, actual));
|
|
144
|
+
}
|
|
145
|
+
return this;
|
|
146
|
+
}
|
|
147
|
+
|
|
119
148
|
/**
|
|
120
149
|
* Checks template type
|
|
121
150
|
*
|