@botonic/plugin-flow-builder 0.58.0-alpha.0 → 0.58.0-alpha.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.
Files changed (51) hide show
  1. package/lib/cjs/action/push-flow-resolver.d.ts +3 -6
  2. package/lib/cjs/action/push-flow-resolver.js +20 -34
  3. package/lib/cjs/action/push-flow-resolver.js.map +1 -1
  4. package/lib/cjs/content-fields/flow-update-variables.d.ts +15 -0
  5. package/lib/cjs/content-fields/flow-update-variables.js +133 -0
  6. package/lib/cjs/content-fields/flow-update-variables.js.map +1 -0
  7. package/lib/cjs/content-fields/hubtype-fields/node-types.d.ts +2 -1
  8. package/lib/cjs/content-fields/hubtype-fields/node-types.js +1 -0
  9. package/lib/cjs/content-fields/hubtype-fields/node-types.js.map +1 -1
  10. package/lib/cjs/content-fields/hubtype-fields/nodes.d.ts +2 -1
  11. package/lib/cjs/content-fields/hubtype-fields/update-variables.d.ts +9 -0
  12. package/lib/cjs/content-fields/hubtype-fields/update-variables.js +3 -0
  13. package/lib/cjs/content-fields/hubtype-fields/update-variables.js.map +1 -0
  14. package/lib/cjs/content-fields/index.d.ts +3 -2
  15. package/lib/cjs/content-fields/index.js +3 -1
  16. package/lib/cjs/content-fields/index.js.map +1 -1
  17. package/lib/cjs/flow-factory.js +2 -0
  18. package/lib/cjs/flow-factory.js.map +1 -1
  19. package/lib/cjs/services/contact-info-fields-api.d.ts +7 -0
  20. package/lib/cjs/services/contact-info-fields-api.js +28 -0
  21. package/lib/cjs/services/contact-info-fields-api.js.map +1 -0
  22. package/lib/esm/action/push-flow-resolver.d.ts +3 -6
  23. package/lib/esm/action/push-flow-resolver.js +20 -34
  24. package/lib/esm/action/push-flow-resolver.js.map +1 -1
  25. package/lib/esm/content-fields/flow-update-variables.d.ts +15 -0
  26. package/lib/esm/content-fields/flow-update-variables.js +133 -0
  27. package/lib/esm/content-fields/flow-update-variables.js.map +1 -0
  28. package/lib/esm/content-fields/hubtype-fields/node-types.d.ts +2 -1
  29. package/lib/esm/content-fields/hubtype-fields/node-types.js +1 -0
  30. package/lib/esm/content-fields/hubtype-fields/node-types.js.map +1 -1
  31. package/lib/esm/content-fields/hubtype-fields/nodes.d.ts +2 -1
  32. package/lib/esm/content-fields/hubtype-fields/update-variables.d.ts +9 -0
  33. package/lib/esm/content-fields/hubtype-fields/update-variables.js +3 -0
  34. package/lib/esm/content-fields/hubtype-fields/update-variables.js.map +1 -0
  35. package/lib/esm/content-fields/index.d.ts +3 -2
  36. package/lib/esm/content-fields/index.js +3 -1
  37. package/lib/esm/content-fields/index.js.map +1 -1
  38. package/lib/esm/flow-factory.js +2 -0
  39. package/lib/esm/flow-factory.js.map +1 -1
  40. package/lib/esm/services/contact-info-fields-api.d.ts +7 -0
  41. package/lib/esm/services/contact-info-fields-api.js +28 -0
  42. package/lib/esm/services/contact-info-fields-api.js.map +1 -0
  43. package/package.json +2 -2
  44. package/src/action/push-flow-resolver.ts +38 -48
  45. package/src/content-fields/flow-update-variables.tsx +184 -0
  46. package/src/content-fields/hubtype-fields/node-types.ts +1 -0
  47. package/src/content-fields/hubtype-fields/nodes.ts +2 -0
  48. package/src/content-fields/hubtype-fields/update-variables.ts +10 -0
  49. package/src/content-fields/index.ts +3 -0
  50. package/src/flow-factory.ts +7 -0
  51. package/src/services/contact-info-fields-api.ts +36 -0
