@botonic/plugin-flow-builder 0.56.1 → 0.57.0-alpha.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/lib/cjs/api.d.ts +2 -2
- package/lib/cjs/api.js +17 -17
- package/lib/cjs/api.js.map +1 -1
- package/lib/cjs/bot-context-manager.d.ts +17 -0
- package/lib/cjs/bot-context-manager.js +93 -0
- package/lib/cjs/bot-context-manager.js.map +1 -0
- package/lib/cjs/constants.d.ts +2 -1
- package/lib/cjs/constants.js +3 -2
- package/lib/cjs/constants.js.map +1 -1
- package/lib/cjs/content-fields/contact-reasons-conditional-matcher.d.ts +4 -0
- package/lib/cjs/content-fields/contact-reasons-conditional-matcher.js +12 -0
- package/lib/cjs/content-fields/contact-reasons-conditional-matcher.js.map +1 -0
- package/lib/cjs/content-fields/flow-contact-reasons-conditional.d.ts +13 -0
- package/lib/cjs/content-fields/flow-contact-reasons-conditional.js +45 -0
- package/lib/cjs/content-fields/flow-contact-reasons-conditional.js.map +1 -0
- package/lib/cjs/content-fields/flow-handoff.d.ts +7 -1
- package/lib/cjs/content-fields/flow-handoff.js +38 -3
- package/lib/cjs/content-fields/flow-handoff.js.map +1 -1
- package/lib/cjs/content-fields/hubtype-fields/contact-reasons-conditional.d.ts +16 -0
- package/lib/cjs/content-fields/hubtype-fields/contact-reasons-conditional.js +3 -0
- package/lib/cjs/content-fields/hubtype-fields/contact-reasons-conditional.js.map +1 -0
- package/lib/cjs/content-fields/hubtype-fields/handoff.d.ts +6 -1
- package/lib/cjs/content-fields/hubtype-fields/node-types.d.ts +2 -1
- package/lib/cjs/content-fields/hubtype-fields/node-types.js +1 -0
- package/lib/cjs/content-fields/hubtype-fields/node-types.js.map +1 -1
- package/lib/cjs/content-fields/hubtype-fields/nodes.d.ts +2 -1
- package/lib/cjs/content-fields/index.d.ts +3 -2
- package/lib/cjs/content-fields/index.js +3 -1
- package/lib/cjs/content-fields/index.js.map +1 -1
- package/lib/cjs/flow-factory.js +2 -0
- package/lib/cjs/flow-factory.js.map +1 -1
- package/lib/cjs/index.d.ts +5 -9
- package/lib/cjs/index.js +16 -67
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/types.d.ts +2 -2
- package/lib/cjs/types.js.map +1 -1
- package/lib/esm/api.d.ts +2 -2
- package/lib/esm/api.js +17 -17
- package/lib/esm/api.js.map +1 -1
- package/lib/esm/bot-context-manager.d.ts +17 -0
- package/lib/esm/bot-context-manager.js +93 -0
- package/lib/esm/bot-context-manager.js.map +1 -0
- package/lib/esm/constants.d.ts +2 -1
- package/lib/esm/constants.js +3 -2
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/content-fields/contact-reasons-conditional-matcher.d.ts +4 -0
- package/lib/esm/content-fields/contact-reasons-conditional-matcher.js +12 -0
- package/lib/esm/content-fields/contact-reasons-conditional-matcher.js.map +1 -0
- package/lib/esm/content-fields/flow-contact-reasons-conditional.d.ts +13 -0
- package/lib/esm/content-fields/flow-contact-reasons-conditional.js +45 -0
- package/lib/esm/content-fields/flow-contact-reasons-conditional.js.map +1 -0
- package/lib/esm/content-fields/flow-handoff.d.ts +7 -1
- package/lib/esm/content-fields/flow-handoff.js +38 -3
- package/lib/esm/content-fields/flow-handoff.js.map +1 -1
- package/lib/esm/content-fields/hubtype-fields/contact-reasons-conditional.d.ts +16 -0
- package/lib/esm/content-fields/hubtype-fields/contact-reasons-conditional.js +3 -0
- package/lib/esm/content-fields/hubtype-fields/contact-reasons-conditional.js.map +1 -0
- package/lib/esm/content-fields/hubtype-fields/handoff.d.ts +6 -1
- package/lib/esm/content-fields/hubtype-fields/node-types.d.ts +2 -1
- package/lib/esm/content-fields/hubtype-fields/node-types.js +1 -0
- package/lib/esm/content-fields/hubtype-fields/node-types.js.map +1 -1
- package/lib/esm/content-fields/hubtype-fields/nodes.d.ts +2 -1
- package/lib/esm/content-fields/index.d.ts +3 -2
- package/lib/esm/content-fields/index.js +3 -1
- package/lib/esm/content-fields/index.js.map +1 -1
- package/lib/esm/flow-factory.js +2 -0
- package/lib/esm/flow-factory.js.map +1 -1
- package/lib/esm/index.d.ts +5 -9
- package/lib/esm/index.js +16 -67
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/types.d.ts +2 -2
- package/lib/esm/types.js.map +1 -1
- package/package.json +2 -2
- package/src/api.ts +19 -19
- package/src/bot-context-manager.ts +153 -0
- package/src/constants.ts +2 -1
- package/src/content-fields/contact-reasons-conditional-matcher.ts +24 -0
- package/src/content-fields/flow-contact-reasons-conditional.tsx +60 -0
- package/src/content-fields/flow-handoff.tsx +49 -7
- package/src/content-fields/hubtype-fields/contact-reasons-conditional.ts +18 -0
- package/src/content-fields/hubtype-fields/handoff.ts +11 -1
- package/src/content-fields/hubtype-fields/node-types.ts +1 -0
- package/src/content-fields/hubtype-fields/nodes.ts +2 -0
- package/src/content-fields/index.ts +3 -0
- package/src/flow-factory.ts +7 -0
- package/src/index.ts +26 -117
- package/src/types.ts +1 -2
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FlowWhatsappTemplate = exports.FlowWhatsappRequestContactInfoNode = exports.FlowWhatsappCtaUrlButtonNode = exports.FlowWhatsappButtonListSection = exports.FlowWhatsappButtonListRow = exports.FlowWhatsappButtonList = exports.FlowVideo = exports.FlowText = exports.FlowRating = exports.FlowQueueStatusConditional = exports.FlowImage = exports.FlowHandoff = exports.FlowGoToFlow = exports.FlowDoNothing = exports.FlowCustomConditionalV2 = exports.FlowCustomConditional = exports.FlowCountryConditional = exports.FlowChannelConditional = exports.FlowCarousel = exports.FlowCaptureUserInput = exports.FlowBotAction = exports.FlowAiAgentRouter = exports.FlowAiAgent = exports.FlowElement = exports.FlowButton = exports.ContentFieldsBase = void 0;
|
|
3
|
+
exports.FlowWhatsappTemplate = exports.FlowWhatsappRequestContactInfoNode = exports.FlowWhatsappCtaUrlButtonNode = exports.FlowWhatsappButtonListSection = exports.FlowWhatsappButtonListRow = exports.FlowWhatsappButtonList = exports.FlowVideo = exports.FlowText = exports.FlowRating = exports.FlowQueueStatusConditional = exports.FlowImage = exports.FlowHandoff = exports.FlowGoToFlow = exports.FlowDoNothing = exports.FlowCustomConditionalV2 = exports.FlowCustomConditional = exports.FlowCountryConditional = exports.FlowContactReasonsConditional = exports.FlowChannelConditional = exports.FlowCarousel = exports.FlowCaptureUserInput = exports.FlowBotAction = exports.FlowAiAgentRouter = exports.FlowAiAgent = exports.FlowElement = exports.FlowButton = exports.ContentFieldsBase = void 0;
|
|
4
4
|
const flow_custom_condition_v2_1 = require("./custom-conditional/flow-custom-condition-v2");
|
|
5
5
|
Object.defineProperty(exports, "FlowCustomConditionalV2", { enumerable: true, get: function () { return flow_custom_condition_v2_1.FlowCustomConditionalV2; } });
|
|
6
6
|
const flow_ai_agent_1 = require("./flow-ai-agent");
|
|
@@ -15,6 +15,8 @@ const flow_carousel_1 = require("./flow-carousel");
|
|
|
15
15
|
Object.defineProperty(exports, "FlowCarousel", { enumerable: true, get: function () { return flow_carousel_1.FlowCarousel; } });
|
|
16
16
|
const flow_channel_conditional_1 = require("./flow-channel-conditional");
|
|
17
17
|
Object.defineProperty(exports, "FlowChannelConditional", { enumerable: true, get: function () { return flow_channel_conditional_1.FlowChannelConditional; } });
|
|
18
|
+
const flow_contact_reasons_conditional_1 = require("./flow-contact-reasons-conditional");
|
|
19
|
+
Object.defineProperty(exports, "FlowContactReasonsConditional", { enumerable: true, get: function () { return flow_contact_reasons_conditional_1.FlowContactReasonsConditional; } });
|
|
18
20
|
const flow_country_conditional_1 = require("./flow-country-conditional");
|
|
19
21
|
Object.defineProperty(exports, "FlowCountryConditional", { enumerable: true, get: function () { return flow_country_conditional_1.FlowCountryConditional; } });
|
|
20
22
|
const flow_custom_conditional_1 = require("./flow-custom-conditional");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/content-fields/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DAA6B,OA2BA;AAxB/B,6DAAyD;AAAhD,wHAAA,iBAAiB,OAAA;AAC1B,6CAA0C;AAAjC,yGAAA,UAAU,OAAA;AACnB,+CAA4C;AAAnC,2GAAA,WAAW,OAAA"}
|
package/lib/cjs/flow-factory.js
CHANGED
|
@@ -48,6 +48,8 @@ class FlowFactory {
|
|
|
48
48
|
return content_fields_1.FlowCustomConditionalV2.fromHubtypeCMS(hubtypeContent, this.botContext);
|
|
49
49
|
case hubtype_fields_1.HtNodeWithContentType.DO_NOTHING:
|
|
50
50
|
return content_fields_1.FlowDoNothing.fromHubtypeCMS(hubtypeContent);
|
|
51
|
+
case hubtype_fields_1.HtNodeWithContentType.CONTACT_REASONS_CONDITION:
|
|
52
|
+
return content_fields_1.FlowContactReasonsConditional.fromHubtypeCMS(hubtypeContent, this.botContext);
|
|
51
53
|
default:
|
|
52
54
|
return undefined;
|
|
53
55
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-factory.js","sourceRoot":"","sources":["../../src/flow-factory.ts"],"names":[],"mappings":";;;AAGA,
|
|
1
|
+
{"version":3,"file":"flow-factory.js","sourceRoot":"","sources":["../../src/flow-factory.ts"],"names":[],"mappings":";;;AAGA,qDAuByB;AACzB,sFAA+E;AAC/E,oEAIwC;AAExC,MAAa,WAAW;IAKtB,YAAY,UAAsB,EAAE,MAAsB,EAAE,MAAc;QACxE,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACtB,CAAC;IAED,KAAK,CAAC,cAAc,CAClB,cAA+B;QAE/B,QAAQ,cAAc,CAAC,IAAI,EAAE,CAAC;YAC5B,KAAK,sCAAqB,CAAC,IAAI;gBAC7B,OAAO,yBAAQ,CAAC,cAAc,CAC5B,cAAc,EACd,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,UA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AAc,EACd,IAAI,CAAC,UAAU,CAChB,CAAA;YACH,KAAK,oBAAoB;gBACvB,OAAO,2CAA0B,CAAC,cAAc,CAC9C,cAAc,EACd,IAAI,CAAC,MAAM,CACZ,CAAA;YACH,KAAK,oBAAoB;gBACvB,OAAO,sCAAqB,CAAC,cAAc,CACzC,cAAc,EACd,IAAI,CAAC,UAAU,CAChB,CAAA;YACH;gBACE,OAAO,SAAS,CAAA;QACpB,CAAC;IACH,CAAC;CACF;AAlID,kCAkIC"}
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { BotContext, Plugin, ResolvedPlugins, Session } from '@botonic/core';
|
|
2
2
|
import { FlowBuilderApi } from './api';
|
|
3
3
|
import type { FlowContent } from './content-fields';
|
|
4
4
|
import { type HtNodeWithContent } from './content-fields/hubtype-fields';
|
|
@@ -8,7 +8,7 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
8
8
|
cmsApi: FlowBuilderApi;
|
|
9
9
|
private flow?;
|
|
10
10
|
private functions;
|
|
11
|
-
private
|
|
11
|
+
private botContext;
|
|
12
12
|
getAccessToken: (session: Session) => string;
|
|
13
13
|
trackEvent?: TrackEventFunction;
|
|
14
14
|
getAiAgentResponse?: AiAgentFunction;
|
|
@@ -20,13 +20,9 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
20
20
|
customRatingMessageEnabled: boolean;
|
|
21
21
|
disableAIAgentInFirstInteraction: boolean;
|
|
22
22
|
constructor(options: BotonicPluginFlowBuilderOptions<ResolvedPlugins, any>);
|
|
23
|
-
resolveFlowUrl(
|
|
24
|
-
pre(
|
|
25
|
-
|
|
26
|
-
private convertWhatsappAiAgentEmptyPayloads;
|
|
27
|
-
private updateRequestBeforeRoutes;
|
|
28
|
-
private removeSourceSuffix;
|
|
29
|
-
post(request: PluginPreRequest): void;
|
|
23
|
+
resolveFlowUrl(botContext: BotContext): string;
|
|
24
|
+
pre(botContext: BotContext): Promise<void>;
|
|
25
|
+
post(botContext: BotContext): void;
|
|
30
26
|
getContentsByContentID(contentID: string, prevContents?: FlowContent[]): Promise<FlowContent[]>;
|
|
31
27
|
getUUIDByContentID(contentID: string): string;
|
|
32
28
|
private getContentsById;
|
package/lib/cjs/index.js
CHANGED
|
@@ -2,17 +2,15 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FlowBuilderJSONVersion = exports.trackFlowContent = exports.getCommonFlowContentEventArgsForContentId = exports.EMPTY_PAYLOAD = exports.AGENT_RATING_PAYLOAD = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
-
const core_1 = require("@botonic/core");
|
|
6
5
|
const uuid_1 = require("uuid");
|
|
7
6
|
const api_1 = require("./api");
|
|
7
|
+
const bot_context_manager_1 = require("./bot-context-manager");
|
|
8
8
|
const constants_1 = require("./constants");
|
|
9
9
|
const hubtype_fields_1 = require("./content-fields/hubtype-fields");
|
|
10
10
|
const flow_factory_1 = require("./flow-factory");
|
|
11
11
|
const functions_1 = require("./functions");
|
|
12
12
|
const types_1 = require("./types");
|
|
13
|
-
const user_input_1 = require("./user-input");
|
|
14
13
|
const authentication_1 = require("./utils/authentication");
|
|
15
|
-
const input_1 = require("./utils/input");
|
|
16
14
|
// TODO: Create a proper service to wrap all calls and allow api versioning
|
|
17
15
|
class BotonicPluginFlowBuilder {
|
|
18
16
|
constructor(options) {
|
|
@@ -39,76 +37,27 @@ class BotonicPluginFlowBuilder {
|
|
|
39
37
|
this.disableAIAgentInFirstInteraction =
|
|
40
38
|
options.disableAIAgentInFirstInteraction || false;
|
|
41
39
|
}
|
|
42
|
-
resolveFlowUrl(
|
|
43
|
-
if (
|
|
40
|
+
resolveFlowUrl(botContext) {
|
|
41
|
+
if (botContext.session.is_test_integration) {
|
|
44
42
|
return `${this.apiUrl}/v1/bot_flows/{bot_id}/versions/${types_1.FlowBuilderJSONVersion.DRAFT}/`;
|
|
45
43
|
}
|
|
46
44
|
return `${this.apiUrl}/v1/bot_flows/{bot_id}/versions/${this.jsonVersion}/`;
|
|
47
45
|
}
|
|
48
|
-
async pre(
|
|
49
|
-
|
|
50
|
-
this.convertWhatsappAiAgentEmptyPayloads(request);
|
|
51
|
-
this.currentRequest = request;
|
|
46
|
+
async pre(botContext) {
|
|
47
|
+
this.botContext = botContext;
|
|
52
48
|
this.cmsApi = await api_1.FlowBuilderApi.create({
|
|
53
|
-
flowUrl: this.resolveFlowUrl(
|
|
49
|
+
flowUrl: this.resolveFlowUrl(botContext),
|
|
54
50
|
url: this.apiUrl,
|
|
55
51
|
flow: this.flow,
|
|
56
|
-
accessToken: this.getAccessToken(
|
|
57
|
-
|
|
52
|
+
accessToken: this.getAccessToken(botContext.session),
|
|
53
|
+
botContext: this.botContext,
|
|
58
54
|
});
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
this.resolveWhatsappContactRequestPayload(request);
|
|
63
|
-
const checkUserTextInput = (0, input_1.inputHasTextOrTranscript)(request.input) && !request.input.payload;
|
|
64
|
-
if (checkUserTextInput) {
|
|
65
|
-
const resolvedLocale = this.cmsApi.getResolvedLocale();
|
|
66
|
-
const nextPayload = await (0, user_input_1.getNextPayloadByUserInput)(this.cmsApi, resolvedLocale, request, this.smartIntentsConfig);
|
|
67
|
-
request.input.payload = nextPayload;
|
|
68
|
-
}
|
|
69
|
-
await this.updateRequestBeforeRoutes(request);
|
|
70
|
-
}
|
|
71
|
-
resolveWhatsappContactRequestPayload(request) {
|
|
72
|
-
if (request.input.type !== core_1.INPUT.CONTACT ||
|
|
73
|
-
request.input.origin !== core_1.WhatsappInputOrigin.ContactRequest) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
const whatsappRequestContactInfoNode = this.cmsApi.getWhatsappRequestContactInfoNode();
|
|
77
|
-
if (whatsappRequestContactInfoNode) {
|
|
78
|
-
request.input.payload = this.cmsApi.getPayload(whatsappRequestContactInfoNode.content.button.target);
|
|
79
|
-
}
|
|
80
|
-
this.cmsApi.removeWhatsappRequestContactId();
|
|
81
|
-
}
|
|
82
|
-
convertWhatsappAiAgentEmptyPayloads(request) {
|
|
83
|
-
if (request.session.user.provider === core_1.PROVIDER.WHATSAPP) {
|
|
84
|
-
const shouldUseReferral = request.input.referral &&
|
|
85
|
-
request.input.payload?.startsWith(constants_1.EMPTY_PAYLOAD);
|
|
86
|
-
if (shouldUseReferral) {
|
|
87
|
-
request.input.type = core_1.INPUT.TEXT;
|
|
88
|
-
request.input.data = request.input.referral;
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
async updateRequestBeforeRoutes(request) {
|
|
93
|
-
this.cmsApi.removeCaptureUserInputId();
|
|
94
|
-
if (request.input.payload) {
|
|
95
|
-
request.input.payload = this.removeSourceSuffix(request.input.payload);
|
|
96
|
-
if (this.cmsApi.isBotAction(request.input.payload)) {
|
|
97
|
-
const cmsBotAction = this.cmsApi.getNodeById(request.input.payload);
|
|
98
|
-
request.input.payload =
|
|
99
|
-
this.cmsApi.createPayloadWithParams(cmsBotAction);
|
|
100
|
-
// Re-execute convertWhatsappAiAgentEmptyPayloads function to handle
|
|
101
|
-
// the case that a BotAction has a payload equals to EMPTY_PAYLOAD
|
|
102
|
-
this.convertWhatsappAiAgentEmptyPayloads(request);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
removeSourceSuffix(payload) {
|
|
107
|
-
return payload.split(constants_1.SOURCE_INFO_SEPARATOR)[0];
|
|
55
|
+
const botContextManager = new bot_context_manager_1.BotContextManager(this.cmsApi, this.smartIntentsConfig);
|
|
56
|
+
await botContextManager.updateBeforeRoutes(botContext);
|
|
108
57
|
}
|
|
109
|
-
post(
|
|
110
|
-
|
|
111
|
-
delete
|
|
58
|
+
post(botContext) {
|
|
59
|
+
botContext.input.nluResolution = undefined;
|
|
60
|
+
delete botContext.session.user.system_locale_updated;
|
|
112
61
|
}
|
|
113
62
|
async getContentsByContentID(contentID, prevContents) {
|
|
114
63
|
const node = this.cmsApi.getNodeByContentID(contentID);
|
|
@@ -124,7 +73,7 @@ class BotonicPluginFlowBuilder {
|
|
|
124
73
|
}
|
|
125
74
|
async getStartContents() {
|
|
126
75
|
const startNode = this.cmsApi.getStartNode();
|
|
127
|
-
this.
|
|
76
|
+
this.botContext.session.flow_thread_id = (0, uuid_1.v7)();
|
|
128
77
|
return await this.getContentsByNode(startNode);
|
|
129
78
|
}
|
|
130
79
|
async getContentsByNode(node, prevContents) {
|
|
@@ -132,11 +81,11 @@ class BotonicPluginFlowBuilder {
|
|
|
132
81
|
const resolvedLocale = this.cmsApi.getResolvedLocale();
|
|
133
82
|
if (node.type === hubtype_fields_1.HtNodeWithContentType.FUNCTION &&
|
|
134
83
|
!functions_1.DEFAULT_FUNCTION_NAMES.includes(node.content.action)) {
|
|
135
|
-
const customFunctionResolver = new functions_1.CustomFunction(this.functions, this.
|
|
84
|
+
const customFunctionResolver = new functions_1.CustomFunction(this.functions, this.botContext, resolvedLocale);
|
|
136
85
|
const targetId = await customFunctionResolver.call(node);
|
|
137
86
|
return this.getContentsById(targetId, contents);
|
|
138
87
|
}
|
|
139
|
-
const flowFactory = new flow_factory_1.FlowFactory(this.
|
|
88
|
+
const flowFactory = new flow_factory_1.FlowFactory(this.botContext, this.cmsApi, resolvedLocale);
|
|
140
89
|
const content = await flowFactory.getFlowContent(node);
|
|
141
90
|
if (content) {
|
|
142
91
|
contents.push(content);
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;AAMA,+BAAmC;AAEnC,+BAAsC;AACtC,+DAAyD;AACzD,2CAAkE;AAElE,oEAIwC;AACxC,iDAA4C;AAC5C,2CAAoE;AACpE,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C,CAAA;QAC1E,MAAM,eAAe,GAAG,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CACpD,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CACtB,CAAA;QACD,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CACnD,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,KAAK,CACvB,CAAA;QAED,OAAO;YACL,GAAG,YAAY;YACf,eAAe;YACf,cAAc;SACf,CAAA;IACH,CAAC;IAED,cAAc,CAAC,WAA8B;QAC3C,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;IAChC,CAAC;CACF;AAhLD,2CAgLC;AAED,mDAAwB;AACxB,yCAAiE;AAAxD,iHAAA,oBAAoB,OAAA;AAAE,0GAAA,aAAa,OAAA;AAC5C,2DAAgC;AAEhC,uCAGmB;AAFjB,qIAAA,yCAAyC,OAAA;AACzC,4GAAA,gBAAgB,OAAA;AAElB,iCAMgB;AAHd,+GAAA,sBAAsB,OAAA;AAIxB,oDAAyB"}
|
package/lib/cjs/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AiAgentArgs, BotContext, GuardrailRule, InferenceResponse,
|
|
1
|
+
import type { AiAgentArgs, BotContext, GuardrailRule, InferenceResponse, ResolvedPlugins } from '@botonic/core';
|
|
2
2
|
import type { FlowContent } from './content-fields';
|
|
3
3
|
import type { HtFlowBuilderData, HtRatingButton } from './content-fields/hubtype-fields';
|
|
4
4
|
import type { FlowBuilderContentMessage } from './structured-output/flow-builder-content';
|
|
@@ -31,7 +31,7 @@ export interface FlowBuilderApiOptions {
|
|
|
31
31
|
flowUrl: string;
|
|
32
32
|
flow?: HtFlowBuilderData;
|
|
33
33
|
accessToken: string;
|
|
34
|
-
|
|
34
|
+
botContext: BotContext;
|
|
35
35
|
}
|
|
36
36
|
export declare enum ProcessEnvNodeEnvs {
|
|
37
37
|
PRODUCTION = "production",
|
package/lib/cjs/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":";;;AAuEA,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,+CAAyB,CAAA;IACzB,iDAA2B,CAAA;AAC7B,CAAC,EAHW,kBAAkB,kCAAlB,kBAAkB,QAG7B;AAED,IAAY,sBAGX;AAHD,WAAY,sBAAsB;IAChC,yCAAe,CAAA;IACf,2CAAiB,CAAA;AACnB,CAAC,EAHW,sBAAsB,sCAAtB,sBAAsB,QAGjC"}
|
package/lib/esm/api.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { BotContext } from '@botonic/core';
|
|
2
2
|
import { type HtBotActionNode, type HtCaptureUserInputNode, type HtFlowBuilderData, type HtFlowWebview, type HtKeywordNode, type HtNodeComponent, type HtNodeLink, type HtNodeWithContent, type HtRatingButton, type HtRatingNode, type HtSmartIntentNode, type HtWhatsappRequestContactInfoNode } from './content-fields/hubtype-fields';
|
|
3
3
|
import { type FlowBuilderApiOptions } from './types';
|
|
4
4
|
export declare class FlowBuilderApi {
|
|
5
5
|
url: string;
|
|
6
6
|
flowUrl: string;
|
|
7
7
|
flow: HtFlowBuilderData;
|
|
8
|
-
|
|
8
|
+
botContext: BotContext;
|
|
9
9
|
private constructor();
|
|
10
10
|
static create(options: FlowBuilderApiOptions): Promise<FlowBuilderApi>;
|
|
11
11
|
private getFlow;
|
package/lib/esm/api.js
CHANGED
|
@@ -12,12 +12,12 @@ class FlowBuilderApi {
|
|
|
12
12
|
static async create(options) {
|
|
13
13
|
const newApi = new FlowBuilderApi();
|
|
14
14
|
newApi.url = options.url;
|
|
15
|
-
newApi.
|
|
15
|
+
newApi.botContext = options.botContext;
|
|
16
16
|
// TODO: Refactor later to combine logic from `FlowBuilderApi.create`, `resolveFlowUrl` and `getAccessToken` to be in one place
|
|
17
17
|
if (process.env.NODE_ENV === types_1.ProcessEnvNodeEnvs.DEVELOPMENT) {
|
|
18
18
|
await newApi.updateSessionWithUserInfo(options.accessToken);
|
|
19
19
|
}
|
|
20
|
-
const updatedRequest = newApi.
|
|
20
|
+
const updatedRequest = newApi.botContext;
|
|
21
21
|
newApi.flowUrl = options.flowUrl.replace('{bot_id}', updatedRequest.session.bot.id);
|
|
22
22
|
newApi.flow = options.flow ?? (await newApi.getFlow(options.accessToken));
|
|
23
23
|
return newApi;
|
|
@@ -33,8 +33,8 @@ class FlowBuilderApi {
|
|
|
33
33
|
const response = await axios_1.default.get(url, {
|
|
34
34
|
headers: { Authorization: `Bearer ${token}` },
|
|
35
35
|
});
|
|
36
|
-
this.
|
|
37
|
-
this.
|
|
36
|
+
this.botContext.session.organization_id = response.data.organization_id;
|
|
37
|
+
this.botContext.session.bot.id = response.data.bot_id;
|
|
38
38
|
}
|
|
39
39
|
getNodeByFlowId(id) {
|
|
40
40
|
const subFlow = this.flow.flows.find(subFlow => subFlow.id === id);
|
|
@@ -172,20 +172,20 @@ class FlowBuilderApi {
|
|
|
172
172
|
return !!this.getCaptureUserInputId();
|
|
173
173
|
}
|
|
174
174
|
getCaptureUserInputId() {
|
|
175
|
-
return this.
|
|
175
|
+
return this.botContext.session.capture_user_input?.node_id;
|
|
176
176
|
}
|
|
177
177
|
setCaptureUserInputId(id) {
|
|
178
|
-
if (this.
|
|
179
|
-
this.
|
|
178
|
+
if (this.botContext.session.capture_user_input) {
|
|
179
|
+
this.botContext.session.capture_user_input.node_id = id;
|
|
180
180
|
}
|
|
181
|
-
this.
|
|
181
|
+
this.botContext.session.capture_user_input = { node_id: id };
|
|
182
182
|
}
|
|
183
183
|
removeCaptureUserInputId() {
|
|
184
|
-
this.
|
|
184
|
+
this.botContext.session.capture_user_input = undefined;
|
|
185
185
|
}
|
|
186
186
|
setUserExtraDataVariable(key, value) {
|
|
187
|
-
if (this.
|
|
188
|
-
this.
|
|
187
|
+
if (this.botContext.session.user.extra_data) {
|
|
188
|
+
this.botContext.session.user.extra_data[key] = value;
|
|
189
189
|
}
|
|
190
190
|
}
|
|
191
191
|
getCaptureUserInputNode() {
|
|
@@ -196,16 +196,16 @@ class FlowBuilderApi {
|
|
|
196
196
|
return this.getNodeById(captureUserInputId);
|
|
197
197
|
}
|
|
198
198
|
getSessionWhatsappRequestContactId() {
|
|
199
|
-
return this.
|
|
199
|
+
return this.botContext.session.whatsapp_request_contact?.id;
|
|
200
200
|
}
|
|
201
201
|
setWhatsappRequestContactId(id) {
|
|
202
|
-
if (this.
|
|
203
|
-
this.
|
|
202
|
+
if (this.botContext.session.whatsapp_request_contact) {
|
|
203
|
+
this.botContext.session.whatsapp_request_contact.id = id;
|
|
204
204
|
}
|
|
205
|
-
this.
|
|
205
|
+
this.botContext.session.whatsapp_request_contact = { id };
|
|
206
206
|
}
|
|
207
207
|
removeWhatsappRequestContactId() {
|
|
208
|
-
this.
|
|
208
|
+
this.botContext.session.whatsapp_request_contact = undefined;
|
|
209
209
|
}
|
|
210
210
|
getWhatsappRequestContactInfoNode() {
|
|
211
211
|
const whatsappRequestContactId = this.getSessionWhatsappRequestContactId();
|
|
@@ -217,7 +217,7 @@ class FlowBuilderApi {
|
|
|
217
217
|
getResolvedLocale() {
|
|
218
218
|
const flowLocales = this.flow.locales;
|
|
219
219
|
const defaultLocaleCode = this.flow.default_locale_code;
|
|
220
|
-
return new flow_locale_1.FlowLocale(this.
|
|
220
|
+
return new flow_locale_1.FlowLocale(this.botContext, flowLocales, defaultLocaleCode).resolve();
|
|
221
221
|
}
|
|
222
222
|
isPushFlowPayload(payload) {
|
|
223
223
|
return payload?.startsWith(constants_1.PUSH_FLOW_PAYLOAD) ?? false;
|
package/lib/esm/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/api.ts"],"names":[],"mappings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B,CAClB,CAAC,OAAO,EAAE,CAAA;IACb,CAAC;IAED,iBAAiB,CAAC,OAAgB;QAChC,OAAO,OAAO,EAAE,UAAU,CAAC,6BAAiB,CAAC,IAAI,KAAK,CAAA;IACxD,CAAC;CACF;AA9SD,wCA8SC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type BotContext } from '@botonic/core';
|
|
2
|
+
import type { FlowBuilderApi } from './api';
|
|
3
|
+
import type { SmartIntentsInferenceConfig } from './user-input/smart-intent';
|
|
4
|
+
export declare class BotContextManager {
|
|
5
|
+
private readonly cmsApi;
|
|
6
|
+
private readonly smartIntentsConfig;
|
|
7
|
+
constructor(cmsApi: FlowBuilderApi, smartIntentsConfig: SmartIntentsInferenceConfig);
|
|
8
|
+
updateBeforeRoutes(botContext: BotContext): Promise<void>;
|
|
9
|
+
private updateFirstInteractionOnPushFlowPayload;
|
|
10
|
+
private resolvePayloadFromUserTextInput;
|
|
11
|
+
private resolveWhatsappContactRequestPayload;
|
|
12
|
+
private resolveOnCloseHandoffPayload;
|
|
13
|
+
private convertWhatsappAiAgentEmptyPayloads;
|
|
14
|
+
private removePayloadSourceSuffix;
|
|
15
|
+
private resolveBotActionPayload;
|
|
16
|
+
private removeSourceSuffix;
|
|
17
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BotContextManager = void 0;
|
|
4
|
+
const core_1 = require("@botonic/core");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const content_fields_1 = require("./content-fields");
|
|
7
|
+
const hubtype_fields_1 = require("./content-fields/hubtype-fields");
|
|
8
|
+
const user_input_1 = require("./user-input");
|
|
9
|
+
const input_1 = require("./utils/input");
|
|
10
|
+
class BotContextManager {
|
|
11
|
+
constructor(cmsApi, smartIntentsConfig) {
|
|
12
|
+
this.cmsApi = cmsApi;
|
|
13
|
+
this.smartIntentsConfig = smartIntentsConfig;
|
|
14
|
+
}
|
|
15
|
+
async updateBeforeRoutes(botContext) {
|
|
16
|
+
// When AI Agent is executed in Whatsapp, button payloads come as referral and must be converted to text being processed by the agent.
|
|
17
|
+
this.convertWhatsappAiAgentEmptyPayloads(botContext);
|
|
18
|
+
// If the payload is a push-flow payload, set first interaction to false
|
|
19
|
+
this.updateFirstInteractionOnPushFlowPayload(botContext);
|
|
20
|
+
this.resolveWhatsappContactRequestPayload(botContext);
|
|
21
|
+
this.resolveOnCloseHandoffPayload(botContext);
|
|
22
|
+
await this.resolvePayloadFromUserTextInput(botContext);
|
|
23
|
+
this.cmsApi.removeCaptureUserInputId();
|
|
24
|
+
this.removePayloadSourceSuffix(botContext);
|
|
25
|
+
this.resolveBotActionPayload(botContext);
|
|
26
|
+
}
|
|
27
|
+
async updateFirstInteractionOnPushFlowPayload(botContext) {
|
|
28
|
+
if (this.cmsApi.isPushFlowPayload(botContext.input.payload)) {
|
|
29
|
+
botContext.session.is_first_interaction = false;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
async resolvePayloadFromUserTextInput(botContext) {
|
|
33
|
+
const checkUserTextInput = (0, input_1.inputHasTextOrTranscript)(botContext.input) && !botContext.input.payload;
|
|
34
|
+
if (!checkUserTextInput) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const resolvedLocale = this.cmsApi.getResolvedLocale();
|
|
38
|
+
const nextPayload = await (0, user_input_1.getNextPayloadByUserInput)(this.cmsApi, resolvedLocale, botContext, this.smartIntentsConfig);
|
|
39
|
+
botContext.input.payload = nextPayload;
|
|
40
|
+
}
|
|
41
|
+
resolveWhatsappContactRequestPayload(botContext) {
|
|
42
|
+
if (botContext.input.type !== core_1.INPUT.CONTACT ||
|
|
43
|
+
botContext.input.origin !== core_1.WhatsappInputOrigin.ContactRequest) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
const whatsappRequestContactInfoNode = this.cmsApi.getWhatsappRequestContactInfoNode();
|
|
47
|
+
if (whatsappRequestContactInfoNode) {
|
|
48
|
+
botContext.input.payload = this.cmsApi.getPayload(whatsappRequestContactInfoNode.content.button.target);
|
|
49
|
+
}
|
|
50
|
+
this.cmsApi.removeWhatsappRequestContactId();
|
|
51
|
+
}
|
|
52
|
+
resolveOnCloseHandoffPayload(botContext) {
|
|
53
|
+
if (botContext.input.payload?.startsWith(constants_1.ON_CLOSE_HANDOFF_PAYLOAD)) {
|
|
54
|
+
const handoffNodeId = botContext.input.payload.split(constants_1.SEPARATOR)[1];
|
|
55
|
+
const handoffNode = this.cmsApi.getNodeById(handoffNodeId);
|
|
56
|
+
if (handoffNode && handoffNode.type === hubtype_fields_1.HtNodeWithContentType.HANDOFF) {
|
|
57
|
+
const flowHandoff = content_fields_1.FlowHandoff.fromHubtypeCMS(handoffNode, this.cmsApi.getResolvedLocale(), this.cmsApi);
|
|
58
|
+
botContext.input.payload = flowHandoff.resolveOnClosePayload(botContext);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
convertWhatsappAiAgentEmptyPayloads(botContext) {
|
|
63
|
+
if (botContext.session.user.provider === core_1.PROVIDER.WHATSAPP) {
|
|
64
|
+
const shouldUseReferral = botContext.input.referral &&
|
|
65
|
+
botContext.input.payload?.startsWith(constants_1.EMPTY_PAYLOAD);
|
|
66
|
+
if (shouldUseReferral) {
|
|
67
|
+
botContext.input.type = core_1.INPUT.TEXT;
|
|
68
|
+
botContext.input.data = botContext.input.referral;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
removePayloadSourceSuffix(botContext) {
|
|
73
|
+
if (botContext.input.payload) {
|
|
74
|
+
botContext.input.payload = this.removeSourceSuffix(botContext.input.payload);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
resolveBotActionPayload(botContext) {
|
|
78
|
+
if (botContext.input.payload &&
|
|
79
|
+
this.cmsApi.isBotAction(botContext.input.payload)) {
|
|
80
|
+
const cmsBotAction = this.cmsApi.getNodeById(botContext.input.payload);
|
|
81
|
+
botContext.input.payload =
|
|
82
|
+
this.cmsApi.createPayloadWithParams(cmsBotAction);
|
|
83
|
+
// Re-execute convertWhatsappAiAgentEmptyPayloads function to handle
|
|
84
|
+
// the case that a BotAction has a payload equals to EMPTY_PAYLOAD
|
|
85
|
+
this.convertWhatsappAiAgentEmptyPayloads(botContext);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
removeSourceSuffix(payload) {
|
|
89
|
+
return payload.split(constants_1.SOURCE_INFO_SEPARATOR)[0];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.BotContextManager = BotContextManager;
|
|
93
|
+
//# sourceMappingURL=bot-context-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bot-context-manager.js","sourceRoot":"","sources":["../../src/bot-context-manager.ts"],"names":[],"mappings":";;;AAAA,wCAKsB;AAGtB,2CAKoB;AACpB,qDAA8C;AAC9C,oEAIwC;AACxC,6CAAwD;AAExD,yCAAwD;AAExD,MAAa,iBAAiB;IAC5B,YACmB,MAAsB,EACtB,kBAA+C;QAD/C,WAAM,GAAN,MAAM,CAAgB;QACtB,uBAAkB,GAAlB,kBAAkB,CAA6B;IAC/D,CAAC;IAEJ,KAAK,CAAC,kBAAkB,CAAC,UAAsB;QAC7C,sIAAsI;QACtI,IAAI,CAAC,mCAAmC,CAAC,UAAU,CAAC,CAAA;QAEpD,wEAAwE;QACxE,IAAI,CAAC,uCAAuC,CAAC,UAAU,CAAC,CAAA;QAExD,IAAI,CAAC,oCAAoC,CAAC,UAAU,CAAC,CAAA;QACrD,IAAI,CAAC,4BAA4B,CAAC,UAAU,CAAC,CAAA;QAE7C,MAAM,IAAI,CAAC,+BAA+B,CAAC,UAAU,CAAC,CAAA;QAEtD,IAAI,CAAC,MAAM,CAAC,wBAAwB,EAAE,CAAA;QACtC,IAAI,CAAC,yBAAyB,CAAC,UAAU,CAAC,CAAA;QAC1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C7B,UAAU,CAAC,KAAK,CAAC,OAAO,GAAG,IAAI,CAAC,kBAAkB,CAChD,UAAU,CAAC,KAAK,CAAC,OAAO,CACzB,CAAA;QACH,CAAC;IACH,CAAC;IAEO,uBAAuB,CAAC,UAAsB;QACpD,IACE,UAAU,CAAC,KAAK,CAAC,OAAO;YACxB,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,EACjD,CAAC;YACD,MAAM,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAC1C,UAAU,CAAC,KAAK,CAAC,OAAO,CACzB,CAAA;YAED,UAAU,CAAC,KAAK,CAAC,OAAO;gBACtB,IAAI,CAAC,MAAM,CAAC,uBAAuB,CAAC,YAAY,CAAC,CAAA;YAEnD,oEAAoE;YACpE,kEAAkE;YAClE,IAAI,CAAC,mCAAmC,CAAC,UAAU,CAAC,CAAA;QACtD,CAAC;IACH,CAAC;IAEO,kBAAkB,CAAC,OAAe;QACxC,OAAO,OAAO,CAAC,KAAK,CAAC,iCAAqB,CAAC,CAAC,CAAC,CAAC,CAAA;IAChD,CAAC;CACF;AAhID,8CAgIC"}
|
package/lib/esm/constants.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
export declare const FLOW_BUILDER_API_URL_PROD: string;
|
|
2
2
|
export declare const SEPARATOR = "|";
|
|
3
3
|
export declare const SOURCE_INFO_SEPARATOR = "|source_";
|
|
4
|
-
export declare const EMPTY_PAYLOAD = "fb-empty-payload";
|
|
5
4
|
export declare const VARIABLE_PATTERN_GLOBAL: RegExp;
|
|
6
5
|
export declare const ACCESS_TOKEN_VARIABLE_KEY = "_access_token";
|
|
7
6
|
export declare const REG_EXP_PATTERN: RegExp;
|
|
8
7
|
export declare const UUID_REGEXP: RegExp;
|
|
8
|
+
export declare const EMPTY_PAYLOAD = "fb-empty-payload";
|
|
9
|
+
export declare const ON_CLOSE_HANDOFF_PAYLOAD = "fb-on-close-handoff";
|
|
9
10
|
export declare const AGENT_RATING_PAYLOAD = "agent-rating";
|
|
10
11
|
export declare const PUSH_FLOW_PAYLOAD = "push-flow";
|
|
11
12
|
export declare const MAIN_FLOW_NAME = "Main";
|
package/lib/esm/constants.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.FALLBACK_FLOW_NAME = exports.AI_AGENTS_FLOW_NAME = exports.MAIN_FLOW_NAME = exports.PUSH_FLOW_PAYLOAD = exports.AGENT_RATING_PAYLOAD = exports.
|
|
3
|
+
exports.FALLBACK_FLOW_NAME = exports.AI_AGENTS_FLOW_NAME = exports.MAIN_FLOW_NAME = exports.PUSH_FLOW_PAYLOAD = exports.AGENT_RATING_PAYLOAD = exports.ON_CLOSE_HANDOFF_PAYLOAD = exports.EMPTY_PAYLOAD = exports.UUID_REGEXP = exports.REG_EXP_PATTERN = exports.ACCESS_TOKEN_VARIABLE_KEY = exports.VARIABLE_PATTERN_GLOBAL = exports.SOURCE_INFO_SEPARATOR = exports.SEPARATOR = exports.FLOW_BUILDER_API_URL_PROD = void 0;
|
|
4
4
|
exports.FLOW_BUILDER_API_URL_PROD = process.env.HUBTYPE_API_URL || 'https://api.hubtype.com';
|
|
5
5
|
exports.SEPARATOR = '|';
|
|
6
6
|
exports.SOURCE_INFO_SEPARATOR = `${exports.SEPARATOR}source_`;
|
|
7
|
-
exports.EMPTY_PAYLOAD = 'fb-empty-payload';
|
|
8
7
|
exports.VARIABLE_PATTERN_GLOBAL = /{([^{}]+)}/g;
|
|
9
8
|
exports.ACCESS_TOKEN_VARIABLE_KEY = '_access_token';
|
|
10
9
|
exports.REG_EXP_PATTERN = /^\/(.*)\/([gimyus]*)$/;
|
|
11
10
|
exports.UUID_REGEXP = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
12
11
|
/* ********** PAYLOADS ********** */
|
|
12
|
+
exports.EMPTY_PAYLOAD = 'fb-empty-payload';
|
|
13
|
+
exports.ON_CLOSE_HANDOFF_PAYLOAD = 'fb-on-close-handoff';
|
|
13
14
|
exports.AGENT_RATING_PAYLOAD = 'agent-rating';
|
|
14
15
|
exports.PUSH_FLOW_PAYLOAD = 'push-flow';
|
|
15
16
|
/* ********** FLOW NAMES ********** */
|
package/lib/esm/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,yBAAyB,GACpC,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,yBAAyB,CAAA;AAC7C,QAAA,SAAS,GAAG,GAAG,CAAA;AACf,QAAA,qBAAqB,GAAG,GAAG,iBAAS,SAAS,CAAA;AAC7C,QAAA,
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,yBAAyB,GACpC,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,yBAAyB,CAAA;AAC7C,QAAA,SAAS,GAAG,GAAG,CAAA;AACf,QAAA,qBAAqB,GAAG,GAAG,iBAAS,SAAS,CAAA;AAC7C,QAAA,uBAAuB,GAAG,aAAa,CAAA;AACvC,QAAA,yBAAyB,GAAG,eAAe,CAAA;AAC3C,QAAA,eAAe,GAAG,uBAAuB,CAAA;AACzC,QAAA,WAAW,GACtB,iEAAiE,CAAA;AAEnE,oCAAoC;AACvB,QAAA,aAAa,GAAG,kBAAkB,CAAA;AAClC,QAAA,wBAAwB,GAAG,qBAAqB,CAAA;AAChD,QAAA,oBAAoB,GAAG,cAAc,CAAA;AACrC,QAAA,iBAAiB,GAAG,WAAW,CAAA;AAE5C,sCAAsC;AACzB,QAAA,cAAc,GAAG,MAAM,CAAA;AACvB,QAAA,mBAAmB,GAAG,WAAW,CAAA;AACjC,QAAA,kBAAkB,GAAG,UAAU,CAAA"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { HubtypeCaseContactReason } from '@botonic/core';
|
|
2
|
+
import type { HtContactReasonBranch } from './hubtype-fields/contact-reasons-conditional';
|
|
3
|
+
export declare function contactReasonMatchesBranch(sessionContactReason: HubtypeCaseContactReason, branch: HtContactReasonBranch): boolean;
|
|
4
|
+
export declare function findMatchingContactReasonBranch(sessionContactReasons: HubtypeCaseContactReason[], contactReasonBranches: HtContactReasonBranch[]): HtContactReasonBranch | undefined;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.contactReasonMatchesBranch = contactReasonMatchesBranch;
|
|
4
|
+
exports.findMatchingContactReasonBranch = findMatchingContactReasonBranch;
|
|
5
|
+
function contactReasonMatchesBranch(sessionContactReason, branch) {
|
|
6
|
+
return (sessionContactReason.project_id === branch.project_id &&
|
|
7
|
+
sessionContactReason.name === branch.name);
|
|
8
|
+
}
|
|
9
|
+
function findMatchingContactReasonBranch(sessionContactReasons, contactReasonBranches) {
|
|
10
|
+
return contactReasonBranches.find(branch => sessionContactReasons.some(sessionContactReason => contactReasonMatchesBranch(sessionContactReason, branch)));
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=contact-reasons-conditional-matcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contact-reasons-conditional-matcher.js","sourceRoot":"","sources":["../../../src/content-fields/contact-reasons-conditional-matcher.ts"],"names":[],"mappings":";;AAIA,gEAQC;AAED,0EASC;AAnBD,SAAgB,0BAA0B,CACxC,oBAA8C,EAC9C,MAA6B;IAE7B,OAAO,CACL,oBAAoB,CAAC,UAAU,KAAK,MAAM,CAAC,UAAU;QACrD,oBAAoB,CAAC,IAAI,KAAK,MAAM,CAAC,IAAI,CAC1C,CAAA;AACH,CAAC;AAED,SAAgB,+BAA+B,CAC7C,qBAAiD,EACjD,qBAA8C;IAE9C,OAAO,qBAAqB,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CACzC,qBAAqB,CAAC,IAAI,CAAC,oBAAoB,CAAC,EAAE,CAChD,0BAA0B,CAAC,oBAAoB,EAAE,MAAM,CAAC,CACzD,CACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { BotContext } from '@botonic/core';
|
|
2
|
+
import { ContentFieldsBase } from './content-fields-base';
|
|
3
|
+
import type { HtNodeLink } from './hubtype-fields/common';
|
|
4
|
+
import type { HtContactReasonBranch, HtContactReasonsNode } from './hubtype-fields/contact-reasons-conditional';
|
|
5
|
+
export declare class FlowContactReasonsConditional extends ContentFieldsBase {
|
|
6
|
+
contactReasons: HtContactReasonBranch[];
|
|
7
|
+
defaultTarget?: HtNodeLink;
|
|
8
|
+
static fromHubtypeCMS(component: HtContactReasonsNode, botContext: BotContext): FlowContactReasonsConditional;
|
|
9
|
+
private setFollowUp;
|
|
10
|
+
trackFlow(_botContext: BotContext): Promise<void>;
|
|
11
|
+
processContent(_botContext: BotContext): Promise<void>;
|
|
12
|
+
toBotonic(): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
}
|