@botonic/plugin-flow-builder 0.25.0-alpha.8 → 0.25.0-beta.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/action/index.js +4 -2
- package/lib/cjs/action/index.js.map +1 -1
- package/lib/cjs/action/knowledge-bases.js +2 -1
- package/lib/cjs/action/knowledge-bases.js.map +1 -1
- package/lib/cjs/api.d.ts +3 -1
- package/lib/cjs/api.js +26 -3
- package/lib/cjs/api.js.map +1 -1
- package/lib/cjs/constants.d.ts +3 -1
- package/lib/cjs/constants.js +4 -2
- package/lib/cjs/constants.js.map +1 -1
- package/lib/cjs/content-fields/flow-text.d.ts +4 -2
- package/lib/cjs/content-fields/flow-text.js +17 -10
- package/lib/cjs/content-fields/flow-text.js.map +1 -1
- package/lib/cjs/content-fields/hubtype-fields/function.d.ts +3 -1
- package/lib/cjs/content-fields/hubtype-fields/function.js +1 -0
- package/lib/cjs/content-fields/hubtype-fields/function.js.map +1 -1
- package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.d.ts +2 -1
- package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.js +2 -3
- package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.js.map +1 -1
- package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.d.ts +2 -1
- package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.js +2 -2
- package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.js.map +1 -1
- package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list.d.ts +2 -1
- package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list.js +2 -2
- package/lib/cjs/content-fields/whatsapp-button-list/flow-whatsapp-button-list.js.map +1 -1
- package/lib/cjs/functions/conditional-bot-variable.d.ts +8 -0
- package/lib/cjs/functions/conditional-bot-variable.js +11 -0
- package/lib/cjs/functions/conditional-bot-variable.js.map +1 -0
- package/lib/cjs/functions/conditional-country.d.ts +7 -0
- package/lib/cjs/functions/conditional-country.js +9 -0
- package/lib/cjs/functions/conditional-country.js.map +1 -0
- package/lib/cjs/functions/conditional-provider.js +1 -3
- package/lib/cjs/functions/conditional-provider.js.map +1 -1
- package/lib/cjs/functions/conditional-queue-status.d.ts +8 -2
- package/lib/cjs/functions/conditional-queue-status.js +14 -6
- package/lib/cjs/functions/conditional-queue-status.js.map +1 -1
- package/lib/cjs/functions/index.d.ts +4 -0
- package/lib/cjs/functions/index.js +4 -0
- package/lib/cjs/functions/index.js.map +1 -1
- package/lib/cjs/index.d.ts +3 -2
- package/lib/cjs/index.js +30 -14
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/utils.d.ts +2 -0
- package/lib/cjs/utils.js +18 -1
- package/lib/cjs/utils.js.map +1 -1
- package/lib/esm/action/index.js +4 -2
- package/lib/esm/action/index.js.map +1 -1
- package/lib/esm/action/knowledge-bases.js +2 -1
- package/lib/esm/action/knowledge-bases.js.map +1 -1
- package/lib/esm/api.d.ts +3 -1
- package/lib/esm/api.js +27 -4
- package/lib/esm/api.js.map +1 -1
- package/lib/esm/constants.d.ts +3 -1
- package/lib/esm/constants.js +3 -1
- package/lib/esm/constants.js.map +1 -1
- package/lib/esm/content-fields/flow-text.d.ts +4 -2
- package/lib/esm/content-fields/flow-text.js +18 -11
- package/lib/esm/content-fields/flow-text.js.map +1 -1
- package/lib/esm/content-fields/hubtype-fields/function.d.ts +3 -1
- package/lib/esm/content-fields/hubtype-fields/function.js +1 -0
- package/lib/esm/content-fields/hubtype-fields/function.js.map +1 -1
- package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.d.ts +2 -1
- package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.js +2 -3
- package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.js.map +1 -1
- package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.d.ts +2 -1
- package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.js +2 -2
- package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.js.map +1 -1
- package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list.d.ts +2 -1
- package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list.js +2 -2
- package/lib/esm/content-fields/whatsapp-button-list/flow-whatsapp-button-list.js.map +1 -1
- package/lib/esm/functions/conditional-bot-variable.d.ts +8 -0
- package/lib/esm/functions/conditional-bot-variable.js +7 -0
- package/lib/esm/functions/conditional-bot-variable.js.map +1 -0
- package/lib/esm/functions/conditional-country.d.ts +7 -0
- package/lib/esm/functions/conditional-country.js +5 -0
- package/lib/esm/functions/conditional-country.js.map +1 -0
- package/lib/esm/functions/conditional-provider.js +1 -3
- package/lib/esm/functions/conditional-provider.js.map +1 -1
- package/lib/esm/functions/conditional-queue-status.d.ts +8 -2
- package/lib/esm/functions/conditional-queue-status.js +14 -6
- package/lib/esm/functions/conditional-queue-status.js.map +1 -1
- package/lib/esm/functions/index.d.ts +4 -0
- package/lib/esm/functions/index.js +4 -0
- package/lib/esm/functions/index.js.map +1 -1
- package/lib/esm/index.d.ts +3 -2
- package/lib/esm/index.js +30 -14
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/utils.d.ts +2 -0
- package/lib/esm/utils.js +16 -0
- package/lib/esm/utils.js.map +1 -1
- package/package.json +4 -6
- package/src/action/index.tsx +4 -2
- package/src/action/knowledge-bases.ts +3 -2
- package/src/api.ts +35 -4
- package/src/constants.ts +3 -1
- package/src/content-fields/flow-text.tsx +23 -17
- package/src/content-fields/hubtype-fields/function.ts +4 -1
- package/src/content-fields/whatsapp-button-list/flow-whatsapp-button-list-row.tsx +4 -2
- package/src/content-fields/whatsapp-button-list/flow-whatsapp-button-list-section.tsx +4 -2
- package/src/content-fields/whatsapp-button-list/flow-whatsapp-button-list.tsx +4 -2
- package/src/functions/conditional-bot-variable.ts +18 -0
- package/src/functions/conditional-country.ts +14 -0
- package/src/functions/conditional-provider.ts +1 -2
- package/src/functions/conditional-queue-status.ts +17 -6
- package/src/functions/index.ts +4 -0
- package/src/index.ts +48 -17
- package/src/utils.ts +26 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"conditional-country.js","sourceRoot":"","sources":["../../../src/functions/conditional-country.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,kBAAkB,CAAC,EACjC,OAAO,EACP,OAAO,GACgB;IACvB,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAA;IACvD,OAAO,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,KAAK,OAAO,CAAC,IAAI,SAAS,CAAA;AAChE,CAAC"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
export function conditionalProvider({ request, results, }) {
|
|
2
2
|
const provider = request.session.user.provider;
|
|
3
|
-
|
|
4
|
-
return provider;
|
|
5
|
-
return 'default';
|
|
3
|
+
return results.find(result => result === provider) || 'default';
|
|
6
4
|
}
|
|
7
5
|
//# sourceMappingURL=conditional-provider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditional-provider.js","sourceRoot":"","sources":["../../../src/functions/conditional-provider.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,mBAAmB,CAAC,EAClC,OAAO,EACP,OAAO,GACiB;IACxB,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAA;IAC9C,
|
|
1
|
+
{"version":3,"file":"conditional-provider.js","sourceRoot":"","sources":["../../../src/functions/conditional-provider.ts"],"names":[],"mappings":"AAOA,MAAM,UAAU,mBAAmB,CAAC,EAClC,OAAO,EACP,OAAO,GACiB;IACxB,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAA;IAC9C,OAAO,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,KAAK,QAAQ,CAAC,IAAI,SAAS,CAAA;AACjE,CAAC"}
|
|
@@ -3,8 +3,14 @@ type ConditionalQueueStatusArgs = {
|
|
|
3
3
|
request: ActionRequest;
|
|
4
4
|
queue_id: string;
|
|
5
5
|
queue_name: string;
|
|
6
|
+
check_available_agents: boolean;
|
|
6
7
|
};
|
|
7
|
-
|
|
8
|
+
declare enum QueueStatusResult {
|
|
9
|
+
OPEN = "open",
|
|
10
|
+
CLOSED = "closed",
|
|
11
|
+
OPEN_WITHOUT_AGENTS = "open-without-agents"
|
|
12
|
+
}
|
|
13
|
+
export declare function conditionalQueueStatus({ queue_id, check_available_agents, }: ConditionalQueueStatusArgs): Promise<QueueStatusResult>;
|
|
8
14
|
interface AvailabilityData {
|
|
9
15
|
available: boolean;
|
|
10
16
|
waiting_cases: number;
|
|
@@ -13,5 +19,5 @@ interface AvailabilityData {
|
|
|
13
19
|
name: string;
|
|
14
20
|
available_agents: number;
|
|
15
21
|
}
|
|
16
|
-
export declare function getQueueAvailability(queueId: string): Promise<AvailabilityData>;
|
|
22
|
+
export declare function getQueueAvailability(queueId: string, checkAvailableAgents?: boolean): Promise<AvailabilityData>;
|
|
17
23
|
export {};
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import { __awaiter } from "tslib";
|
|
2
2
|
import axios from 'axios';
|
|
3
3
|
const HUBTYPE_API_URL = process.env.HUBTYPE_API_URL || 'https://api.hubtype.com';
|
|
4
|
-
|
|
4
|
+
var QueueStatusResult;
|
|
5
|
+
(function (QueueStatusResult) {
|
|
6
|
+
QueueStatusResult["OPEN"] = "open";
|
|
7
|
+
QueueStatusResult["CLOSED"] = "closed";
|
|
8
|
+
QueueStatusResult["OPEN_WITHOUT_AGENTS"] = "open-without-agents";
|
|
9
|
+
})(QueueStatusResult || (QueueStatusResult = {}));
|
|
10
|
+
export function conditionalQueueStatus({ queue_id, check_available_agents, }) {
|
|
5
11
|
return __awaiter(this, void 0, void 0, function* () {
|
|
6
|
-
const data = yield getQueueAvailability(queue_id);
|
|
7
|
-
|
|
8
|
-
|
|
12
|
+
const data = yield getQueueAvailability(queue_id, check_available_agents);
|
|
13
|
+
if (check_available_agents && data.open && data.available_agents === 0) {
|
|
14
|
+
return QueueStatusResult.OPEN_WITHOUT_AGENTS;
|
|
15
|
+
}
|
|
16
|
+
return data.open ? QueueStatusResult.OPEN : QueueStatusResult.CLOSED;
|
|
9
17
|
});
|
|
10
18
|
}
|
|
11
|
-
export function getQueueAvailability(queueId) {
|
|
19
|
+
export function getQueueAvailability(queueId, checkAvailableAgents = false) {
|
|
12
20
|
return __awaiter(this, void 0, void 0, function* () {
|
|
13
21
|
const response = yield axios.get(`${HUBTYPE_API_URL}/public/v1/queues/${queueId}/availability/`,
|
|
14
22
|
// TODO: Make it configurable in the future
|
|
@@ -16,7 +24,7 @@ export function getQueueAvailability(queueId) {
|
|
|
16
24
|
params: {
|
|
17
25
|
check_queue_schedule: true,
|
|
18
26
|
check_waiting_cases: false,
|
|
19
|
-
check_available_agents:
|
|
27
|
+
check_available_agents: checkAvailableAgents,
|
|
20
28
|
},
|
|
21
29
|
});
|
|
22
30
|
return response.data;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conditional-queue-status.js","sourceRoot":"","sources":["../../../src/functions/conditional-queue-status.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,yBAAyB,CAAA;
|
|
1
|
+
{"version":3,"file":"conditional-queue-status.js","sourceRoot":"","sources":["../../../src/functions/conditional-queue-status.ts"],"names":[],"mappings":";AACA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,MAAM,eAAe,GAAG,OAAO,CAAC,GAAG,CAAC,eAAe,IAAI,yBAAyB,CAAA;AAShF,IAAK,iBAIJ;AAJD,WAAK,iBAAiB;IACpB,kCAAa,CAAA;IACb,sCAAiB,CAAA;IACjB,gEAA2C,CAAA;AAC7C,CAAC,EAJI,iBAAiB,KAAjB,iBAAiB,QAIrB;AAED,MAAM,UAAgB,sBAAsB,CAAC,EAC3C,QAAQ,EACR,sBAAsB,GACK;;QAC3B,MAAM,IAAI,GAAG,MAAM,oBAAoB,CAAC,QAAQ,EAAE,sBAAsB,CAAC,CAAA;QACzE,IAAI,sBAAsB,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,gBAAgB,KAAK,CAAC,EAAE;YACtE,OAAO,iBAAiB,CAAC,mBAAmB,CAAA;SAC7C;QACD,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC,MAAM,CAAA;IACtE,CAAC;CAAA;AAWD,MAAM,UAAgB,oBAAoB,CACxC,OAAe,EACf,oBAAoB,GAAG,KAAK;;QAE5B,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAC9B,GAAG,eAAe,qBAAqB,OAAO,gBAAgB;QAC9D,2CAA2C;QAC3C;YACE,MAAM,EAAE;gBACN,oBAAoB,EAAE,IAAI;gBAC1B,mBAAmB,EAAE,KAAK;gBAC1B,sBAAsB,EAAE,oBAAoB;aAC7C;SACF,CACF,CAAA;QACD,OAAO,QAAQ,CAAC,IAAI,CAAA;IACtB,CAAC;CAAA"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import { conditionalBotVariable } from './conditional-bot-variable';
|
|
2
|
+
import { conditionalCountry } from './conditional-country';
|
|
1
3
|
import { conditionalProvider } from './conditional-provider';
|
|
2
4
|
import { conditionalQueueStatus } from './conditional-queue-status';
|
|
3
5
|
export declare const DEFAULT_FUNCTIONS: {
|
|
4
6
|
'check-queue-status': typeof conditionalQueueStatus;
|
|
5
7
|
'get-channel-type': typeof conditionalProvider;
|
|
8
|
+
'check-country': typeof conditionalCountry;
|
|
9
|
+
'check-bot-variable': typeof conditionalBotVariable;
|
|
6
10
|
};
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import { conditionalBotVariable } from './conditional-bot-variable';
|
|
2
|
+
import { conditionalCountry } from './conditional-country';
|
|
1
3
|
import { conditionalProvider } from './conditional-provider';
|
|
2
4
|
import { conditionalQueueStatus } from './conditional-queue-status';
|
|
3
5
|
export const DEFAULT_FUNCTIONS = {
|
|
4
6
|
// TODO: Rename api action name
|
|
5
7
|
'check-queue-status': conditionalQueueStatus,
|
|
6
8
|
'get-channel-type': conditionalProvider,
|
|
9
|
+
'check-country': conditionalCountry,
|
|
10
|
+
'check-bot-variable': conditionalBotVariable,
|
|
7
11
|
};
|
|
8
12
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/functions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AAEnE,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,+BAA+B;IAC/B,oBAAoB,EAAE,sBAAsB;IAC5C,kBAAkB,EAAE,mBAAmB;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/functions/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAA;AAEnE,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,+BAA+B;IAC/B,oBAAoB,EAAE,sBAAsB;IAC5C,kBAAkB,EAAE,mBAAmB;IACvC,eAAe,EAAE,kBAAkB;IACnC,oBAAoB,EAAE,sBAAsB;CAC7C,CAAA"}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { Plugin, PluginPreRequest, Session } from '@botonic/core';
|
|
|
2
2
|
import { ActionRequest } from '@botonic/react';
|
|
3
3
|
import { FlowBuilderApi } from './api';
|
|
4
4
|
import { FlowContent } from './content-fields';
|
|
5
|
-
import {
|
|
5
|
+
import { HtNodeWithContent } from './content-fields/hubtype-fields';
|
|
6
6
|
import { BotonicPluginFlowBuilderOptions, KnowledgeBaseResponse, PayloadParamsBase } from './types';
|
|
7
7
|
export default class BotonicPluginFlowBuilder implements Plugin {
|
|
8
8
|
readonly options: BotonicPluginFlowBuilderOptions;
|
|
@@ -22,7 +22,8 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
22
22
|
getStartContents(locale: string): Promise<FlowContent[]>;
|
|
23
23
|
getContentsByNode(node: HtNodeWithContent, locale: string, prevContents?: FlowContent[]): Promise<FlowContent[]>;
|
|
24
24
|
private getFlowContent;
|
|
25
|
-
callFunction
|
|
25
|
+
private callFunction;
|
|
26
|
+
private getArgumentsByLocale;
|
|
26
27
|
getPayloadParams<T extends PayloadParamsBase>(payload: string): T;
|
|
27
28
|
}
|
|
28
29
|
export * from './action';
|
package/lib/esm/index.js
CHANGED
|
@@ -32,7 +32,9 @@ export default class BotonicPluginFlowBuilder {
|
|
|
32
32
|
!request.input.payload &&
|
|
33
33
|
!request.session.is_first_interaction;
|
|
34
34
|
if (checkUserTextInput) {
|
|
35
|
-
const
|
|
35
|
+
const locale = this.getLocale(request.session);
|
|
36
|
+
const resolvedLocale = this.cmsApi.getResolvedLocale(locale);
|
|
37
|
+
const nodeByUserInput = yield getNodeByUserInput(this.cmsApi, resolvedLocale, request);
|
|
36
38
|
request.input.payload = this.cmsApi.getPayload(nodeByUserInput === null || nodeByUserInput === void 0 ? void 0 : nodeByUserInput.target);
|
|
37
39
|
}
|
|
38
40
|
if (request.input.payload) {
|
|
@@ -61,17 +63,18 @@ export default class BotonicPluginFlowBuilder {
|
|
|
61
63
|
getContentsByNode(node, locale, prevContents) {
|
|
62
64
|
return __awaiter(this, void 0, void 0, function* () {
|
|
63
65
|
const contents = prevContents || [];
|
|
64
|
-
const
|
|
66
|
+
const resolvedLocale = this.cmsApi.getResolvedLocale(locale);
|
|
65
67
|
if (node.type === HtNodeWithContentType.FUNCTION) {
|
|
66
|
-
const targetId = yield this.callFunction(node,
|
|
67
|
-
return this.getContentsById(targetId,
|
|
68
|
+
const targetId = yield this.callFunction(node, resolvedLocale);
|
|
69
|
+
return this.getContentsById(targetId, resolvedLocale, contents);
|
|
68
70
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
const content = this.getFlowContent(node, resolvedLocale);
|
|
72
|
+
if (content) {
|
|
73
|
+
contents.push(content);
|
|
74
|
+
}
|
|
75
|
+
// TODO: prevent infinite recursive calls
|
|
76
|
+
if (node.follow_up) {
|
|
77
|
+
return this.getContentsById(node.follow_up.id, resolvedLocale, contents);
|
|
75
78
|
}
|
|
76
79
|
return contents;
|
|
77
80
|
});
|
|
@@ -87,7 +90,7 @@ export default class BotonicPluginFlowBuilder {
|
|
|
87
90
|
case HtNodeWithContentType.VIDEO:
|
|
88
91
|
return FlowVideo.fromHubtypeCMS(hubtypeContent, locale);
|
|
89
92
|
case HtNodeWithContentType.WHATSAPP_BUTTON_LIST:
|
|
90
|
-
return FlowWhatsappButtonList.fromHubtypeCMS(hubtypeContent, locale);
|
|
93
|
+
return FlowWhatsappButtonList.fromHubtypeCMS(hubtypeContent, locale, this.cmsApi);
|
|
91
94
|
case HtNodeWithContentType.HANDOFF:
|
|
92
95
|
return FlowHandoff.fromHubtypeCMS(hubtypeContent, locale, this.cmsApi);
|
|
93
96
|
default:
|
|
@@ -95,11 +98,12 @@ export default class BotonicPluginFlowBuilder {
|
|
|
95
98
|
}
|
|
96
99
|
}
|
|
97
100
|
callFunction(functionNode, locale) {
|
|
98
|
-
var _a;
|
|
99
101
|
return __awaiter(this, void 0, void 0, function* () {
|
|
100
102
|
const functionNodeId = functionNode.id;
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
+
const functionArguments = this.getArgumentsByLocale(functionNode.content.arguments, locale);
|
|
104
|
+
const nameValues = functionArguments.map(arg => {
|
|
105
|
+
return { [arg.name]: arg.value };
|
|
106
|
+
});
|
|
103
107
|
const args = Object.assign({
|
|
104
108
|
request: this.currentRequest,
|
|
105
109
|
results: functionNode.content.result_mapping.map(r => r.result),
|
|
@@ -113,6 +117,18 @@ export default class BotonicPluginFlowBuilder {
|
|
|
113
117
|
return result.target.id;
|
|
114
118
|
});
|
|
115
119
|
}
|
|
120
|
+
getArgumentsByLocale(args, locale) {
|
|
121
|
+
let resultArguments = [];
|
|
122
|
+
for (const arg of args) {
|
|
123
|
+
if ('locale' in arg && arg.locale === locale) {
|
|
124
|
+
resultArguments = [...resultArguments, ...arg.values];
|
|
125
|
+
}
|
|
126
|
+
if ('type' in arg) {
|
|
127
|
+
resultArguments = [...resultArguments, arg];
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return resultArguments;
|
|
131
|
+
}
|
|
116
132
|
getPayloadParams(payload) {
|
|
117
133
|
const payloadParams = JSON.parse(payload.split(SEPARATOR)[1] || '{}');
|
|
118
134
|
return payloadParams;
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAA;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AACtC,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAA;AAC9D,OAAO,EACL,YAAY,EAEZ,WAAW,EACX,SAAS,EACT,QAAQ,EACR,SAAS,EACT,sBAAsB,G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,aAAa,CAAA;IACtB,CAAC;CACF;AAED,cAAc,UAAU,CAAA;AACxB,cAAc,kBAAkB,CAAA"}
|
package/lib/esm/utils.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { Session } from '@botonic/core';
|
|
2
|
+
import { ActionRequest } from '@botonic/react';
|
|
2
3
|
import { BotonicPluginFlowBuilderOptions } from './types';
|
|
3
4
|
export declare function resolveGetAccessToken(options: BotonicPluginFlowBuilderOptions): (session: Session) => string;
|
|
5
|
+
export declare function getValueFromKeyPath(request: ActionRequest, keyPath: string): any;
|
package/lib/esm/utils.js
CHANGED
|
@@ -15,4 +15,20 @@ export function resolveGetAccessToken(options) {
|
|
|
15
15
|
throw new Error('No method defined for getting access token');
|
|
16
16
|
}
|
|
17
17
|
}
|
|
18
|
+
export function getValueFromKeyPath(request, keyPath) {
|
|
19
|
+
if (keyPath.startsWith('input') || keyPath.startsWith('session')) {
|
|
20
|
+
return keyPath
|
|
21
|
+
.split('.')
|
|
22
|
+
.reduce((object, key) => resolveObjectKey(object, key), request);
|
|
23
|
+
}
|
|
24
|
+
return keyPath
|
|
25
|
+
.split('.')
|
|
26
|
+
.reduce((object, key) => resolveObjectKey(object, key), request.session.user.extra_data);
|
|
27
|
+
}
|
|
28
|
+
function resolveObjectKey(object, key) {
|
|
29
|
+
if (object && object[key] !== undefined) {
|
|
30
|
+
return object[key];
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
18
34
|
//# sourceMappingURL=utils.js.map
|
package/lib/esm/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAGA,OAAO,EAAmC,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAE7E,SAAS,yBAAyB,CAAC,OAAgB;IACjD,I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": "@botonic/plugin-flow-builder",
|
|
3
|
-
"version": "0.25.0-
|
|
3
|
+
"version": "0.25.0-beta.0",
|
|
4
4
|
"main": "./lib/cjs/index.js",
|
|
5
5
|
"module": "./lib/esm/index.js",
|
|
6
6
|
"description": "Use Flow Builder to show your contents",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "rm -rf lib && ../../node_modules/.bin/tsc -p tsconfig.json && ../../node_modules/.bin/tsc -p tsconfig.esm.json",
|
|
9
9
|
"build:watch": "npm run build -- --watch",
|
|
10
|
-
"test": "echo
|
|
10
|
+
"test": "echo Skipping tests...",
|
|
11
11
|
"cloc": "../../scripts/qa/cloc-package.sh .",
|
|
12
|
-
"prepare": "node ../../preinstall.js",
|
|
13
12
|
"prepublishOnly": "rm -rf lib && npm i && npm run build",
|
|
14
13
|
"lint": "npm run lint_core -- --fix",
|
|
15
|
-
"lint_ci": "npm run lint_core -- -c ../.eslintrc_slow.js",
|
|
16
14
|
"lint_core": "../../node_modules/.bin/eslint_d --cache --quiet 'src/**/*.ts*'"
|
|
17
15
|
},
|
|
18
16
|
"dependencies": {
|
|
19
|
-
"@botonic/react": "0.25.0-
|
|
20
|
-
"axios": "^1.6.
|
|
17
|
+
"@botonic/react": "0.25.0-beta.0",
|
|
18
|
+
"axios": "^1.6.8",
|
|
21
19
|
"uuid": "^9.0.1"
|
|
22
20
|
},
|
|
23
21
|
"repository": {
|
package/src/action/index.tsx
CHANGED
|
@@ -38,16 +38,18 @@ export class FlowBuilderAction extends React.Component<FlowBuilderActionProps> {
|
|
|
38
38
|
|
|
39
39
|
render(): JSX.Element | JSX.Element[] {
|
|
40
40
|
const { contents } = this.props
|
|
41
|
-
|
|
41
|
+
const request = this.context
|
|
42
|
+
return contents.map(content => content.toBotonic(content.id, request))
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
export class FlowBuilderMultichannelAction extends FlowBuilderAction {
|
|
46
47
|
render(): JSX.Element | JSX.Element[] {
|
|
47
48
|
const { contents } = this.props
|
|
49
|
+
const request = this.context
|
|
48
50
|
return (
|
|
49
51
|
<Multichannel text={{ buttonsAsText: false }}>
|
|
50
|
-
{contents.map(content => content.toBotonic(content.id))}
|
|
52
|
+
{contents.map(content => content.toBotonic(content.id, request))}
|
|
51
53
|
</Multichannel>
|
|
52
54
|
)
|
|
53
55
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
1
2
|
import { ActionRequest } from '@botonic/react'
|
|
2
3
|
import { v4 as uuid } from 'uuid'
|
|
3
4
|
|
|
@@ -16,6 +17,7 @@ export async function createNodeFromKnowledgeBase(
|
|
|
16
17
|
): Promise<HtNodeWithContent | undefined> {
|
|
17
18
|
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins)
|
|
18
19
|
const locale = flowBuilderPlugin.getLocale(request.session)
|
|
20
|
+
const resolvedLocale = cmsApi.getResolvedLocale(locale)
|
|
19
21
|
const knowledgeBaseConfig = cmsApi.getKnowledgeBaseConfig()
|
|
20
22
|
|
|
21
23
|
if (
|
|
@@ -25,7 +27,6 @@ export async function createNodeFromKnowledgeBase(
|
|
|
25
27
|
try {
|
|
26
28
|
const knowledgeBaseResponse =
|
|
27
29
|
await flowBuilderPlugin.getKnowledgeBaseResponse(request)
|
|
28
|
-
|
|
29
30
|
if (knowledgeBaseResponse.hasKnowledge) {
|
|
30
31
|
await trackEvent(request, EventName.botAiKnowledgeBase, {
|
|
31
32
|
answer: knowledgeBaseResponse.answer,
|
|
@@ -40,7 +41,7 @@ export async function createNodeFromKnowledgeBase(
|
|
|
40
41
|
text: [
|
|
41
42
|
{
|
|
42
43
|
message: knowledgeBaseResponse.answer,
|
|
43
|
-
locale,
|
|
44
|
+
locale: resolvedLocale,
|
|
44
45
|
},
|
|
45
46
|
],
|
|
46
47
|
buttons_style: undefined,
|
package/src/api.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Input, PluginPreRequest } from '@botonic/core'
|
|
2
2
|
import axios from 'axios'
|
|
3
3
|
|
|
4
|
-
import { SEPARATOR } from './constants'
|
|
4
|
+
import { REG_EXP_PATTERN, SEPARATOR } from './constants'
|
|
5
5
|
import {
|
|
6
6
|
HtBotActionNode,
|
|
7
7
|
HtFallbackNode,
|
|
@@ -169,13 +169,30 @@ export class FlowBuilderApi {
|
|
|
169
169
|
locale: string
|
|
170
170
|
): boolean {
|
|
171
171
|
const result = node.content.keywords.find(
|
|
172
|
-
|
|
172
|
+
keywords =>
|
|
173
|
+
keywords.locale === locale &&
|
|
174
|
+
this.inputMatchesAnyKeyword(input, keywords.values)
|
|
173
175
|
)
|
|
174
176
|
return Boolean(result)
|
|
175
177
|
}
|
|
176
178
|
|
|
177
|
-
private
|
|
178
|
-
return keywords.some(keyword =>
|
|
179
|
+
private inputMatchesAnyKeyword(input: string, keywords: string[]): boolean {
|
|
180
|
+
return keywords.some(keyword => {
|
|
181
|
+
const regExpMatchArray = keyword.match(REG_EXP_PATTERN)
|
|
182
|
+
if (regExpMatchArray) {
|
|
183
|
+
return this.resolveKeywordAsRegExp(regExpMatchArray, input)
|
|
184
|
+
}
|
|
185
|
+
return input.includes(keyword)
|
|
186
|
+
})
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
private resolveKeywordAsRegExp(
|
|
190
|
+
regExpMatchArray: RegExpMatchArray,
|
|
191
|
+
input: string
|
|
192
|
+
) {
|
|
193
|
+
const [, pattern, flags] = regExpMatchArray
|
|
194
|
+
const keywordAsRegExp = new RegExp(pattern, flags)
|
|
195
|
+
return input.match(keywordAsRegExp)
|
|
179
196
|
}
|
|
180
197
|
|
|
181
198
|
getPayload(target?: HtNodeLink): string | undefined {
|
|
@@ -203,4 +220,18 @@ export class FlowBuilderApi {
|
|
|
203
220
|
})
|
|
204
221
|
return `${payloadNode.content.payload}${SEPARATOR}${payloadJson}`
|
|
205
222
|
}
|
|
223
|
+
|
|
224
|
+
getResolvedLocale(locale: string): string {
|
|
225
|
+
if (this.flow.locales.find(flowLocale => flowLocale === locale)) {
|
|
226
|
+
return locale
|
|
227
|
+
}
|
|
228
|
+
const language = locale.split('-')[0]
|
|
229
|
+
if (this.flow.locales.find(flowLocale => flowLocale === language)) {
|
|
230
|
+
console.log(`locale: ${locale} has been resolved as ${language}`)
|
|
231
|
+
return language
|
|
232
|
+
}
|
|
233
|
+
throw new Error(
|
|
234
|
+
`locale: ${locale} cannot be resolved in ${this.flow.locales}`
|
|
235
|
+
)
|
|
236
|
+
}
|
|
206
237
|
}
|
package/src/constants.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export const SEPARATOR = '|'
|
|
2
2
|
export const SOURCE_INFO_SEPARATOR = `${SEPARATOR}source_`
|
|
3
|
-
export const
|
|
3
|
+
export const VARIABLE_PATTERN = /{([^}]+)}/g
|
|
4
|
+
export const ACCESS_TOKEN_VARIABLE_KEY = '_access_token'
|
|
5
|
+
export const REG_EXP_PATTERN = /^\/(.*)\/([gimyus]*)$/
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Text } from '@botonic/react'
|
|
1
|
+
import { ActionRequest, Text } from '@botonic/react'
|
|
2
2
|
import React from 'react'
|
|
3
3
|
|
|
4
4
|
import { FlowBuilderApi } from '../api'
|
|
5
|
-
import {
|
|
5
|
+
import { ACCESS_TOKEN_VARIABLE_KEY, VARIABLE_PATTERN } from '../constants'
|
|
6
|
+
import { getValueFromKeyPath } from '../utils'
|
|
6
7
|
import { ContentFieldsBase } from './content-fields-base'
|
|
7
8
|
import { FlowButton } from './flow-button'
|
|
8
9
|
import { HtButtonStyle, HtTextNode } from './hubtype-fields'
|
|
@@ -21,38 +22,43 @@ export class FlowText extends ContentFieldsBase {
|
|
|
21
22
|
const newText = new FlowText(cmsText.id)
|
|
22
23
|
newText.code = cmsText.code
|
|
23
24
|
newText.buttonStyle = cmsText.content.buttons_style || HtButtonStyle.BUTTON
|
|
24
|
-
newText.text = this.
|
|
25
|
-
this.getTextByLocale(locale, cmsText.content.text),
|
|
26
|
-
cmsApi.request.session.user.extra_data
|
|
27
|
-
)
|
|
25
|
+
newText.text = this.getTextByLocale(locale, cmsText.content.text)
|
|
28
26
|
newText.buttons = cmsText.content.buttons.map(button =>
|
|
29
27
|
FlowButton.fromHubtypeCMS(button, locale, cmsApi)
|
|
30
28
|
)
|
|
31
29
|
return newText
|
|
32
30
|
}
|
|
33
31
|
|
|
34
|
-
static replaceVariables(
|
|
35
|
-
text
|
|
36
|
-
extraData?: Record<string, any>
|
|
37
|
-
): string {
|
|
38
|
-
const matches = text.match(VARIABLE_REGEX)
|
|
32
|
+
static replaceVariables(text: string, request: ActionRequest): string {
|
|
33
|
+
const matches = text.match(VARIABLE_PATTERN)
|
|
39
34
|
|
|
40
35
|
let replacedText = text
|
|
41
|
-
if (matches &&
|
|
36
|
+
if (matches && request) {
|
|
42
37
|
matches.forEach(match => {
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
|
|
38
|
+
const keyPath = match.slice(1, -1)
|
|
39
|
+
const botVariable = keyPath.endsWith(ACCESS_TOKEN_VARIABLE_KEY)
|
|
40
|
+
? match
|
|
41
|
+
: getValueFromKeyPath(request, keyPath)
|
|
42
|
+
replacedText = replacedText.replace(
|
|
43
|
+
match,
|
|
44
|
+
this.isValidType(botVariable) ? botVariable : match
|
|
45
|
+
)
|
|
46
46
|
})
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
return replacedText
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
private static isValidType(botVariable: any): boolean {
|
|
53
|
+
const validTypes = ['boolean', 'string', 'number']
|
|
54
|
+
return validTypes.includes(typeof botVariable)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
toBotonic(id: string, request: ActionRequest): JSX.Element {
|
|
58
|
+
const replacedText = FlowText.replaceVariables(this.text, request)
|
|
53
59
|
return (
|
|
54
60
|
<Text key={id}>
|
|
55
|
-
{
|
|
61
|
+
{replacedText}
|
|
56
62
|
{this.buttons.map((button, buttonIndex) =>
|
|
57
63
|
button.renderButton(buttonIndex, this.buttonStyle)
|
|
58
64
|
)}
|
|
@@ -2,6 +2,7 @@ import { HtBaseNode, HtNodeLink } from './common'
|
|
|
2
2
|
import { HtNodeWithContentType } from './node-types'
|
|
3
3
|
|
|
4
4
|
export enum HtArgumentType {
|
|
5
|
+
BOOLEAN = 'boolean',
|
|
5
6
|
NUMBER = 'number',
|
|
6
7
|
STRING = 'string',
|
|
7
8
|
JSON = 'json',
|
|
@@ -23,11 +24,13 @@ export interface HtFunctionResult {
|
|
|
23
24
|
target?: HtNodeLink
|
|
24
25
|
}
|
|
25
26
|
|
|
27
|
+
export type HtFunctionArguments = HtFunctionArgumentLocale | HtFunctionArgument
|
|
28
|
+
|
|
26
29
|
export interface HtFunctionNode extends HtBaseNode {
|
|
27
30
|
type: HtNodeWithContentType.FUNCTION
|
|
28
31
|
content: {
|
|
29
32
|
action: string
|
|
30
|
-
arguments:
|
|
33
|
+
arguments: HtFunctionArguments[]
|
|
31
34
|
result_mapping: HtFunctionResult[]
|
|
32
35
|
}
|
|
33
36
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { WhatsappButtonListRowProps } from '@botonic/react'
|
|
2
2
|
|
|
3
|
+
import { FlowBuilderApi } from '../../api'
|
|
3
4
|
import { SOURCE_INFO_SEPARATOR } from '../../constants'
|
|
4
5
|
import { ContentFieldsBase } from '../content-fields-base'
|
|
5
6
|
import { HtWhatsappButtonListRow } from '../hubtype-fields'
|
|
@@ -11,12 +12,13 @@ export class FlowWhatsappButtonListRow extends ContentFieldsBase {
|
|
|
11
12
|
|
|
12
13
|
static fromHubtypeCMS(
|
|
13
14
|
component: HtWhatsappButtonListRow,
|
|
14
|
-
locale: string
|
|
15
|
+
locale: string,
|
|
16
|
+
cmsApi: FlowBuilderApi
|
|
15
17
|
): FlowWhatsappButtonListRow {
|
|
16
18
|
const newRow = new FlowWhatsappButtonListRow(component.id)
|
|
17
19
|
newRow.title = this.getTextByLocale(locale, component.text)
|
|
18
20
|
newRow.description = this.getTextByLocale(locale, component.description)
|
|
19
|
-
newRow.targetId = component.target
|
|
21
|
+
newRow.targetId = cmsApi.getPayload(component.target)
|
|
20
22
|
return newRow
|
|
21
23
|
}
|
|
22
24
|
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
WhatsappButtonListSectionProps,
|
|
4
4
|
} from '@botonic/react'
|
|
5
5
|
|
|
6
|
+
import { FlowBuilderApi } from '../../api'
|
|
6
7
|
import { HtWhatsappButtonListSection } from '../hubtype-fields'
|
|
7
8
|
import { ContentFieldsBase } from './../content-fields-base'
|
|
8
9
|
import { FlowWhatsappButtonListRow } from './flow-whatsapp-button-list-row'
|
|
@@ -13,12 +14,13 @@ export class FlowWhatsappButtonListSection extends ContentFieldsBase {
|
|
|
13
14
|
|
|
14
15
|
static fromHubtypeCMS(
|
|
15
16
|
component: HtWhatsappButtonListSection,
|
|
16
|
-
locale: string
|
|
17
|
+
locale: string,
|
|
18
|
+
cmsApi: FlowBuilderApi
|
|
17
19
|
): FlowWhatsappButtonListSection {
|
|
18
20
|
const newButton = new FlowWhatsappButtonListSection(component.id)
|
|
19
21
|
newButton.title = this.getTextByLocale(locale, component.title)
|
|
20
22
|
newButton.rows = component.rows.map(row =>
|
|
21
|
-
FlowWhatsappButtonListRow.fromHubtypeCMS(row, locale)
|
|
23
|
+
FlowWhatsappButtonListRow.fromHubtypeCMS(row, locale, cmsApi)
|
|
22
24
|
)
|
|
23
25
|
return newButton
|
|
24
26
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { WhatsappButtonList } from '@botonic/react'
|
|
2
2
|
import React from 'react'
|
|
3
3
|
|
|
4
|
+
import { FlowBuilderApi } from '../../api'
|
|
4
5
|
import { HtWhatsappButtonListNode } from '../hubtype-fields'
|
|
5
6
|
import { ContentFieldsBase } from './../content-fields-base'
|
|
6
7
|
import { FlowWhatsappButtonListSection } from './flow-whatsapp-button-list-section'
|
|
@@ -13,7 +14,8 @@ export class FlowWhatsappButtonList extends ContentFieldsBase {
|
|
|
13
14
|
|
|
14
15
|
static fromHubtypeCMS(
|
|
15
16
|
component: HtWhatsappButtonListNode,
|
|
16
|
-
locale: string
|
|
17
|
+
locale: string,
|
|
18
|
+
cmsApi: FlowBuilderApi
|
|
17
19
|
): FlowWhatsappButtonList {
|
|
18
20
|
const newWhatsappButtonList = new FlowWhatsappButtonList(component.id)
|
|
19
21
|
newWhatsappButtonList.code = component.code
|
|
@@ -26,7 +28,7 @@ export class FlowWhatsappButtonList extends ContentFieldsBase {
|
|
|
26
28
|
component.content.button_text
|
|
27
29
|
)
|
|
28
30
|
newWhatsappButtonList.sections = component.content.sections.map(section =>
|
|
29
|
-
FlowWhatsappButtonListSection.fromHubtypeCMS(section, locale)
|
|
31
|
+
FlowWhatsappButtonListSection.fromHubtypeCMS(section, locale, cmsApi)
|
|
30
32
|
)
|
|
31
33
|
return newWhatsappButtonList
|
|
32
34
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ActionRequest } from '@botonic/react'
|
|
2
|
+
|
|
3
|
+
import { getValueFromKeyPath } from '../utils'
|
|
4
|
+
|
|
5
|
+
interface ConditionalCountryArgs {
|
|
6
|
+
request: ActionRequest
|
|
7
|
+
results: string[]
|
|
8
|
+
keyPath: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function conditionalBotVariable({
|
|
12
|
+
request,
|
|
13
|
+
results,
|
|
14
|
+
keyPath,
|
|
15
|
+
}: ConditionalCountryArgs): string {
|
|
16
|
+
const botVariable = getValueFromKeyPath(request, keyPath)
|
|
17
|
+
return results.find(result => result === botVariable) ?? 'default'
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ActionRequest } from '@botonic/react'
|
|
2
|
+
|
|
3
|
+
interface ConditionalCountryArgs {
|
|
4
|
+
request: ActionRequest
|
|
5
|
+
results: string[]
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function conditionalCountry({
|
|
9
|
+
request,
|
|
10
|
+
results,
|
|
11
|
+
}: ConditionalCountryArgs): string {
|
|
12
|
+
const country = request.session.user.extra_data.country
|
|
13
|
+
return results.find(result => result === country) || 'default'
|
|
14
|
+
}
|