@@ -0,0 +1,133 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FlowUpdateVariables = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const core_1 = require("@botonic/core");
6
+ const constants_1 = require("../constants");
7
+ const contact_info_fields_api_1 = require("../services/contact-info-fields-api");
8
+ const tracking_1 = require("../tracking");
9
+ const get_flow_builder_plugin_1 = require("../utils/get-flow-builder-plugin");
10
+ const content_fields_base_1 = require("./content-fields-base");
11
+ const SESSION_CONTACT_INFO_PREFIX = 'session.user.contact_info.';
12
+ class FlowUpdateVariables extends content_fields_base_1.ContentFieldsBase {
13
+ constructor() {
14
+ super(...arguments);
15
+ this.setVariables = {};
16
+ this.unsetVariables = [];
17
+ }
18
+ static async fromHubtypeCMS(cmsUpdateVariables, botContext) {
19
+ const newUpdateVariables = new FlowUpdateVariables(cmsUpdateVariables.id);
20
+ newUpdateVariables.setVariables = cmsUpdateVariables.content.set_variables;
21
+ newUpdateVariables.unsetVariables =
22
+ cmsUpdateVariables.content.unset_variables;
23
+ await newUpdateVariables.applyVariablesAndSyncContactInfo(botContext);
24
+ return newUpdateVariables;
25
+ }
26
+ async applyVariablesAndSyncContactInfo(botContext) {
27
+ const contactInfoUpdates = [];
28
+ const updateVariable = (keyPath, value) => {
29
+ const fieldName = this.getContactInfoFieldName(keyPath);
30
+ if (fieldName) {
31
+ this.updateSessionContactInfoField(botContext, fieldName, value);
32
+ contactInfoUpdates.push({ fieldName, value });
33
+ }
34
+ else {
35
+ this.setSessionValueFromKeyPath(botContext, keyPath, value);
36
+ }
37
+ };
38
+ for (const [keyPath, value] of Object.entries(this.setVariables)) {
39
+ updateVariable(keyPath, value);
40
+ }
41
+ for (const keyPath of this.unsetVariables) {
42
+ updateVariable(keyPath, undefined);
43
+ }
44
+ if (contactInfoUpdates.length === 0) {
45
+ return;
46
+ }
47
+ const hubtypeApiUrl = botContext.session._hubtype_api || constants_1.FLOW_BUILDER_API_URL_PROD;
48
+ const flowBuilderPlugin = (0, get_flow_builder_plugin_1.getFlowBuilderPlugin)(botContext.plugins);
49
+ const accessToken = flowBuilderPlugin.getAccessToken(botContext.session);
50
+ const chatId = botContext.session.user.id;
51
+ const contactInfoFieldsClient = new contact_info_fields_api_1.ContactInfoFieldsClient(hubtypeApiUrl, accessToken);
52
+ await Promise.all(contactInfoUpdates.map(({ fieldName, value }) => {
53
+ if (value === undefined) {
54
+ return contactInfoFieldsClient.delete(chatId, fieldName);
55
+ }
56
+ return contactInfoFieldsClient.update(chatId, fieldName, value);
57
+ }));
58
+ }
59
+ setSessionValueFromKeyPath(botContext, keyPath, value) {
60
+ const keys = keyPath.split('.');
61
+ if (keys.shift() !== 'session') {
62
+ return;
63
+ }
64
+ const lastKey = keys.pop();
65
+ if (!lastKey) {
66
+ return;
67
+ }
68
+ let current = botContext.session;
69
+ for (const key of keys) {
70
+ if (current[key] === undefined || current[key] === null) {
71
+ current[key] = {};
72
+ }
73
+ current = current[key];
74
+ }
75
+ current[lastKey] = value;
76
+ }
77
+ getContactInfoFieldName(keyPath) {
78
+ if (!keyPath.startsWith(SESSION_CONTACT_INFO_PREFIX)) {
79
+ return undefined;
80
+ }
81
+ const fieldName = keyPath.slice(SESSION_CONTACT_INFO_PREFIX.length);
82
+ return fieldName || undefined;
83
+ }
84
+ updateSessionContactInfoField(botContext, fieldName, value) {
85
+ if (!botContext.session.user.contact_info) {
86
+ botContext.session.user.contact_info = [];
87
+ }
88
+ const contactInfo = botContext.session.user.contact_info;
89
+ const index = contactInfo.findIndex(field => field.name === fieldName);
90
+ if (value === undefined) {
91
+ if (index >= 0) {
92
+ contactInfo.splice(index, 1);
93
+ }
94
+ return;
95
+ }
96
+ const stringValue = String(value);
97
+ const valueType = typeof value;
98
+ if (index >= 0) {
99
+ contactInfo[index].value = stringValue;
100
+ contactInfo[index].type = valueType;
101
+ return;
102
+ }
103
+ contactInfo.push({
104
+ name: fieldName,
105
+ type: valueType,
106
+ value: stringValue,
107
+ });
108
+ }
109
+ async trackFlow(botContext) {
110
+ const { flowThreadId, flowId, flowName, flowNodeId, flowNodeContentId } = (0, tracking_1.getCommonFlowContentEventArgsForContentId)(botContext, this.id);
111
+ const eventUpdateVariables = {
112
+ action: core_1.EventAction.UpdateVariables,
113
+ flowThreadId,
114
+ flowId,
115
+ flowName,
116
+ flowNodeId,
117
+ flowNodeContentId,
118
+ flowNodeIsMeaningful: false,
119
+ setVariables: this.setVariables,
120
+ unsetVariables: this.unsetVariables,
121
+ };
122
+ const { action, ...eventArgs } = eventUpdateVariables;
123
+ await (0, tracking_1.trackEvent)(botContext, action, eventArgs);
124
+ }
125
+ async processContent(botContext) {
126
+ await this.trackFlow(botContext);
127
+ }
128
+ toBotonic() {
129
+ return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
130
+ }
131
+ }
132
+ exports.FlowUpdateVariables = FlowUpdateVariables;
133
+ //# sourceMappingURL=flow-update-variables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flow-update-variables.js","sourceRoot":"","sources":["../../../src/content-fields/flow-update-variables.tsx"],"names":[],"mappings":";;;;AAAA,wCAKsB;AAEtB,4CAAwD;AACxD,iFAA6E;AAC7E,0CAGoB;AACpB,8EAAuE;AACvE,+DAAyD;AAGzD,MAAM,2BAA2B,GAAG,4BAA4B,CAAA;AAEhE,MAAa,mBAAoB,SAAQ,uCAAiB;IAA1D;;QACS,iBAAY,GAA8C,EAAE,CAAA;QAC5D,mBAAc,GAAa,EAAE,CAAA;IAkKtC,CAAC;IAhKC,MAAM,CAAC,KAAK,CAAC,cAAc,CACzB,kBAAyC,EACzC,UAAsB;QAEtB,MAAM,kBAAkB,GAAG,IAAI,mBAAmB,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAA;QACzE,kBAAkB,CAAC,YAAY,GAAG,kBAAkB,CAAC,OAAO,CAAC,aAAa,CAAA;QAC1E,kBAAkB,CAAC,cAAc;YAC/B,kBAAkB,CAAC,OAAO,CAAC,eAAe,CAAA;QAC5C,MAAM,kBAAkB,CAAC,gCAAgC,CAAC,UAAU,CAAC,CAAA;QACrE,OAAO,kBAAkB,CAAA;IAC3B,CAAC;IAEO,KAAK,CAAC,gCAAgC,CAC5C,UAAsB;QAEtB,MAAM,kBAAkB,GAGlB,EAAE,CAAA;QAER,MAAM,cAAc,GAAG,CACrB,OAAe,EACf,KAA4C,EAC5C,EAAE;YACF,MAAM,SAAS,GAAG,IAAI,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAA;YAEvD,IAAI,SAAS,EAAE,CAAC;gBACd,IAAI,CAAC,6BAA6B,CA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,CAAC,cAAc;SACpC,CAAA;QACD,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,EAAE,GAAG,oBAAoB,CAAA;QACrD,MAAM,IAAA,qBAAU,EAAC,UAAU,EAAE,MAAM,EAAE,SAAS,CAAC,CAAA;IACjD,CAAC;IAED,KAAK,CAAC,cAAc,CAAC,UAAsB;QACzC,MAAM,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,CAAA;IAClC,CAAC;IAED,SAAS;QACP,OAAO,kDAAK,CAAA;IACd,CAAC;CACF;AApKD,kDAoKC"}
@@ -21,7 +21,8 @@ export declare enum HtNodeWithContentType {
21
21
  CAPTURE_USER_INPUT = "capture-user-input",
22
22
  CUSTOM_CONDITION = "custom-condition",
23
23
  DO_NOTHING = "do-nothing",
24
- CONTACT_REASONS_CONDITION = "contact-reasons-condition"
24
+ CONTACT_REASONS_CONDITION = "contact-reasons-condition",
25
+ UPDATE_VARIABLES = "update-variables"
25
26
  }
