@tiledesk/tiledesk-tybot-connector 2.5.0 → 2.6.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/CHANGELOG.md +1 -52
- package/ExtUtil.js +1 -0
- package/TdCache copy.js +242 -0
- package/TiledeskExpression.js +1 -6
- package/TiledeskWhenExpression.js +1 -18
- package/engine/MongodbBotsDataSource.js +1 -3
- package/engine/MongodbIntentsMachine.js +2 -3
- package/engine/TiledeskChatbot.js +4 -76
- package/engine/TiledeskChatbotConst.js +1 -7
- package/engine/mock/MockBotsDataSource.js +6 -11
- package/index.js +36 -132
- package/models/faq_kb.js +0 -11
- package/package.json +1 -1
- package/services/AIController.js +1 -31
- package/services/AIService.js +33 -62
- package/services/IntegrationService.js +1 -4
- package/services/{LLMService.js → KbService.js} +3 -3
- package/services/RequestService.js +2 -23
- package/services/TilebotService.js +3 -19
- package/tiledeskChatbotPlugs/DirectivesChatbotPlug.js +17 -34
- package/tiledeskChatbotPlugs/directives/DirAiCondition.js +51 -18
- package/tiledeskChatbotPlugs/directives/DirAiPrompt.js +52 -103
- package/tiledeskChatbotPlugs/directives/DirAskGPTV2.js +5 -108
- package/tiledeskChatbotPlugs/directives/DirCallSubagent.js +8 -34
- package/tiledeskChatbotPlugs/directives/DirCaptureUserReply.js +11 -36
- package/tiledeskChatbotPlugs/directives/DirGptTask.js +4 -16
- package/tiledeskChatbotPlugs/directives/DirIntent.js +6 -12
- package/tiledeskChatbotPlugs/directives/DirIteration.js +10 -63
- package/tiledeskChatbotPlugs/directives/DirMoveToAgent.js +16 -69
- package/tiledeskChatbotPlugs/directives/DirRemoveCurrentBot.js +2 -40
- package/tiledeskChatbotPlugs/directives/DirReply.js +6 -81
- package/tiledeskChatbotPlugs/directives/DirReplyV2.js +4 -58
- package/tiledeskChatbotPlugs/directives/DirWebRequest.js +0 -8
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2.js +1 -11
- package/tiledeskChatbotPlugs/directives/DirWebRequestV2_old.js +418 -0
- package/tiledeskChatbotPlugs/directives/DirWebResponse.js +2 -5
- package/tiledeskChatbotPlugs/directives/Directives.js +0 -6
- package/utils/HttpUtils.js +17 -99
- package/utils/TiledeskChatbotUtil.js +5 -73
- package/utils/winston.js +2 -80
- package/services/InternalSubAgentService.js +0 -330
- package/tiledeskChatbotPlugs/directives/DirInviteHuman.js +0 -259
- package/tiledeskChatbotPlugs/directives/DirInvokeSubAgent.js +0 -345
- package/tiledeskChatbotPlugs/directives/DirJSONConditionMulti.js +0 -171
- package/tiledeskChatbotPlugs/directives/DirRemoveHuman.js +0 -129
- package/tiledeskChatbotPlugs/directives/DirReturn.js +0 -98
- package/utils/ConnectorsV3.js +0 -292
- package/utils/LlmStream.js +0 -215
- package/utils/SentenceChunker.js +0 -94
- package/utils/StreamSender.js +0 -109
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
const { DirIntent } = require('./DirIntent');
|
|
2
|
-
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
3
|
-
const { TiledeskWhenExpression } = require('../../TiledeskWhenExpression');
|
|
4
|
-
const winston = require('../../utils/winston');
|
|
5
|
-
const { Logger } = require('../../Logger');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* DirJSONConditionMulti
|
|
9
|
-
*
|
|
10
|
-
* Multi-branch condition: N cases evaluated IN ORDER, each with its own exit.
|
|
11
|
-
* The first case whose `when` is true routes the flow to its own block and the
|
|
12
|
-
* action stops there; the remaining cases are never evaluated. When no case
|
|
13
|
-
* matches, the flow leaves through `elseIntent`.
|
|
14
|
-
*
|
|
15
|
-
* It replaces the chain of single conditions (each one's false branch feeding
|
|
16
|
-
* the next) with one block that has one exit per case.
|
|
17
|
-
*
|
|
18
|
-
* Rules (see design-studio docs/V3/multi-conditions-piano.md):
|
|
19
|
-
* 1. cases are evaluated in order; the first true one wins and stops the chain;
|
|
20
|
-
* 2. a case with no `when` (or an empty one) is SKIPPED, never taken as true —
|
|
21
|
-
* an empty case at the top would otherwise swallow all the traffic;
|
|
22
|
-
* 3. an evaluation error on a case counts as "no match": `flowError` is set and
|
|
23
|
-
* the next case is tried, so one broken case does not shadow the sound ones
|
|
24
|
-
* that follow it;
|
|
25
|
-
* 4. a case that matches but has no target block advances to the next action,
|
|
26
|
-
* exactly as DirJSONConditionV2 does with an unset trueIntent;
|
|
27
|
-
* 5. no case matched -> `elseIntent`; unset, the next action runs;
|
|
28
|
-
* 6. nothing usable at all -> a warning, and the chain advances.
|
|
29
|
-
*
|
|
30
|
-
* There is no legacy delegation here (unlike DirJSONConditionV2): this action
|
|
31
|
-
* type is new, so no bot can carry an older shape of it.
|
|
32
|
-
*
|
|
33
|
-
* The callback contract matches the dispatcher (DirectivesChatbotPlug): the
|
|
34
|
-
* callback is invoked with `stop` (truthy halts the directive chain) and is
|
|
35
|
-
* guaranteed to be called EXACTLY ONCE on every path, including errors.
|
|
36
|
-
*/
|
|
37
|
-
class DirJSONConditionMulti {
|
|
38
|
-
|
|
39
|
-
constructor(context) {
|
|
40
|
-
if (!context) {
|
|
41
|
-
throw new Error('context object is mandatory.');
|
|
42
|
-
}
|
|
43
|
-
this.context = context;
|
|
44
|
-
this.chatbot = context.chatbot;
|
|
45
|
-
this.requestId = this.context.requestId;
|
|
46
|
-
|
|
47
|
-
this.intentDir = new DirIntent(context);
|
|
48
|
-
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.intent_id || this.context.reply?.attributes?.intent_info?.intent_id });
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
execute(directive, callback) {
|
|
52
|
-
winston.verbose("Execute JSONConditionMulti directive");
|
|
53
|
-
let action;
|
|
54
|
-
if (directive.action) {
|
|
55
|
-
action = directive.action;
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
this.logger.error("Incorrect action for ", directive.name, directive);
|
|
59
|
-
winston.warn("DirJSONConditionMulti Incorrect directive: ", directive);
|
|
60
|
-
callback();
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
this.go(action, (stop) => {
|
|
65
|
-
this.logger.native("[ConditionMulti] Executed");
|
|
66
|
-
callback(stop);
|
|
67
|
-
}).catch((err) => {
|
|
68
|
-
// Last-resort net: never leave the directive chain hanging.
|
|
69
|
-
winston.error("(DirJSONConditionMulti) Unhandled error in go(): " + (err && err.message));
|
|
70
|
-
callback();
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
async go(action, callback) {
|
|
75
|
-
// Guarantee the callback fires exactly once, regardless of which branch/throw occurs.
|
|
76
|
-
let finished = false;
|
|
77
|
-
const done = (stop) => {
|
|
78
|
-
if (finished) return;
|
|
79
|
-
finished = true;
|
|
80
|
-
callback(stop);
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
try {
|
|
84
|
-
const cases = Array.isArray(action.cases) ? action.cases : [];
|
|
85
|
-
const elseIntent = this.#cleanIntent(action.elseIntent);
|
|
86
|
-
const elseIntentAttributes = action.elseIntentAttributes;
|
|
87
|
-
// Same decision as V2: a matched case always stops the chain.
|
|
88
|
-
const stopOnConditionMet = true;
|
|
89
|
-
|
|
90
|
-
const evaluable = cases.filter((c) => c && typeof c.when === 'string' && c.when.trim() !== "");
|
|
91
|
-
if (evaluable.length === 0 && !elseIntent) {
|
|
92
|
-
this.logger.warn("[ConditionMulti] Invalid action: no evaluable case and no elseIntent");
|
|
93
|
-
winston.warn("(DirJSONConditionMulti) No evaluable case and no elseIntent");
|
|
94
|
-
done();
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
if (evaluable.length !== cases.length) {
|
|
98
|
-
// Rule 2. Worth saying out loud: an unfinished case in the editor is a branch
|
|
99
|
-
// of the flow that silently never fires.
|
|
100
|
-
winston.verbose("(DirJSONConditionMulti) " + (cases.length - evaluable.length) + " case(s) without a condition were skipped");
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// Load conversation variables (native-typed) from cache, once for every case.
|
|
104
|
-
let variables = {};
|
|
105
|
-
if (this.context.tdcache) {
|
|
106
|
-
variables = await TiledeskChatbot.allParametersStatic(this.context.tdcache, this.context.requestId) || {};
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
109
|
-
winston.error("(DirJSONConditionMulti) No this.context.tdcache — evaluating with empty variables");
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const expression = new TiledeskWhenExpression();
|
|
113
|
-
for (let i = 0; i < evaluable.length; i++) {
|
|
114
|
-
const branch = evaluable[i];
|
|
115
|
-
const label = branch.label || branch._tdCaseId || ('#' + (i + 1));
|
|
116
|
-
let result;
|
|
117
|
-
try {
|
|
118
|
-
const value = expression.evaluate(branch.when, variables);
|
|
119
|
-
result = (value === null || value === undefined) ? false : Boolean(value);
|
|
120
|
-
}
|
|
121
|
-
catch (err) {
|
|
122
|
-
// Rule 3: a broken case is not a match, and it does not shadow the ones below it.
|
|
123
|
-
winston.error("(DirJSONConditionMulti) Error evaluating case '" + label + "': " + (err && err.message));
|
|
124
|
-
this.logger.error("[ConditionMulti] An error occurred evaluating case '" + label + "'");
|
|
125
|
-
if (this.context.tdcache) {
|
|
126
|
-
await TiledeskChatbot.addParameterStatic(this.context.tdcache, this.context.requestId, "flowError", "An error occurred evaluating condition '" + label + "' (when)");
|
|
127
|
-
}
|
|
128
|
-
result = false;
|
|
129
|
-
}
|
|
130
|
-
winston.debug("(DirJSONConditionMulti) case '" + label + "' -> " + result);
|
|
131
|
-
if (!result) continue;
|
|
132
|
-
|
|
133
|
-
this.logger.native("[ConditionMulti] Case '" + label + "' matched");
|
|
134
|
-
const intent = this.#cleanIntent(branch.intent);
|
|
135
|
-
if (!intent) {
|
|
136
|
-
// Rule 4: the switch is decided, but there is nowhere to go.
|
|
137
|
-
this.logger.native("[ConditionMulti] Case '" + label + "' has no target block");
|
|
138
|
-
winston.warn("(DirJSONConditionMulti) Matched case '" + label + "' has no intent");
|
|
139
|
-
done();
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
this.intentDir.execute(DirIntent.intentDirectiveFor(intent, branch.intentAttributes), () => done(stopOnConditionMet));
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// Rule 5: nothing matched.
|
|
147
|
-
this.logger.native("[ConditionMulti] No case matched");
|
|
148
|
-
if (elseIntent) {
|
|
149
|
-
this.intentDir.execute(DirIntent.intentDirectiveFor(elseIntent, elseIntentAttributes), () => done(stopOnConditionMet));
|
|
150
|
-
}
|
|
151
|
-
else {
|
|
152
|
-
this.logger.native("[ConditionMulti] No elseIntent specified");
|
|
153
|
-
done();
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
catch (err) {
|
|
157
|
-
winston.error("(DirJSONConditionMulti) Unexpected error in go(): " + (err && err.message));
|
|
158
|
-
done(); // advance the chain rather than hang
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/** An intent that is missing, or blank, is an unconnected exit — not a target. */
|
|
163
|
-
#cleanIntent(intent) {
|
|
164
|
-
if (typeof intent !== 'string') return null;
|
|
165
|
-
const trimmed = intent.trim();
|
|
166
|
-
return trimmed === "" ? null : trimmed;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
module.exports = { DirJSONConditionMulti };
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
const { DirIntent } = require('./DirIntent');
|
|
2
|
-
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
3
|
-
const { DirInviteHuman } = require('./DirInviteHuman');
|
|
4
|
-
const httpUtils = require('../../utils/HttpUtils');
|
|
5
|
-
const winston = require('../../utils/winston');
|
|
6
|
-
const { Logger } = require('../../Logger');
|
|
7
|
-
|
|
8
|
-
class DirRemoveHuman {
|
|
9
|
-
|
|
10
|
-
constructor(context) {
|
|
11
|
-
if (!context) {
|
|
12
|
-
throw new Error('context object is mandatory.');
|
|
13
|
-
}
|
|
14
|
-
this.context = context;
|
|
15
|
-
this.chatbot = context.chatbot;
|
|
16
|
-
this.requestId = context.requestId;
|
|
17
|
-
this.projectId = context.projectId;
|
|
18
|
-
this.token = context.token;
|
|
19
|
-
this.tdcache = context.tdcache;
|
|
20
|
-
this.API_ENDPOINT = context.API_ENDPOINT;
|
|
21
|
-
this.intentDir = new DirIntent(context);
|
|
22
|
-
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.intent_id || this.context.reply?.attributes?.intent_info?.intent_id });
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
execute(directive, callback) {
|
|
26
|
-
winston.verbose("Execute RemoveHuman directive");
|
|
27
|
-
let called = false;
|
|
28
|
-
const safeCallback = (stop) => {
|
|
29
|
-
if (called) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
called = true;
|
|
33
|
-
callback(stop);
|
|
34
|
-
};
|
|
35
|
-
if (!directive || !directive.action) {
|
|
36
|
-
this.logger.error("[Remove Human] Incorrect action for ", directive?.name, directive);
|
|
37
|
-
winston.warn("(DirRemoveHuman) Incorrect directive: ", directive);
|
|
38
|
-
safeCallback();
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
this.go(directive.action, (stop) => {
|
|
42
|
-
safeCallback(stop);
|
|
43
|
-
}).catch((err) => {
|
|
44
|
-
winston.error("(DirRemoveHuman) unexpected error: " + JSON.stringify(DirInviteHuman.errorSummary(err)));
|
|
45
|
-
safeCallback();
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
async go(action, callback) {
|
|
50
|
-
const trueIntent = action.trueIntent;
|
|
51
|
-
const falseIntent = action.falseIntent;
|
|
52
|
-
|
|
53
|
-
if (this.requestId && this.requestId.startsWith(DirInviteHuman.AUTOMATION_PREFIX)) {
|
|
54
|
-
this.logger.error("[Remove Human] requires a conversation");
|
|
55
|
-
await this.setParameter("flowError", "(Remove human) requires a conversation");
|
|
56
|
-
this.jump(falseIntent, action.falseIntentAttributes, callback);
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
let result;
|
|
61
|
-
try {
|
|
62
|
-
result = await this.remove({ scope: DirRemoveHuman.normalizeScope(action.scope) });
|
|
63
|
-
} catch (err) {
|
|
64
|
-
const summary = DirInviteHuman.errorSummary(err);
|
|
65
|
-
this.logger.error("[Remove Human] Error: " + summary.message);
|
|
66
|
-
winston.error("(DirRemoveHuman) remove error: " + JSON.stringify(summary));
|
|
67
|
-
await this.setParameter("flowError", "(Remove human) An error occurred: " + summary.message);
|
|
68
|
-
this.jump(falseIntent, action.falseIntentAttributes, callback);
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const removed = (result && Array.isArray(result.removed)) ? result.removed : [];
|
|
73
|
-
await this.setParameter("removed_humans", removed);
|
|
74
|
-
await this.setParameter("removed_humans_count", removed.length);
|
|
75
|
-
this.logger.native("[Remove Human] Removed: " + (removed.length > 0 ? removed.map((r) => r.fullname || r.id_user).join(', ') : 'nobody'));
|
|
76
|
-
this.jump(trueIntent, action.trueIntentAttributes, callback);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
jump(intent, attributes, callback) {
|
|
80
|
-
if (!intent) {
|
|
81
|
-
callback();
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
const intentDirective = DirIntent.intentDirectiveFor(intent, attributes);
|
|
85
|
-
this.intentDir.execute(intentDirective, () => {
|
|
86
|
-
callback(true);
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
async setParameter(name, value) {
|
|
91
|
-
try {
|
|
92
|
-
if (this.chatbot) {
|
|
93
|
-
await this.chatbot.addParameter(name, value);
|
|
94
|
-
} else if (this.tdcache) {
|
|
95
|
-
await TiledeskChatbot.addParameterStatic(this.tdcache, this.requestId, name, value);
|
|
96
|
-
}
|
|
97
|
-
} catch (err) {
|
|
98
|
-
winston.error("(DirRemoveHuman) error setting parameter " + name + ": " + JSON.stringify(DirInviteHuman.errorSummary(err)));
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
remove(body) {
|
|
103
|
-
return new Promise((resolve, reject) => {
|
|
104
|
-
const HTTPREQUEST = {
|
|
105
|
-
url: `${this.API_ENDPOINT}/${this.projectId}/requests/${this.requestId}/participants/remove`,
|
|
106
|
-
headers: {
|
|
107
|
-
'Content-Type': 'application/json',
|
|
108
|
-
'Authorization': DirInviteHuman.fixToken(this.token)
|
|
109
|
-
},
|
|
110
|
-
json: body,
|
|
111
|
-
method: 'POST',
|
|
112
|
-
timeout: DirInviteHuman.INVITE_TIMEOUT_MS
|
|
113
|
-
};
|
|
114
|
-
httpUtils.request(HTTPREQUEST, (err, resbody) => {
|
|
115
|
-
if (err) {
|
|
116
|
-
reject(err);
|
|
117
|
-
} else {
|
|
118
|
-
resolve(resbody);
|
|
119
|
-
}
|
|
120
|
-
});
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
static normalizeScope(scope) {
|
|
125
|
-
return scope === 'all_humans' ? 'all_humans' : 'invited';
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
module.exports = { DirRemoveHuman };
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
const { Filler } = require('../Filler');
|
|
2
|
-
const { TiledeskChatbot } = require('../../engine/TiledeskChatbot');
|
|
3
|
-
const { InternalSubAgentService } = require('../../services/InternalSubAgentService');
|
|
4
|
-
const { TiledeskChatbotConst } = require('../../engine/TiledeskChatbotConst');
|
|
5
|
-
const { Logger } = require('../../Logger');
|
|
6
|
-
const winston = require('../../utils/winston');
|
|
7
|
-
|
|
8
|
-
class DirReturn {
|
|
9
|
-
|
|
10
|
-
constructor(context) {
|
|
11
|
-
if (!context) {
|
|
12
|
-
throw new Error('context object is mandatory.');
|
|
13
|
-
}
|
|
14
|
-
this.context = context;
|
|
15
|
-
this.projectId = context.projectId;
|
|
16
|
-
this.requestId = context.requestId;
|
|
17
|
-
this.token = context.token;
|
|
18
|
-
this.tdcache = context.tdcache;
|
|
19
|
-
this.logger = new Logger({ request_id: this.requestId, dev: this.context.supportRequest?.draft, intent_id: this.context.reply?.intent_id || this.context.reply?.attributes?.intent_info?.intent_id });
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
execute(directive, callback) {
|
|
23
|
-
const action = directive.action;
|
|
24
|
-
if (!action) {
|
|
25
|
-
this.logger.error('[Return] Incorrect action for ', directive.name, directive);
|
|
26
|
-
callback();
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
this.go(action, () => {
|
|
31
|
-
this.logger.native('[Return] Executed');
|
|
32
|
-
callback();
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async go(action, callback) {
|
|
37
|
-
if (!this.tdcache) {
|
|
38
|
-
winston.error('(DirReturn) tdcache is mandatory');
|
|
39
|
-
callback();
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const requestAttributes = await TiledeskChatbot.allParametersStatic(this.tdcache, this.requestId);
|
|
44
|
-
const filler = new Filler();
|
|
45
|
-
const filledStatus = filler.fill(action.status, requestAttributes);
|
|
46
|
-
|
|
47
|
-
let payload;
|
|
48
|
-
try {
|
|
49
|
-
payload = await this.#resolvePayload(action, filler, requestAttributes);
|
|
50
|
-
} catch (error) {
|
|
51
|
-
winston.error('(DirReturn) Error building return payload: ', error);
|
|
52
|
-
this.logger.error('[Return] Error building payload');
|
|
53
|
-
callback();
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const returnMessage = {
|
|
58
|
-
status: filledStatus,
|
|
59
|
-
payload: payload
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
this.logger.native('[Return] payload: ', returnMessage);
|
|
63
|
-
|
|
64
|
-
const topic = InternalSubAgentService.webhookTopic(this.requestId);
|
|
65
|
-
const readyKey = TiledeskChatbotConst.redisWebhookReadyKey(this.requestId);
|
|
66
|
-
try {
|
|
67
|
-
const serialized = JSON.stringify(returnMessage);
|
|
68
|
-
await this.tdcache.publish(topic, serialized);
|
|
69
|
-
await this.tdcache.set(readyKey, serialized, { EX: 120 });
|
|
70
|
-
winston.verbose('(DirReturn) Published return to topic: ' + topic);
|
|
71
|
-
} catch (error) {
|
|
72
|
-
winston.error('(DirReturn) Error publishing return: ', error);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
callback();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
async #resolvePayload(action, filler, requestAttributes) {
|
|
79
|
-
if (action.payload && action.bodyType === 'json') {
|
|
80
|
-
const jsonBody = filler.fill(action.payload, requestAttributes);
|
|
81
|
-
try {
|
|
82
|
-
return JSON.parse(jsonBody);
|
|
83
|
-
} catch (error) {
|
|
84
|
-
winston.error('(DirReturn) Error parsing json payload: ' + jsonBody, error);
|
|
85
|
-
this.logger.error('[Return] Error parsing json payload ', jsonBody);
|
|
86
|
-
throw error;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
if (action.payload !== undefined && action.payload !== null) {
|
|
91
|
-
return InternalSubAgentService.fillValue(action.payload, requestAttributes);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return null;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
module.exports = { DirReturn };
|