wingbot 3.59.0 → 3.59.2
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/plugins/ai.wingbot.openai/plugin.js +22 -0
- package/src/Processor.js +28 -5
- package/src/Responder.js +3 -2
package/package.json
CHANGED
|
@@ -123,6 +123,28 @@ function chatgptPlugin (params, configuration = {}) {
|
|
|
123
123
|
.forEach((t) => {
|
|
124
124
|
let trim = t.trim();
|
|
125
125
|
|
|
126
|
+
if (annotation) {
|
|
127
|
+
// replace the annotation first
|
|
128
|
+
|
|
129
|
+
const replacements = annotation.split(MSG_REPLACE);
|
|
130
|
+
const last = replacements.length > 1
|
|
131
|
+
? replacements.length - 1
|
|
132
|
+
: replacements.length;
|
|
133
|
+
replacements.forEach((r, i) => {
|
|
134
|
+
const foundI = trim.indexOf(r.trim(), i === last
|
|
135
|
+
? trim.length - r.trim().length
|
|
136
|
+
: 0);
|
|
137
|
+
|
|
138
|
+
if (foundI === -1
|
|
139
|
+
|| (i === 0 && foundI > 0)
|
|
140
|
+
|| (i === last && (trim.length - foundI - r.length) > 0)) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
trim = trim.replace(r.trim(), '').trim();
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
126
148
|
if (annotation && annotation.includes(MSG_REPLACE)) {
|
|
127
149
|
trim = annotation.replace(MSG_REPLACE, trim);
|
|
128
150
|
} else if (annotation) {
|
package/src/Processor.js
CHANGED
|
@@ -527,7 +527,14 @@ class Processor extends EventEmitter {
|
|
|
527
527
|
}
|
|
528
528
|
}
|
|
529
529
|
|
|
530
|
-
async _processMessage (
|
|
530
|
+
async _processMessage (
|
|
531
|
+
message,
|
|
532
|
+
pageId,
|
|
533
|
+
messageSender,
|
|
534
|
+
responderData,
|
|
535
|
+
preloadPromise = null,
|
|
536
|
+
senderMeta = null
|
|
537
|
+
) {
|
|
531
538
|
let senderId = message.sender && message.sender.id;
|
|
532
539
|
const fromEvent = !!preloadPromise;
|
|
533
540
|
|
|
@@ -663,7 +670,8 @@ class Processor extends EventEmitter {
|
|
|
663
670
|
token,
|
|
664
671
|
options,
|
|
665
672
|
responderData,
|
|
666
|
-
configuration
|
|
673
|
+
configuration,
|
|
674
|
+
senderMeta
|
|
667
675
|
);
|
|
668
676
|
const postBack = this._createPostBack(postbackAcumulator, req, res, features);
|
|
669
677
|
|
|
@@ -815,7 +823,8 @@ class Processor extends EventEmitter {
|
|
|
815
823
|
senderId,
|
|
816
824
|
pageId,
|
|
817
825
|
messageSender,
|
|
818
|
-
responderData
|
|
826
|
+
responderData,
|
|
827
|
+
res.senderMeta
|
|
819
828
|
);
|
|
820
829
|
|
|
821
830
|
await emitPromise; // probably has been resolved this time
|
|
@@ -906,7 +915,14 @@ class Processor extends EventEmitter {
|
|
|
906
915
|
});
|
|
907
916
|
}
|
|
908
917
|
|
|
909
|
-
_processPostbacks (
|
|
918
|
+
_processPostbacks (
|
|
919
|
+
postbackAcumulator,
|
|
920
|
+
senderId,
|
|
921
|
+
pageId,
|
|
922
|
+
messageSender,
|
|
923
|
+
responderData,
|
|
924
|
+
senderMeta
|
|
925
|
+
) {
|
|
910
926
|
return postbackAcumulator.reduce((promise, postback) => promise
|
|
911
927
|
.then(() => postback)
|
|
912
928
|
.then(({ action, data = {}, features }) => {
|
|
@@ -917,7 +933,14 @@ class Processor extends EventEmitter {
|
|
|
917
933
|
request = Request.postBack(senderId, action, data);
|
|
918
934
|
}
|
|
919
935
|
Object.assign(request, { features });
|
|
920
|
-
return this._processMessage(
|
|
936
|
+
return this._processMessage(
|
|
937
|
+
request,
|
|
938
|
+
pageId,
|
|
939
|
+
messageSender,
|
|
940
|
+
responderData,
|
|
941
|
+
null,
|
|
942
|
+
senderMeta
|
|
943
|
+
);
|
|
921
944
|
}), Promise.resolve({}));
|
|
922
945
|
}
|
|
923
946
|
|
package/src/Responder.js
CHANGED
|
@@ -102,7 +102,8 @@ class Responder {
|
|
|
102
102
|
token = null,
|
|
103
103
|
options = {},
|
|
104
104
|
data = {},
|
|
105
|
-
configuration = {}
|
|
105
|
+
configuration = {},
|
|
106
|
+
senderMeta = null
|
|
106
107
|
) {
|
|
107
108
|
this._messageSender = messageSender;
|
|
108
109
|
this._senderId = senderId;
|
|
@@ -190,7 +191,7 @@ class Responder {
|
|
|
190
191
|
this._trackAsAction = null;
|
|
191
192
|
|
|
192
193
|
// both vars are package protected
|
|
193
|
-
this._senderMeta = { flag: null };
|
|
194
|
+
this._senderMeta = senderMeta || { flag: null };
|
|
194
195
|
|
|
195
196
|
this._persona = null;
|
|
196
197
|
|