26
27
  export declare enum HtNodeWithoutContentType {
27
28
  URL = "url",
@@ -26,6 +26,7 @@ var HtNodeWithContentType;
26
26
  HtNodeWithContentType["CUSTOM_CONDITION"] = "custom-condition";
27
27
  HtNodeWithContentType["DO_NOTHING"] = "do-nothing";
28
28
  HtNodeWithContentType["CONTACT_REASONS_CONDITION"] = "contact-reasons-condition";
29
+ HtNodeWithContentType["UPDATE_VARIABLES"] = "update-variables";
29
30
  })(HtNodeWithContentType || (exports.HtNodeWithContentType = HtNodeWithContentType = {}));
30
31
  var HtNodeWithoutContentType;
31
32
  (function (HtNodeWithoutContentType) {
@@ -1 +1 @@
1
- {"version":3,"file":"node-types.js","sourceRoot":"","sources":["../../../../src/content-fields/hubtype-fields/node-types.ts"],"names":[],"mappings":";;;AAAA,IAAY,qBAwBX;AAxBD,WAAY,qBAAqB;IAC/B,8CAAqB,CAAA;IACrB,4CAAmB,CAAA;IACnB,wCAAe,CAAA;IACf,sCAAa,CAAA;IACb,4CAAmB,CAAA;IACnB,sDAA6B,CAAA;IAC7B,8CAAqB,CAAA;IACrB,8CAAqB,CAAA;IACrB,wCAAe,CAAA;IACf,sEAA6C,CAAA;IAC7C,4EAAmD,CAAA;IACnD,wFAA+D,CAAA;IAC/D,gEAAuC,CAAA;IACvC,kDAAyB,CAAA;IACzB,8CAAqB,CAAA;IACrB,4DAAmC,CAAA;IACnC,0CAAiB,CAAA;IACjB,4CAAmB,CAAA;IACnB,kDAAyB,CAAA;IACzB,kEAAyC,CAAA;IACzC,8DAAqC,CAAA;IACrC,kDAAyB,CAAA;IACzB,gFAAuD,CAAA;AACzD,CAAC,EAxBW,qBAAqB,qCAArB,qBAAqB,QAwBhC;AAED,IAAY,wBAGX;AAHD,WAAY,wBAAwB;IAClC,uCAAW,CAAA;IACX,+CAAmB,CAAA;AACrB,CAAC,EAHW,wBAAwB,wCAAxB,wBAAwB,QAGnC;AAED,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,kCAAiB,CAAA;IACjB,4CAA2B,CAAA;AAC7B,CAAC,EAHW,aAAa,6BAAb,aAAa,QAGxB"}
1
+ {"version":3,"file":"node-types.js","sourceRoot":"","sources":["../../../../src/content-fields/hubtype-fields/node-types.ts"],"names":[],"mappings":";;;AAAA,IAAY,qBAyBX;AAzBD,WAAY,qBAAqB;IAC/B,8CAAqB,CAAA;IACrB,4CAAmB,CAAA;IACnB,wCAAe,CAAA;IACf,sCAAa,CAAA;IACb,4CAAmB,CAAA;IACnB,sDAA6B,CAAA;IAC7B,8CAAqB,CAAA;IACrB,8CAAqB,CAAA;IACrB,wCAAe,CAAA;IACf,sEAA6C,CAAA;IAC7C,4EAAmD,CAAA;IACnD,wFAA+D,CAAA;IAC/D,gEAAuC,CAAA;IACvC,kDAAyB,CAAA;IACzB,8CAAqB,CAAA;IACrB,4DAAmC,CAAA;IACnC,0CAAiB,CAAA;IACjB,4CAAmB,CAAA;IACnB,kDAAyB,CAAA;IACzB,kEAAyC,CAAA;IACzC,8DAAqC,CAAA;IACrC,kDAAyB,CAAA;IACzB,gFAAuD,CAAA;IACvD,8DAAqC,CAAA;AACvC,CAAC,EAzBW,qBAAqB,qCAArB,qBAAqB,QAyBhC;AAED,IAAY,wBAGX;AAHD,WAAY,wBAAwB;IAClC,uCAAW,CAAA;IACX,+CAAmB,CAAA;AACrB,CAAC,EAHW,wBAAwB,wCAAxB,wBAAwB,QAGnC;AAED,IAAY,aAGX;AAHD,WAAY,aAAa;IACvB,kCAAiB,CAAA;IACjB,4CAA2B,CAAA;AAC7B,CAAC,EAHW,aAAa,6BAAb,aAAa,QAGxB"}
@@ -16,6 +16,7 @@ import type { HtPayloadNode } from './payload';
16
16
  import type { HtRatingNode } from './rating';
17
17
  import type { HtSmartIntentNode } from './smart-intent';
18
18
  import type { HtTextNode } from './text';
19
+ import type { HtUpdateVariablesNode } from './update-variables';
19
20
  import type { HtUrlNode } from './url';
20
21
  import type { HtVideoNode } from './video';
21
22
  import type { HtWebviewNode } from './webview';
@@ -23,6 +24,6 @@ import type { HtWhatsappButtonListNode } from './whatsapp-button-list';
23
24
  import type { HtWhatsappCTAUrlButtonNode } from './whatsapp-cta-url-button';
24
25
  import type { HtWhatsappRequestContactInfoNode } from './whatsapp-request-contact-info';
25
26
  import type { HtWhatsappTemplateNode } from './whatsapp-template';
26
- export type HtNodeWithContent = HtTextNode | HtImageNode | HtVideoNode | HtCarouselNode | HtHandoffNode | HtKeywordNode | HtFunctionNode | HtFallbackNode | HtWhatsappButtonListNode | HtWhatsappCTAUrlButtonNode | HtWhatsappRequestContactInfoNode | HtSmartIntentNode | HtBotActionNode | HtAiAgentNode | HtAiAgentRouterNode | HtRatingNode | HtWebviewNode | HtGoToFlow | HtWhatsappTemplateNode | HtCaptureUserInputNode | HtCustomConditionalV2Node | HtDoNothingNode | HtContactReasonsNode;
27
+ export type HtNodeWithContent = HtTextNode | HtImageNode | HtVideoNode | HtCarouselNode | HtHandoffNode | HtKeywordNode | HtFunctionNode | HtFallbackNode | HtWhatsappButtonListNode | HtWhatsappCTAUrlButtonNode | HtWhatsappRequestContactInfoNode | HtSmartIntentNode | HtBotActionNode | HtAiAgentNode | HtAiAgentRouterNode | HtRatingNode | HtWebviewNode | HtGoToFlow | HtWhatsappTemplateNode | HtCaptureUserInputNode | HtCustomConditionalV2Node | HtDoNothingNode | HtContactReasonsNode | HtUpdateVariablesNode;
27
28
  export type HtNodeWithoutContent = HtUrlNode | HtPayloadNode;
28
29
  export type HtNodeComponent = HtNodeWithContent | HtNodeWithoutContent;
@@ -0,0 +1,9 @@
1
+ import type { HtBaseNode } from './common';
2
+ import type { HtNodeWithContentType } from './node-types';
3
+ export interface HtUpdateVariablesNode extends HtBaseNode {
4
+ type: HtNodeWithContentType.UPDATE_VARIABLES;
5
+ content: {
6
+ set_variables: Record<string, string | number | boolean>;
7
+ unset_variables: string[];
8
+ };
9
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=update-variables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-variables.js","sourceRoot":"","sources":["../../../../src/content-fields/hubtype-fields/update-variables.ts"],"names":[],"mappings":""}
@@ -15,6 +15,7 @@ import { FlowImage } from './flow-image';
15
15
  import { FlowQueueStatusConditional } from './flow-queue-status-conditional';
16
16
  import { FlowRating } from './flow-rating';
17
17
  import { FlowText } from './flow-text';
18
+ import { FlowUpdateVariables } from './flow-update-variables';
18
19
  import { FlowVideo } from './flow-video';
19
20
  import { FlowWhatsappCtaUrlButtonNode } from './flow-whatsapp-cta-url-button';
20
21
  import { FlowWhatsappRequestContactInfoNode } from './flow-whatsapp-request-contact-info';
@@ -23,5 +24,5 @@ import { FlowWhatsappButtonList, FlowWhatsappButtonListRow, FlowWhatsappButtonLi
23
24
  export { ContentFieldsBase } from './content-fields-base';
24
25
  export { FlowButton } from './flow-button';
25
26
  export { FlowElement } from './flow-element';
26
- export { FlowAiAgent, FlowAiAgentRouter, FlowBotAction, FlowCaptureUserInput, FlowCarousel, FlowChannelConditional, FlowContactReasonsConditional, FlowCountryConditional, FlowCustomConditional, FlowCustomConditionalV2, FlowDoNothing, FlowGoToFlow, FlowHandoff, FlowImage, FlowQueueStatusConditional, FlowRating, FlowText, FlowVideo, FlowWhatsappButtonList, FlowWhatsappButtonListRow, FlowWhatsappButtonListSection, FlowWhatsappCtaUrlButtonNode, FlowWhatsappRequestContactInfoNode, FlowWhatsappTemplate, };
27
- export type FlowContent = FlowCarousel | FlowImage | FlowText | FlowVideo | FlowWhatsappButtonList | FlowWhatsappCtaUrlButtonNode | FlowWhatsappRequestContactInfoNode | FlowWhatsappTemplate | FlowHandoff | FlowBotAction | FlowAiAgent | FlowRating | FlowCountryConditional | FlowChannelConditional | FlowQueueStatusConditional | FlowCustomConditional | FlowGoToFlow | FlowCaptureUserInput | FlowAiAgentRouter | FlowCustomConditionalV2 | FlowDoNothing | FlowContactReasonsConditional;
27
+ export { FlowAiAgent, FlowAiAgentRouter, FlowBotAction, FlowCaptureUserInput, FlowCarousel, FlowChannelConditional, FlowContactReasonsConditional, FlowCountryConditional, FlowCustomConditional, FlowCustomConditionalV2, FlowDoNothing, FlowGoToFlow, FlowHandoff, FlowImage, FlowQueueStatusConditional, FlowRating, FlowText, FlowUpdateVariables, FlowVideo, FlowWhatsappButtonList, FlowWhatsappButtonListRow, FlowWhatsappButtonListSection, FlowWhatsappCtaUrlButtonNode, FlowWhatsappRequestContactInfoNode, FlowWhatsappTemplate, };
28
+ export type FlowContent = FlowCarousel | FlowImage | FlowText | FlowVideo | FlowWhatsappButtonList | FlowWhatsappCtaUrlButtonNode | FlowWhatsappRequestContactInfoNode | FlowWhatsappTemplate | FlowHandoff | FlowBotAction | FlowAiAgent | FlowRating | FlowCountryConditional | FlowChannelConditional | FlowQueueStatusConditional | FlowCustomConditional | FlowGoToFlow | FlowCaptureUserInput | FlowAiAgentRouter | FlowCustomConditionalV2 | FlowDoNothing | FlowUpdateVariables | FlowContactReasonsConditional;
@@ -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.FlowContactReasonsConditional = 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.FlowUpdateVariables = 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");
@@ -35,6 +35,8 @@ const flow_rating_1 = require("./flow-rating");
35
35
  Object.defineProperty(exports, "FlowRating", { enumerable: true, get: function () { return flow_rating_1.FlowRating; } });
36
36
  const flow_text_1 = require("./flow-text");
37
37
  Object.defineProperty(exports, "FlowText", { enumerable: true, get: function () { return flow_text_1.FlowText; } });
38
+ const flow_update_variables_1 = require("./flow-update-variables");
39
+ Object.defineProperty(exports, "FlowUpdateVariables", { enumerable: true, get: function () { return flow_update_variables_1.FlowUpdateVariables; } });
38
40
  const flow_video_1 = require("./flow-video");
39
41
  Object.defineProperty(exports, "FlowVideo", { enumerable: true, get: function () { return flow_video_1.FlowVideo; } });
40
42
  const flow_whatsapp_cta_url_button_1 = require("./flow-whatsapp-cta-url-button");
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/content-fields/index.ts"],"names":[],"mappings":";;;AAAA,4FAAuF;AAwCrF,wGAxCO,kDAAuB,OAwCP;AAvCzB,mDAA6C;AA8B3C,4FA9BO,2BAAW,OA8BP;AA7Bb,iEAA0D;AA8BxD,kGA9BO,wCAAiB,OA8BP;AA7BnB,uDAAiD;AA8B/C,8FA9BO,+BAAa,OA8BP;AA7Bf,uEAAgE;AA8B9D,qGA9BO,8CAAoB,OA8BP;AA7BtB,mDAA8C;AA8B5C,6FA9BO,4BAAY,OA8BP;AA7Bd,yEAAmE;AA8BjE,uGA9BO,iDAAsB,OA8BP;AA7BxB,yFAAkF;AA8BhF,8GA9BO,gEAA6B,OA8BP;AA7B/B,yEAAmE;AA8BjE,uGA9BO,iDAAsB,OA8BP;AA7BxB,uEAAiE;AA8B/D,sGA9BO,+CAAqB,OA8BP;AA7BvB,uDAAiD;AA+B/C,8FA/BO,+BAAa,OA+BP;AA9Bf,uDAAgD;AA+B9C,6FA/BO,8BAAY,OA+BP;AA9Bd,iDAA4C;AA+B1C,4FA/BO,0BAAW,OA+BP;AA9Bb,6CAAwC;AA+BtC,0FA/BO,sBAAS,OA+BP;AA9BX,mFAA4E;AA+B1E,2GA/BO,0DAA0B,OA+BP;AA9B5B,+CAA0C;AA+BxC,2FA/BO,wBAAU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AAS,OAgCP;AA/BX,mFAA4E;AAgC1E,2GAhCO,0DAA0B,OAgCP;AA/B5B,+CAA0C;AAgCxC,2FAhCO,wBAAU,OAgCP;AA/BZ,2CAAsC;AAgCpC,yFAhCO,oBAAQ,OAgCP;AA/BV,mEAA6D;AAgC3D,oGAhCO,2CAAmB,OAgCP;AA/BrB,6CAAwC;AAgCtC,0FAhCO,sBAAS,OAgCP;AA/BX,iFAA6E;AAmC3E,6GAnCO,2DAA4B,OAmCP;AAlC9B,6FAAyF;AAmCvF,mHAnCO,uEAAkC,OAmCP;AAlCpC,qEAA+D;AAmC7D,qGAnCO,6CAAoB,OAmCP;AAlCtB,iEAI+B;AAyB7B,uGA5BA,6CAAsB,OA4BA;AACtB,0GA5BA,gDAAyB,OA4BA;AACzB,8GA5BA,oDAA6B,OA4BA;AAzB/B,6DAAyD;AAAhD,wHAAA,iBAAiB,OAAA;AAC1B,6CAA0C;AAAjC,yGAAA,UAAU,OAAA;AACnB,+CAA4C;AAAnC,2GAAA,WAAW,OAAA"}
@@ -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.UPDATE_VARIABLES:
52
+ return content_fields_1.FlowUpdateVariables.fromHubtypeCMS(hubtypeContent, this.botContext);
51
53
  case hubtype_fields_1.HtNodeWithContentType.CONTACT_REASONS_CONDITION:
52
54
  return content_fields_1.FlowContactReasonsConditional.fromHubtypeCMS(hubtypeContent, this.botContext);
53
55
  default:
@@ -1 +1 @@
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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AClB,OAAO,uCAAsB,CAAC,cAAc,CAC1C,cAAc,EACd,IAAI,CAAC,UAAU,CAChB,CAAA;YACH,KAAK,kBAAkB;gBACrB,OAAO,uCAAsB,CAAC,cAAc,CAC1C,cAAc,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;AAxID,kCAwIC"}
@@ -0,0 +1,7 @@
1
+ export declare class ContactInfoFieldsClient {
2
+ private readonly hubtypeApiUrl;
3
+ private readonly accessToken;
4
+ constructor(hubtypeApiUrl: string, accessToken: string);
5
+ update(chatId: string, fieldName: string, value: string | number | boolean): Promise<void>;
6
+ delete(chatId: string, fieldName: string): Promise<void>;
7
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContactInfoFieldsClient = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const axios_1 = tslib_1.__importDefault(require("axios"));
6
+ class ContactInfoFieldsClient {
7
+ constructor(hubtypeApiUrl, accessToken) {
8
+ this.hubtypeApiUrl = hubtypeApiUrl;
9
+ this.accessToken = accessToken;
10
+ }
11
+ async update(chatId, fieldName, value) {
12
+ await axios_1.default.put(`${this.hubtypeApiUrl}/external/v1/chats/${chatId}/contact_info_fields/${encodeURIComponent(fieldName)}/`, { value }, {
13
+ headers: {
14
+ 'Content-Type': 'application/json',
15
+ Authorization: `Bearer ${this.accessToken}`,
16
+ },
17
+ });
18
+ }
19
+ async delete(chatId, fieldName) {
20
+ await axios_1.default.delete(`${this.hubtypeApiUrl}/external/v1/chats/${chatId}/contact_info_fields/${encodeURIComponent(fieldName)}/`, {
21
+ headers: {
22
+ Authorization: `Bearer ${this.accessToken}`,
23
+ },
24
+ });
25
+ }
26
+ }
27
+ exports.ContactInfoFieldsClient = ContactInfoFieldsClient;
28
+ //# sourceMappingURL=contact-info-fields-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contact-info-fields-api.js","sourceRoot":"","sources":["../../../src/services/contact-info-fields-api.ts"],"names":[],"mappings":";;;;AAAA,0DAAyB;AAEzB,MAAa,uBAAuB;IAClC,YACmB,aAAqB,EACrB,WAAmB;QADnB,kBAAa,GAAb,aAAa,CAAQ;QACrB,gBAAW,GAAX,WAAW,CAAQ;IACnC,CAAC;IAEJ,KAAK,CAAC,MAAM,CACV,MAAc,EACd,SAAiB,EACjB,KAAgC;QAEhC,MAAM,eAAK,CAAC,GAAG,CACb,GAAG,IAAI,CAAC,aAAa,sBAAsB,MAAM,wBAAwB,kBAAkB,CAAC,SAAS,CAAC,GAAG,EACzG,EAAE,KAAK,EAAE,EACT;YACE,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,aAAa,EAAE,UAAU,IAAI,CAAC,WAAW,EAAE;aAC5C;SACF,CACF,CAAA;IACH,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,MAAc,EAAE,SAAiB;QAC5C,MAAM,eAAK,CAAC,MAAM,CAChB,GAAG,IAAI,CAAC,aAAa,sBAAsB,MAAM,wBAAwB,kBAAkB,CAAC,SAAS,CAAC,GAAG,EACzG;YACE,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,IAAI,CAAC,WAAW,EAAE;aAC5C;SACF,CACF,CAAA;IACH,CAAC;CACF;AAjCD,0DAiCC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botonic/plugin-flow-builder",
3
- "version": "0.58.0-alpha.0",
3
+ "version": "0.58.0-alpha.2",
4
4
  "main": "./lib/cjs/index.js",
5
5
  "module": "./lib/esm/index.js",
6
6
  "description": "Use Flow Builder to show your contents",
@@ -15,7 +15,7 @@
15
15
  "format": "biome format --write src/ tests/"
16
16
  },
17
17
  "dependencies": {
18
- "@botonic/react": "0.58.0-alpha.0",
18
+ "@botonic/react": "0.58.0-alpha.2",
19
19
  "axios": "^1.18.1",
20
20
  "uuid": "^10.0.0"
21
21
  },
@@ -1,16 +1,18 @@
1
- import type { BotContext } from '@botonic/core'
1
+ import {
2
+ type BotContext,
3
+ BotonicInputContextType,
4
+ getInputContextOfType,
5
+ } from '@botonic/core'
2
6
  import type { FlowBuilderApi } from '../api'
3
- import { SEPARATOR } from '../constants'
4
7
  import type { HtNodeWithContent } from '../content-fields/hubtype-fields'
5
8
  import type BotonicPluginFlowBuilder from '../index'
6
9
  import type { FlowBuilderContentsResult } from './contents-result'
7
10
  import type { FlowBuilderContext } from './context'
8
11
 
9
12
  export enum PushFlowErrorCode {
10
- NoInputPayload = 'NoInputPayload',
11
- NoPushFlowId = 'NoPushFlowId',
13
+ NoCampaignContext = 'NoCampaignContext',
12
14
  NoCampaignStartNode = 'NoCampaignStartNode',
13
- NoCampaignId = 'NoCampaignId',
15
+ NoCampaignFollowUpNode = 'NoCampaignFollowUpNode',
14
16
  }
15
17
 
16
18
  export class PushFlowError extends Error {
@@ -35,67 +37,55 @@ export class PushFlowResolver {
35
37
  }
36
38
 
37
39
  async getContents(): Promise<FlowBuilderContentsResult> {
38
- const pushFlowId = this.getPushFlowId()
39
- const pushFlowNode = this.getPushFlowNode(pushFlowId)
40
- const campaignId = this.getCampaignId()
40
+ const campaignContext = getInputContextOfType(
41
+ this.botContext.input.context,
42
+ BotonicInputContextType.PushFlow
43
+ )
41
44
 
42
- return {
43
- contents: await this.flowBuilderPlugin.getContentsByNode(pushFlowNode),
44
- campaignFirstMessageId: campaignId,
45
- }
46
- }
47
-
48
- private getPushFlowId(): string {
49
- const payload = this.botContext.input.payload
50
-
51
- if (!payload) {
45
+ if (!campaignContext) {
52
46
  throw new PushFlowError(
53
- PushFlowErrorCode.NoInputPayload,
54
- 'No payload found in input'
47
+ PushFlowErrorCode.NoCampaignContext,
48
+ 'No campaign context found in input context'
55
49
  )
56
50
  }
57
51
 
58
- const parts = payload.split(SEPARATOR)
59
- const pushFlowId = parts.length > 1 ? parts[1] : ''
52
+ const {
53
+ campaign_id: campaignId,
54
+ campaign_flow_id: campaignFlowId,
55
+ campaign_follow_up_id: campaignFollowUpId,
56
+ } = campaignContext
57
+
58
+ const campaignStartNode = this.getCampaignStartNode(campaignFlowId)
59
+ const followUpNode = campaignFollowUpId
60
+ ? this.cmsApi.getNodeById<HtNodeWithContent>(campaignFollowUpId)
61
+ : undefined
60
62
 
61
- if (!pushFlowId) {
63
+ if (campaignFollowUpId && !followUpNode) {
62
64
  throw new PushFlowError(
63
- PushFlowErrorCode.NoPushFlowId,
64
- 'No push flow id found in input payload'
65
+ PushFlowErrorCode.NoCampaignFollowUpNode,
66
+ 'No campaign follow up node found'
65
67
  )
66
68
  }
67
69
 
68
- return pushFlowId
70
+ return {
71
+ contents: await this.flowBuilderPlugin.getContentsByNode(
72
+ followUpNode ?? campaignStartNode
73
+ ),
74
+ campaignFirstMessageId: campaignId,
75
+ }
69
76
  }
70
77
 
71
- private getPushFlowNode(pushFlowId: string): HtNodeWithContent {
72
- const pushFlowNode =
73
- this.cmsApi.getNodeByCampaignId<HtNodeWithContent>(pushFlowId)
78
+ private getCampaignStartNode(campaignId: string): HtNodeWithContent {
79
+ const campaignStartNode =
80
+ this.cmsApi.getNodeByCampaignId<HtNodeWithContent>(campaignId)
74
81
 
75
- if (!pushFlowNode) {
82
+ if (!campaignStartNode) {
76
83
  throw new PushFlowError(
77
84
  PushFlowErrorCode.NoCampaignStartNode,
78
85
  'No campaign start node found'
79
86
  )
80
87
  }
81
88
 
82
- return pushFlowNode
83
- }
84
-
85
- private getCampaignId(): string {
86
- const campaignId =
87
- this.botContext.input.context &&
88
- 'campaign_id' in this.botContext.input.context
89
- ? this.botContext.input.context.campaign_id
90
- : undefined
91
-
92
- if (!campaignId) {
93
- throw new PushFlowError(
94
- PushFlowErrorCode.NoCampaignId,
95
- 'No campaign id found in input context'
96
- )
97
- }
98
-
99
- return campaignId
89
+ return campaignStartNode
100
90
  }
101
91
  }
@@ -0,0 +1,184 @@
1
+ import {
2
+ type BotContext,
3
+ EventAction,
4
+ type EventUpdateVariables,
5
+ type Session,
6
+ } from '@botonic/core'
7
+
8
+ import { FLOW_BUILDER_API_URL_PROD } from '../constants'
9
+ import { ContactInfoFieldsClient } from '../services/contact-info-fields-api'
10
+ import {
11
+ getCommonFlowContentEventArgsForContentId,
12
+ trackEvent,
13
+ } from '../tracking'
14
+ import { getFlowBuilderPlugin } from '../utils/get-flow-builder-plugin'
15
+ import { ContentFieldsBase } from './content-fields-base'
16
+ import type { HtUpdateVariablesNode } from './hubtype-fields/update-variables'
17
+
18
+ const SESSION_CONTACT_INFO_PREFIX = 'session.user.contact_info.'
19
+
20
+ export class FlowUpdateVariables extends ContentFieldsBase {
21
+ public setVariables: Record<string, string | number | boolean> = {}
22
+ public unsetVariables: string[] = []
23
+
24
+ static async fromHubtypeCMS(
25
+ cmsUpdateVariables: HtUpdateVariablesNode,
26
+ botContext: BotContext
27
+ ): Promise<FlowUpdateVariables> {
28
+ const newUpdateVariables = new FlowUpdateVariables(cmsUpdateVariables.id)
29
+ newUpdateVariables.setVariables = cmsUpdateVariables.content.set_variables
30
+ newUpdateVariables.unsetVariables =
31
+ cmsUpdateVariables.content.unset_variables
32
+ await newUpdateVariables.applyVariablesAndSyncContactInfo(botContext)
33
+ return newUpdateVariables
34
+ }
35
+
36
+ private async applyVariablesAndSyncContactInfo(
37
+ botContext: BotContext
38
+ ): Promise<void> {
39
+ const contactInfoUpdates: {
40
+ fieldName: string
41
+ value: string | number | boolean | undefined
42
+ }[] = []
43
+
44
+ const updateVariable = (
45
+ keyPath: string,
46
+ value: string | number | boolean | undefined
47
+ ) => {
48
+ const fieldName = this.getContactInfoFieldName(keyPath)
49
+
50
+ if (fieldName) {
51
+ this.updateSessionContactInfoField(botContext, fieldName, value)
52
+ contactInfoUpdates.push({ fieldName, value })
53
+ } else {
54
+ this.setSessionValueFromKeyPath(botContext, keyPath, value)
55
+ }
56
+ }
57
+
58
+ for (const [keyPath, value] of Object.entries(this.setVariables)) {
59
+ updateVariable(keyPath, value)
60
+ }
61
+
62
+ for (const keyPath of this.unsetVariables) {
63
+ updateVariable(keyPath, undefined)
64
+ }
65
+
66
+ if (contactInfoUpdates.length === 0) {
67
+ return
68
+ }
69
+
70
+ const hubtypeApiUrl =
71
+ botContext.session._hubtype_api || FLOW_BUILDER_API_URL_PROD
72
+ const flowBuilderPlugin = getFlowBuilderPlugin(botContext.plugins)
73
+ const accessToken = flowBuilderPlugin.getAccessToken(botContext.session)
74
+ const chatId = botContext.session.user.id
75
+
76
+ const contactInfoFieldsClient = new ContactInfoFieldsClient(
77
+ hubtypeApiUrl,
78
+ accessToken
79
+ )
80
+
81
+ await Promise.all(
82
+ contactInfoUpdates.map(({ fieldName, value }) => {
83
+ if (value === undefined) {
84
+ return contactInfoFieldsClient.delete(chatId, fieldName)
85
+ }
86
+ return contactInfoFieldsClient.update(chatId, fieldName, value)
87
+ })
88
+ )
89
+ }
90
+
91
+ private setSessionValueFromKeyPath(
92
+ botContext: BotContext,
93
+ keyPath: string,
94
+ value: string | number | boolean | undefined
95
+ ): void {
96
+ const keys = keyPath.split('.')
97
+ if (keys.shift() !== 'session') {
98
+ return
99
+ }
100
+
101
+ const lastKey = keys.pop()
102
+ if (!lastKey) {
103
+ return
104
+ }
105
+
106
+ let current: Session = botContext.session
107
+ for (const key of keys) {
108
+ if (current[key] === undefined || current[key] === null) {
109
+ current[key] = {}
110
+ }
111
+ current = current[key]
112
+ }
113
+ current[lastKey] = value
114
+ }
115
+
116
+ private getContactInfoFieldName(keyPath: string): string | undefined {
117
+ if (!keyPath.startsWith(SESSION_CONTACT_INFO_PREFIX)) {
118
+ return undefined
119
+ }
120
+ const fieldName = keyPath.slice(SESSION_CONTACT_INFO_PREFIX.length)
121
+ return fieldName || undefined
122
+ }
123
+
124
+ private updateSessionContactInfoField(
125
+ botContext: BotContext,
126
+ fieldName: string,
127
+ value: string | number | boolean | undefined
128
+ ): void {
129
+ if (!botContext.session.user.contact_info) {
130
+ botContext.session.user.contact_info = []
131
+ }
132
+
133
+ const contactInfo = botContext.session.user.contact_info
134
+ const index = contactInfo.findIndex(field => field.name === fieldName)
135
+
136
+ if (value === undefined) {
137
+ if (index >= 0) {
138
+ contactInfo.splice(index, 1)
139
+ }
140
+ return
141
+ }
142
+
143
+ const stringValue = String(value)
144
+ const valueType = typeof value
145
+
146
+ if (index >= 0) {
147
+ contactInfo[index].value = stringValue
148
+ contactInfo[index].type = valueType
149
+ return
150
+ }
151
+
152
+ contactInfo.push({
153
+ name: fieldName,
154
+ type: valueType,
155
+ value: stringValue,
156
+ })
157
+ }
158
+
159
+ async trackFlow(botContext: BotContext): Promise<void> {
160
+ const { flowThreadId, flowId, flowName, flowNodeId, flowNodeContentId } =
161
+ getCommonFlowContentEventArgsForContentId(botContext, this.id)
162
+ const eventUpdateVariables: EventUpdateVariables = {
163
+ action: EventAction.UpdateVariables,
164
+ flowThreadId,
165
+ flowId,
166
+ flowName,
167
+ flowNodeId,
168
+ flowNodeContentId,
169
+ flowNodeIsMeaningful: false,
170
+ setVariables: this.setVariables,
171
+ unsetVariables: this.unsetVariables,
172
+ }
173
+ const { action, ...eventArgs } = eventUpdateVariables
174
+ await trackEvent(botContext, action, eventArgs)
175
+ }
176
+
177
+ async processContent(botContext: BotContext): Promise<void> {
178
+ await this.trackFlow(botContext)
179
+ }
180
+
181
+ toBotonic() {
182
+ return <></>
183
+ }
184
+ }