@botonic/plugin-flow-builder 0.21.0-alpha.9 → 0.21.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/action.js +23 -32
- package/lib/cjs/action.js.map +1 -1
- package/lib/cjs/content-fields/content-fields-base.d.ts +3 -2
- package/lib/cjs/content-fields/content-fields-base.js +6 -1
- package/lib/cjs/content-fields/content-fields-base.js.map +1 -1
- package/lib/cjs/content-fields/flow-button.d.ts +1 -1
- package/lib/cjs/content-fields/flow-button.js +7 -5
- package/lib/cjs/content-fields/flow-button.js.map +1 -1
- package/lib/cjs/content-fields/flow-carousel.d.ts +1 -1
- package/lib/cjs/content-fields/flow-carousel.js +4 -5
- package/lib/cjs/content-fields/flow-carousel.js.map +1 -1
- package/lib/cjs/content-fields/flow-image.d.ts +1 -1
- package/lib/cjs/content-fields/flow-image.js +2 -2
- package/lib/cjs/content-fields/flow-image.js.map +1 -1
- package/lib/cjs/content-fields/flow-text.d.ts +1 -1
- package/lib/cjs/content-fields/flow-text.js +3 -3
- package/lib/cjs/content-fields/flow-text.js.map +1 -1
- package/lib/cjs/content-fields/flow-video.d.ts +8 -0
- package/lib/cjs/content-fields/flow-video.js +26 -0
- package/lib/cjs/content-fields/flow-video.js.map +1 -0
- package/lib/cjs/content-fields/index.d.ts +1 -0
- package/lib/cjs/content-fields/index.js +3 -1
- package/lib/cjs/content-fields/index.js.map +1 -1
- package/lib/cjs/content-fields/types.d.ts +2 -1
- package/lib/cjs/flow-builder-models.d.ts +26 -4
- package/lib/cjs/flow-builder-models.js +2 -0
- package/lib/cjs/flow-builder-models.js.map +1 -1
- package/lib/cjs/handoff.d.ts +2 -1
- package/lib/cjs/handoff.js +21 -14
- package/lib/cjs/handoff.js.map +1 -1
- package/lib/cjs/helpers.d.ts +6 -0
- package/lib/cjs/helpers.js +27 -0
- package/lib/cjs/helpers.js.map +1 -0
- package/lib/cjs/index.d.ts +10 -11
- package/lib/cjs/index.js +45 -42
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/types.d.ts +13 -0
- package/lib/cjs/types.js +9 -0
- package/lib/cjs/types.js.map +1 -0
- package/lib/cjs/utils.d.ts +3 -0
- package/lib/cjs/utils.js +19 -1
- package/lib/cjs/utils.js.map +1 -1
- package/lib/esm/action.js +24 -33
- package/lib/esm/action.js.map +1 -1
- package/lib/esm/content-fields/content-fields-base.d.ts +3 -2
- package/lib/esm/content-fields/content-fields-base.js +6 -1
- package/lib/esm/content-fields/content-fields-base.js.map +1 -1
- package/lib/esm/content-fields/flow-button.d.ts +1 -1
- package/lib/esm/content-fields/flow-button.js +7 -5
- package/lib/esm/content-fields/flow-button.js.map +1 -1
- package/lib/esm/content-fields/flow-carousel.d.ts +1 -1
- package/lib/esm/content-fields/flow-carousel.js +4 -5
- package/lib/esm/content-fields/flow-carousel.js.map +1 -1
- package/lib/esm/content-fields/flow-image.d.ts +1 -1
- package/lib/esm/content-fields/flow-image.js +2 -2
- package/lib/esm/content-fields/flow-image.js.map +1 -1
- package/lib/esm/content-fields/flow-text.d.ts +1 -1
- package/lib/esm/content-fields/flow-text.js +3 -3
- package/lib/esm/content-fields/flow-text.js.map +1 -1
- package/lib/esm/content-fields/flow-video.d.ts +8 -0
- package/lib/esm/content-fields/flow-video.js +21 -0
- package/lib/esm/content-fields/flow-video.js.map +1 -0
- package/lib/esm/content-fields/index.d.ts +1 -0
- package/lib/esm/content-fields/index.js +1 -0
- package/lib/esm/content-fields/index.js.map +1 -1
- package/lib/esm/content-fields/types.d.ts +2 -1
- package/lib/esm/flow-builder-models.d.ts +26 -4
- package/lib/esm/flow-builder-models.js +2 -0
- package/lib/esm/flow-builder-models.js.map +1 -1
- package/lib/esm/handoff.d.ts +2 -1
- package/lib/esm/handoff.js +21 -14
- package/lib/esm/handoff.js.map +1 -1
- package/lib/esm/helpers.d.ts +6 -0
- package/lib/esm/helpers.js +22 -0
- package/lib/esm/helpers.js.map +1 -0
- package/lib/esm/index.d.ts +10 -11
- package/lib/esm/index.js +46 -43
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/types.d.ts +13 -0
- package/lib/esm/types.js +6 -0
- package/lib/esm/types.js.map +1 -0
- package/lib/esm/utils.d.ts +3 -0
- package/lib/esm/utils.js +17 -0
- package/lib/esm/utils.js.map +1 -1
- package/package.json +3 -3
- package/src/action.tsx +29 -35
- package/src/content-fields/content-fields-base.ts +12 -3
- package/src/content-fields/flow-button.tsx +6 -4
- package/src/content-fields/flow-carousel.tsx +4 -5
- package/src/content-fields/flow-image.tsx +2 -2
- package/src/content-fields/flow-text.tsx +4 -4
- package/src/content-fields/flow-video.tsx +22 -0
- package/src/content-fields/index.ts +1 -0
- package/src/content-fields/types.ts +2 -1
- package/src/flow-builder-models.ts +30 -2
- package/src/handoff.ts +25 -16
- package/src/helpers.ts +39 -0
- package/src/index.ts +61 -61
- package/src/types.ts +16 -0
- package/src/utils.ts +24 -0
|
@@ -16,7 +16,9 @@ export declare enum NodeType {
|
|
|
16
16
|
START_UP = "start-up",
|
|
17
17
|
URL = "url",
|
|
18
18
|
PAYLOAD = "payload",
|
|
19
|
-
FUNCTION = "function"
|
|
19
|
+
FUNCTION = "function",
|
|
20
|
+
FALLBACK = "fallback",
|
|
21
|
+
VIDEO = "video"
|
|
20
22
|
}
|
|
21
23
|
export interface BaseNode {
|
|
22
24
|
id: string;
|
|
@@ -57,8 +59,8 @@ export interface Button {
|
|
|
57
59
|
text: TextLocale[];
|
|
58
60
|
target?: NodeLink;
|
|
59
61
|
hidden: string;
|
|
60
|
-
url?: UrlLocale;
|
|
61
|
-
payload?: PayloadLocale;
|
|
62
|
+
url?: UrlLocale[];
|
|
63
|
+
payload?: PayloadLocale[];
|
|
62
64
|
}
|
|
63
65
|
export interface TextNodeContent {
|
|
64
66
|
text: TextLocale[];
|
|
@@ -171,4 +173,24 @@ export interface FunctionNode extends Node {
|
|
|
171
173
|
type: NodeType.FUNCTION;
|
|
172
174
|
content: FunctionNodeContent;
|
|
173
175
|
}
|
|
174
|
-
export
|
|
176
|
+
export interface FallbackNodeContent {
|
|
177
|
+
first_message: NodeLink;
|
|
178
|
+
second_message: NodeLink;
|
|
179
|
+
}
|
|
180
|
+
export interface FallbackNode extends Node {
|
|
181
|
+
type: NodeType.FALLBACK;
|
|
182
|
+
content: FallbackNodeContent;
|
|
183
|
+
}
|
|
184
|
+
export interface VideoLocale {
|
|
185
|
+
url: string;
|
|
186
|
+
is_embedded?: boolean;
|
|
187
|
+
locale: string;
|
|
188
|
+
}
|
|
189
|
+
export interface VideoNodeContent {
|
|
190
|
+
video: VideoLocale[];
|
|
191
|
+
}
|
|
192
|
+
export interface VideoNode extends Node {
|
|
193
|
+
type: NodeType.VIDEO;
|
|
194
|
+
content: VideoNodeContent;
|
|
195
|
+
}
|
|
196
|
+
export type NodeComponent = TextNode | ImageNode | CarouselNode | HandoffNode | KeywordNode | IntentNode | UrlNode | StartNode | PayloadNode | FunctionNode | FallbackNode | VideoNode;
|
|
@@ -10,6 +10,8 @@ export var NodeType;
|
|
|
10
10
|
NodeType["URL"] = "url";
|
|
11
11
|
NodeType["PAYLOAD"] = "payload";
|
|
12
12
|
NodeType["FUNCTION"] = "function";
|
|
13
|
+
NodeType["FALLBACK"] = "fallback";
|
|
14
|
+
NodeType["VIDEO"] = "video";
|
|
13
15
|
})(NodeType || (NodeType = {}));
|
|
14
16
|
export var ButtonStyle;
|
|
15
17
|
(function (ButtonStyle) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow-builder-models.js","sourceRoot":"","sources":["../../src/flow-builder-models.ts"],"names":[],"mappings":"AASA,MAAM,CAAN,IAAY,
|
|
1
|
+
{"version":3,"file":"flow-builder-models.js","sourceRoot":"","sources":["../../src/flow-builder-models.ts"],"names":[],"mappings":"AASA,MAAM,CAAN,IAAY,QAaX;AAbD,WAAY,QAAQ;IAClB,yBAAa,CAAA;IACb,2BAAe,CAAA;IACf,iCAAqB,CAAA;IACrB,+BAAmB,CAAA;IACnB,+BAAmB,CAAA;IACnB,6BAAiB,CAAA;IACjB,iCAAqB,CAAA;IACrB,uBAAW,CAAA;IACX,+BAAmB,CAAA;IACnB,iCAAqB,CAAA;IACrB,iCAAqB,CAAA;IACrB,2BAAe,CAAA;AACjB,CAAC,EAbW,QAAQ,KAAR,QAAQ,QAanB;AA6BD,MAAM,CAAN,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,gCAAiB,CAAA;IACjB,0CAA2B,CAAA;AAC7B,CAAC,EAHW,WAAW,KAAX,WAAW,QAGtB"}
|
package/lib/esm/handoff.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { ActionRequest } from '@botonic/react';
|
|
2
|
-
|
|
2
|
+
import { HandoffNode } from './flow-builder-models';
|
|
3
|
+
export declare function doHandoff(request: ActionRequest, locale: string, handoffNode: HandoffNode): Promise<void>;
|
package/lib/esm/handoff.js
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
import { HandOffBuilder } from '@botonic/core';
|
|
2
|
-
|
|
2
|
+
import { getFlowBuilderPlugin } from './helpers';
|
|
3
|
+
export async function doHandoff(request, locale, handoffNode) {
|
|
3
4
|
var _a;
|
|
5
|
+
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins);
|
|
6
|
+
const handoffTargetNode = await flowBuilderPlugin.getHandoffContent((_a = handoffNode.target) === null || _a === void 0 ? void 0 : _a.id);
|
|
4
7
|
// @ts-ignore
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
//
|
|
17
|
-
|
|
8
|
+
const handOffBuilder = new HandOffBuilder(request.session); // handOffBuilder.withQueue(handoffNode.content.queue)
|
|
9
|
+
const handoffQueues = handoffNode.content.queue;
|
|
10
|
+
const queueFound = handoffQueues.find(q => q.locale === locale);
|
|
11
|
+
if (queueFound)
|
|
12
|
+
handOffBuilder.withQueue(queueFound.id);
|
|
13
|
+
// TODO: Retrieve params from FlowBuilder
|
|
14
|
+
// const handoffParams = {
|
|
15
|
+
// agentEmail: 'test@gmail.com',
|
|
16
|
+
// note: 'This is a note that will be attached to the case as a reminder',
|
|
17
|
+
// }
|
|
18
|
+
// if (handoffParams.note) {
|
|
19
|
+
// handOffBuilder.withNote(handoffParams.note)
|
|
20
|
+
// }
|
|
21
|
+
// if (handoffParams.agentEmail) {
|
|
22
|
+
// handOffBuilder.withAgentEmail(handoffParams.agentEmail)
|
|
23
|
+
// }
|
|
24
|
+
handOffBuilder.withOnFinishPayload(handoffTargetNode.id);
|
|
18
25
|
await handOffBuilder.handOff();
|
|
19
26
|
}
|
|
20
27
|
//# sourceMappingURL=handoff.js.map
|
package/lib/esm/handoff.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handoff.js","sourceRoot":"","sources":["../../src/handoff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"handoff.js","sourceRoot":"","sources":["../../src/handoff.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAI9C,OAAO,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAEhD,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,OAAsB,EACtB,MAAc,EACd,WAAwB;;IAExB,MAAM,iBAAiB,GAAG,oBAAoB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;IAC/D,MAAM,iBAAiB,GAAG,MAAM,iBAAiB,CAAC,iBAAiB,CACjE,MAAA,WAAW,CAAC,MAAM,0CAAE,EAAE,CACvB,CAAA;IACD,aAAa;IACb,MAAM,cAAc,GAAG,IAAI,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA,CAAC,sDAAsD;IACjH,MAAM,aAAa,GAAG,WAAW,CAAC,OAAO,CAAC,KAAK,CAAA;IAC/C,MAAM,UAAU,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,MAAM,CAAC,CAAA;IAC/D,IAAI,UAAU;QAAE,cAAc,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;IACvD,yCAAyC;IACzC,0BAA0B;IAC1B,kCAAkC;IAClC,4EAA4E;IAC5E,IAAI;IAEJ,4BAA4B;IAC5B,gDAAgD;IAChD,IAAI;IAEJ,kCAAkC;IAClC,4DAA4D;IAC5D,IAAI;IAEJ,cAAc,CAAC,mBAAmB,CAAC,iBAAiB,CAAC,EAAE,CAAC,CAAA;IACxD,MAAM,cAAc,CAAC,OAAO,EAAE,CAAA;AAChC,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Plugin } from '@botonic/core';
|
|
2
|
+
import BotonicPluginFlowBuilder from './index';
|
|
3
|
+
export declare function getFlowBuilderPlugin(plugins: {
|
|
4
|
+
[id: string]: Plugin;
|
|
5
|
+
}): BotonicPluginFlowBuilder;
|
|
6
|
+
export declare function updateButtonUrls(hubtypeContent: any, contentKey: string, getContentFn: any): Promise<void>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const FLOW_BUILDER_PLUGIN_NAME = 'BotonicPluginFlowBuilder';
|
|
2
|
+
export function getFlowBuilderPlugin(plugins) {
|
|
3
|
+
const flowBuilderPlugin = Object.values(plugins).find(
|
|
4
|
+
// @ts-ignore
|
|
5
|
+
plugin => plugin.name === FLOW_BUILDER_PLUGIN_NAME);
|
|
6
|
+
if (!flowBuilderPlugin)
|
|
7
|
+
throw new Error(`You must include '@botonic/plugin-flow-builder' in your plugins file.`);
|
|
8
|
+
return flowBuilderPlugin;
|
|
9
|
+
}
|
|
10
|
+
export async function updateButtonUrls(hubtypeContent, contentKey, getContentFn) {
|
|
11
|
+
if (hubtypeContent.content[contentKey]) {
|
|
12
|
+
for (const i in hubtypeContent.content[contentKey]) {
|
|
13
|
+
const button = hubtypeContent.content[contentKey][i].button;
|
|
14
|
+
if (button.url) {
|
|
15
|
+
for (const j in button.url) {
|
|
16
|
+
button.url[j] = Object.assign(Object.assign({}, button.url[j]), (await getContentFn(button.url[j].id)));
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/helpers.ts"],"names":[],"mappings":"AAIA,MAAM,wBAAwB,GAAG,0BAA0B,CAAA;AAE3D,MAAM,UAAU,oBAAoB,CAAC,OAEpC;IACC,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI;IACnD,aAAa;IACb,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,KAAK,wBAAwB,CACvB,CAAA;IAC7B,IAAI,CAAC,iBAAiB;QACpB,MAAM,IAAI,KAAK,CACb,uEAAuE,CACxE,CAAA;IACH,OAAO,iBAAiB,CAAA;AAC1B,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,cAAmB,EACnB,UAAkB,EAClB,YAAiB;IAEjB,IAAI,cAAc,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;QACtC,KAAK,MAAM,CAAC,IAAI,cAAc,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE;YAClD,MAAM,MAAM,GAAG,cAAc,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAA;YAC3D,IAAI,MAAM,CAAC,GAAG,EAAE;gBACd,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,GAAG,EAAE;oBAC1B,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,mCACR,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,GACb,CAAC,MAAM,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAC1C,CAAA;iBACF;aACF;SACF;KACF;AACH,CAAC"}
|
package/lib/esm/index.d.ts
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import { Input, Plugin, PluginPostRequest, PluginPreRequest, Session } from '@botonic/core';
|
|
2
2
|
import { FlowContent } from './content-fields';
|
|
3
3
|
import { FlowBuilderData, FunctionNode, HandoffNode, IntentNode, KeywordNode, NodeComponent } from './flow-builder-models';
|
|
4
|
-
|
|
5
|
-
flowUrl: string;
|
|
6
|
-
flow?: FlowBuilderData;
|
|
7
|
-
customFunctions?: Record<any, any>;
|
|
8
|
-
getLocale: (session: Session) => string;
|
|
9
|
-
getAccessToken: () => string;
|
|
10
|
-
};
|
|
4
|
+
import { BotonicPluginFlowBuilderOptions } from './types';
|
|
11
5
|
export default class BotonicPluginFlowBuilder implements Plugin {
|
|
12
6
|
readonly options: BotonicPluginFlowBuilderOptions;
|
|
13
7
|
private flowUrl;
|
|
@@ -17,16 +11,21 @@ export default class BotonicPluginFlowBuilder implements Plugin {
|
|
|
17
11
|
private getAccessToken;
|
|
18
12
|
getLocale: (session: Session) => string;
|
|
19
13
|
constructor(options: BotonicPluginFlowBuilderOptions);
|
|
20
|
-
readFlowContent(): Promise<FlowBuilderData>;
|
|
14
|
+
readFlowContent(session: Session): Promise<FlowBuilderData>;
|
|
21
15
|
pre(request: PluginPreRequest): Promise<void>;
|
|
22
16
|
post(_request: PluginPostRequest): Promise<void>;
|
|
23
17
|
getContent(id: string): Promise<NodeComponent>;
|
|
24
|
-
getHandoffContent(): Promise<HandoffNode>;
|
|
18
|
+
getHandoffContent(handoffTargetId: string | undefined): Promise<HandoffNode>;
|
|
25
19
|
getFlowContent(hubtypeContent: NodeComponent, locale: string): FlowContent | undefined;
|
|
26
20
|
getStartId(): Promise<string>;
|
|
27
|
-
|
|
28
|
-
|
|
21
|
+
getFallbackId(alternate: boolean): Promise<string>;
|
|
22
|
+
getContents(id: string, locale: string, prevContents?: FlowContent[]): Promise<{
|
|
23
|
+
contents: FlowContent[];
|
|
24
|
+
handoffNode: HandoffNode;
|
|
25
|
+
}>;
|
|
26
|
+
getPayloadByIntent(input: Input, locale: string): Promise<string | undefined>;
|
|
29
27
|
hasIntent(node: IntentNode, intent: string, locale: string): boolean;
|
|
28
|
+
hasMetConfidenceThreshold(node: IntentNode, predictedConfidence: number): boolean;
|
|
30
29
|
getPayloadByKeyword(input: Input, locale: string): Promise<string | undefined>;
|
|
31
30
|
matchKeywords(node: KeywordNode, input: string, locale: string): boolean;
|
|
32
31
|
containsAnyKeywords(input: string, keywords: string[]): boolean;
|
package/lib/esm/index.js
CHANGED
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
import axios from 'axios';
|
|
2
|
-
import { FlowCarousel, FlowImage, FlowText, } from './content-fields';
|
|
2
|
+
import { FlowCarousel, FlowImage, FlowText, FlowVideo, } from './content-fields';
|
|
3
3
|
import { NodeType, } from './flow-builder-models';
|
|
4
4
|
import { DEFAULT_FUNCTIONS } from './functions';
|
|
5
|
+
import { resolveGetAccessToken } from './utils';
|
|
6
|
+
import { updateButtonUrls } from './helpers';
|
|
5
7
|
export default class BotonicPluginFlowBuilder {
|
|
6
8
|
constructor(options) {
|
|
7
9
|
this.options = options;
|
|
8
10
|
this.getLocale = options.getLocale;
|
|
9
|
-
this.getAccessToken = options
|
|
11
|
+
this.getAccessToken = resolveGetAccessToken(options);
|
|
10
12
|
this.flowUrl = options.flowUrl;
|
|
11
|
-
|
|
13
|
+
if (options.flow)
|
|
14
|
+
this.flow = options.flow;
|
|
12
15
|
const customFunctions = options.customFunctions || {};
|
|
13
16
|
this.functions = Object.assign(Object.assign({}, DEFAULT_FUNCTIONS), customFunctions);
|
|
14
17
|
}
|
|
15
|
-
async readFlowContent() {
|
|
16
|
-
const
|
|
17
|
-
headers: { Authorization: `Bearer ${this.getAccessToken()}` },
|
|
18
|
+
async readFlowContent(session) {
|
|
19
|
+
const { data } = await axios.get(this.flowUrl, {
|
|
20
|
+
headers: { Authorization: `Bearer ${this.getAccessToken(session)}` },
|
|
18
21
|
});
|
|
19
|
-
return
|
|
22
|
+
return data;
|
|
20
23
|
}
|
|
21
24
|
async pre(request) {
|
|
22
25
|
this.currentRequest = request;
|
|
23
|
-
this.flow = this.readFlowContent();
|
|
26
|
+
this.flow = await this.readFlowContent(this.currentRequest.session);
|
|
24
27
|
}
|
|
25
28
|
async post(_request) { }
|
|
26
29
|
async getContent(id) {
|
|
@@ -30,9 +33,9 @@ export default class BotonicPluginFlowBuilder {
|
|
|
30
33
|
throw Error(`Node with id: '${id}' not found`);
|
|
31
34
|
return content;
|
|
32
35
|
}
|
|
33
|
-
async getHandoffContent() {
|
|
36
|
+
async getHandoffContent(handoffTargetId) {
|
|
34
37
|
const flow = await this.flow;
|
|
35
|
-
const content = flow.nodes.find(node => node.
|
|
38
|
+
const content = flow.nodes.find(node => node.id === handoffTargetId);
|
|
36
39
|
if (!content)
|
|
37
40
|
throw Error(`Handoff node not found`);
|
|
38
41
|
return content;
|
|
@@ -45,6 +48,8 @@ export default class BotonicPluginFlowBuilder {
|
|
|
45
48
|
return FlowImage.fromHubtypeCMS(hubtypeContent, locale);
|
|
46
49
|
case NodeType.CAROUSEL:
|
|
47
50
|
return FlowCarousel.fromHubtypeCMS(hubtypeContent, locale);
|
|
51
|
+
case NodeType.VIDEO:
|
|
52
|
+
return FlowVideo.fromHubtypeCMS(hubtypeContent, locale);
|
|
48
53
|
default:
|
|
49
54
|
return undefined;
|
|
50
55
|
}
|
|
@@ -52,34 +57,28 @@ export default class BotonicPluginFlowBuilder {
|
|
|
52
57
|
async getStartId() {
|
|
53
58
|
const flow = await this.flow;
|
|
54
59
|
const startNode = flow.nodes.find(node => node.type === NodeType.START_UP);
|
|
55
|
-
if (!startNode)
|
|
60
|
+
if (!startNode)
|
|
56
61
|
throw new Error('start-up id must be defined');
|
|
57
|
-
}
|
|
58
62
|
return startNode.target.id;
|
|
59
63
|
}
|
|
64
|
+
async getFallbackId(alternate) {
|
|
65
|
+
const flow = await this.flow;
|
|
66
|
+
const fallbackNode = flow.nodes.find(node => node.type === NodeType.FALLBACK);
|
|
67
|
+
if (!fallbackNode)
|
|
68
|
+
throw new Error('fallback node must be defined');
|
|
69
|
+
const fallbackFirstMessage = fallbackNode.content.first_message;
|
|
70
|
+
const fallbackSecondMessage = fallbackNode.content.second_message;
|
|
71
|
+
if (!fallbackSecondMessage)
|
|
72
|
+
return fallbackFirstMessage.id;
|
|
73
|
+
return alternate ? fallbackFirstMessage.id : fallbackSecondMessage.id;
|
|
74
|
+
}
|
|
60
75
|
async getContents(id, locale, prevContents) {
|
|
61
76
|
const contents = prevContents || [];
|
|
62
77
|
const hubtypeContent = await this.getContent(id);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
for (const j in button.url) {
|
|
68
|
-
button.url[j] = Object.assign(Object.assign({}, button.url[j]), (await this.getContent(button.url[j].id)));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
if (hubtypeContent.content.buttons) {
|
|
74
|
-
for (const i in hubtypeContent.content.buttons) {
|
|
75
|
-
const button = hubtypeContent.content.buttons[i];
|
|
76
|
-
if (button.url) {
|
|
77
|
-
for (const j in button.url) {
|
|
78
|
-
button.url[j] = Object.assign(Object.assign({}, button.url[j]), (await this.getContent(button.url[j].id)));
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
78
|
+
const isHandoff = hubtypeContent.type === NodeType.HANDOFF;
|
|
79
|
+
// TODO: Create function to populate these buttons
|
|
80
|
+
await updateButtonUrls(hubtypeContent, 'elements', this.getContent);
|
|
81
|
+
await updateButtonUrls(hubtypeContent, 'buttons', this.getContent);
|
|
83
82
|
const content = await this.getFlowContent(hubtypeContent, locale);
|
|
84
83
|
if (hubtypeContent.type === NodeType.FUNCTION) {
|
|
85
84
|
const targetId = await this.callFunction(hubtypeContent, locale);
|
|
@@ -94,20 +93,21 @@ export default class BotonicPluginFlowBuilder {
|
|
|
94
93
|
}
|
|
95
94
|
// execute function
|
|
96
95
|
// return this.getContents(function result_mapping target, locale, contents)
|
|
97
|
-
return contents;
|
|
96
|
+
return { contents, handoffNode: isHandoff && hubtypeContent };
|
|
98
97
|
}
|
|
99
|
-
async
|
|
98
|
+
async getPayloadByIntent(input, locale) {
|
|
100
99
|
var _a;
|
|
101
100
|
try {
|
|
102
101
|
const flow = await this.flow;
|
|
103
102
|
const intents = flow.nodes.filter(node => node.type === NodeType.INTENT);
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
103
|
+
const inputIntent = input.intent;
|
|
104
|
+
const inputConfidence = input.confidence;
|
|
105
|
+
if (inputIntent) {
|
|
106
|
+
const matchedIntentNode = intents.find(node => inputIntent &&
|
|
107
|
+
this.hasIntent(node, inputIntent, locale) &&
|
|
108
|
+
inputConfidence &&
|
|
109
|
+
this.hasMetConfidenceThreshold(node, inputConfidence));
|
|
110
|
+
return (_a = matchedIntentNode === null || matchedIntentNode === void 0 ? void 0 : matchedIntentNode.target) === null || _a === void 0 ? void 0 : _a.id;
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
catch (error) {
|
|
@@ -116,8 +116,11 @@ export default class BotonicPluginFlowBuilder {
|
|
|
116
116
|
return undefined;
|
|
117
117
|
}
|
|
118
118
|
hasIntent(node, intent, locale) {
|
|
119
|
-
|
|
120
|
-
|
|
119
|
+
return node.content.intents.some(i => i.locale === locale && i.values.includes(intent));
|
|
120
|
+
}
|
|
121
|
+
hasMetConfidenceThreshold(node, predictedConfidence) {
|
|
122
|
+
const nodeConfidence = node.content.confidence / 100;
|
|
123
|
+
return predictedConfidence >= nodeConfidence;
|
|
121
124
|
}
|
|
122
125
|
async getPayloadByKeyword(input, locale) {
|
|
123
126
|
var _a;
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EACL,YAAY,EAEZ,SAAS,EACT,QAAQ,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,EACL,YAAY,EAEZ,SAAS,EACT,QAAQ,EACR,SAAS,GACV,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAQL,QAAQ,GAET,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AAE/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAC/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAA;AAE5C,MAAM,CAAC,OAAO,OAAO,wBAAwB;IAQ3C,YAAqB,OAAwC;QAAxC,YAAO,GAAP,OAAO,CAAiC;QAC3D,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;QAClC,IAAI,CAAC,cAAc,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAA;QACpD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAA;QAC9B,IAAI,OAAO,CAAC,IAAI;YAAE,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;QAC1C,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,EAAE,CAAA;QACrD,IAAI,CAAC,SAAS,mCAAQ,iBAAiB,GAAK,eAAe,CAAE,CAAA;IAC/D,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,OAAgB;QACpC,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,I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}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Session } from '@botonic/core';
|
|
2
|
+
import { FlowBuilderData } from './flow-builder-models';
|
|
3
|
+
export interface BotonicPluginFlowBuilderOptions {
|
|
4
|
+
flowUrl: string;
|
|
5
|
+
flow?: FlowBuilderData;
|
|
6
|
+
customFunctions?: Record<any, any>;
|
|
7
|
+
getLocale: (session: Session) => string;
|
|
8
|
+
getAccessToken: () => string;
|
|
9
|
+
}
|
|
10
|
+
export declare enum ProcessEnvNodeEnvs {
|
|
11
|
+
PRODUCTION = "production",
|
|
12
|
+
DEVELOPMENT = "development"
|
|
13
|
+
}
|
package/lib/esm/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAYA,MAAM,CAAN,IAAY,kBAGX;AAHD,WAAY,kBAAkB;IAC5B,+CAAyB,CAAA;IACzB,iDAA2B,CAAA;AAC7B,CAAC,EAHW,kBAAkB,KAAlB,kBAAkB,QAG7B"}
|
package/lib/esm/utils.d.ts
CHANGED
|
@@ -1 +1,4 @@
|
|
|
1
|
+
import { Session } from '@botonic/core';
|
|
2
|
+
import { BotonicPluginFlowBuilderOptions } from './types';
|
|
1
3
|
export declare function getWebpackEnvVar(webpackEnvVar: string | false, name: string, defaultValue: string): string;
|
|
4
|
+
export declare function resolveGetAccessToken(options: BotonicPluginFlowBuilderOptions): (session: Session) => string;
|
package/lib/esm/utils.js
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
|
+
import { ProcessEnvNodeEnvs } from './types';
|
|
1
2
|
export function getWebpackEnvVar(webpackEnvVar, name, defaultValue) {
|
|
2
3
|
return (webpackEnvVar ||
|
|
3
4
|
(typeof process !== 'undefined' && process.env[name]) ||
|
|
4
5
|
defaultValue);
|
|
5
6
|
}
|
|
7
|
+
function getAccessTokenFromSession(session) {
|
|
8
|
+
if (!session._access_token) {
|
|
9
|
+
throw new Error('No access token found in session');
|
|
10
|
+
}
|
|
11
|
+
return session._access_token;
|
|
12
|
+
}
|
|
13
|
+
export function resolveGetAccessToken(options) {
|
|
14
|
+
switch (process.env.NODE_ENV) {
|
|
15
|
+
case ProcessEnvNodeEnvs.PRODUCTION:
|
|
16
|
+
return getAccessTokenFromSession;
|
|
17
|
+
case ProcessEnvNodeEnvs.DEVELOPMENT:
|
|
18
|
+
return options.getAccessToken;
|
|
19
|
+
default:
|
|
20
|
+
throw new Error('No method defined for getting access token');
|
|
21
|
+
}
|
|
22
|
+
}
|
|
6
23
|
//# 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":"AAEA,OAAO,EAAmC,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAE7E,MAAM,UAAU,gBAAgB,CAC9B,aAA6B,EAC7B,IAAY,EACZ,YAAoB;IAEpB,OAAO,CACL,aAAa;QACb,CAAC,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACrD,YAAY,CACb,CAAA;AACH,CAAC;AAED,SAAS,yBAAyB,CAAC,OAAgB;IACjD,IAAI,CAAC,OAAO,CAAC,aAAa,EAAE;QAC1B,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAA;KACpD;IACD,OAAO,OAAO,CAAC,aAAa,CAAA;AAC9B,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,OAAwC;IAExC,QAAQ,OAAO,CAAC,GAAG,CAAC,QAAQ,EAAE;QAC5B,KAAK,kBAAkB,CAAC,UAAU;YAChC,OAAO,yBAAyB,CAAA;QAClC,KAAK,kBAAkB,CAAC,WAAW;YACjC,OAAO,OAAO,CAAC,cAAc,CAAA;QAC/B;YACE,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAA;KAChE;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botonic/plugin-flow-builder",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.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",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"@babel/runtime": "^7.20.13",
|
|
51
|
-
"
|
|
52
|
-
"
|
|
51
|
+
"axios": "^1.3.4",
|
|
52
|
+
"@botonic/react": "^0.21.2"
|
|
53
53
|
}
|
|
54
54
|
}
|
package/src/action.tsx
CHANGED
|
@@ -1,65 +1,59 @@
|
|
|
1
|
-
import { ActionRequest, RequestContext
|
|
1
|
+
import { ActionRequest, RequestContext } from '@botonic/react'
|
|
2
2
|
import React from 'react'
|
|
3
3
|
|
|
4
4
|
import { FlowContent } from './content-fields'
|
|
5
5
|
import { doHandoff } from './handoff'
|
|
6
|
-
import
|
|
6
|
+
import { getFlowBuilderPlugin } from './helpers'
|
|
7
7
|
|
|
8
8
|
type FlowBuilderActionProps = {
|
|
9
9
|
content?: FlowContent[]
|
|
10
10
|
isHandoff?: boolean
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
let alternateFallbackMessage = false
|
|
13
14
|
export class FlowBuilderAction extends React.Component<FlowBuilderActionProps> {
|
|
14
15
|
static contextType = RequestContext
|
|
15
16
|
|
|
16
17
|
static async botonicInit(request: ActionRequest): Promise<any> {
|
|
17
|
-
const flowBuilderPlugin = request.plugins
|
|
18
|
-
.hubtypeFlowBuilder as BotonicPluginFlowBuilder
|
|
18
|
+
const flowBuilderPlugin = getFlowBuilderPlugin(request.plugins)
|
|
19
19
|
const locale = flowBuilderPlugin.getLocale(request.session)
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
20
|
+
const payload = request.input.payload
|
|
21
|
+
let targetContentId: string | undefined = payload
|
|
22
|
+
if (!payload && request.session.is_first_interaction) {
|
|
23
|
+
targetContentId = await flowBuilderPlugin.getStartId()
|
|
24
|
+
}
|
|
25
|
+
if (!payload) {
|
|
26
|
+
const intentPayload = await flowBuilderPlugin.getPayloadByIntent(
|
|
26
27
|
request.input,
|
|
27
28
|
locale
|
|
28
29
|
)
|
|
29
|
-
if (intentPayload)
|
|
30
|
-
payload = intentPayload
|
|
31
|
-
}
|
|
30
|
+
if (intentPayload) targetContentId = intentPayload
|
|
32
31
|
const keywordPayload = await flowBuilderPlugin.getPayloadByKeyword(
|
|
33
32
|
request.input,
|
|
34
33
|
locale
|
|
35
34
|
)
|
|
36
|
-
if (keywordPayload)
|
|
37
|
-
payload = keywordPayload
|
|
38
|
-
}
|
|
35
|
+
if (keywordPayload) targetContentId = keywordPayload
|
|
39
36
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
queue: 'Test', // TODO: Take it from the flow
|
|
46
|
-
agentEmail: 'test@gmail.com',
|
|
47
|
-
note: 'This is a note that will be attached to the case as a reminder',
|
|
48
|
-
}
|
|
49
|
-
await doHandoff(request, handoffParams.queue, handoffParams.note)
|
|
50
|
-
const isHandoff = true
|
|
51
|
-
return { isHandoff }
|
|
37
|
+
if (!targetContentId) {
|
|
38
|
+
targetContentId = await flowBuilderPlugin.getFallbackId(
|
|
39
|
+
alternateFallbackMessage
|
|
40
|
+
)
|
|
41
|
+
alternateFallbackMessage = !alternateFallbackMessage
|
|
52
42
|
}
|
|
53
|
-
|
|
43
|
+
|
|
44
|
+
const { contents, handoffNode } = await flowBuilderPlugin.getContents(
|
|
45
|
+
targetContentId,
|
|
46
|
+
locale
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
if (handoffNode) await doHandoff(request, locale, handoffNode)
|
|
50
|
+
|
|
51
|
+
return { contents, handoffNode }
|
|
54
52
|
}
|
|
55
53
|
|
|
56
54
|
render(): JSX.Element | JSX.Element[] {
|
|
57
55
|
// @ts-ignore
|
|
58
|
-
const {
|
|
59
|
-
|
|
60
|
-
return <Text>You are being transferred to an agent!</Text>
|
|
61
|
-
} else {
|
|
62
|
-
return contents!.map((content, index) => content.toBotonic(index))
|
|
63
|
-
}
|
|
56
|
+
const { contents, handoffNode } = this.props
|
|
57
|
+
return contents!.map(content => content.toBotonic(content.id))
|
|
64
58
|
}
|
|
65
59
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
MediaFileLocale,
|
|
3
|
+
TextLocale,
|
|
4
|
+
VideoLocale,
|
|
5
|
+
} from '../flow-builder-models'
|
|
2
6
|
|
|
3
7
|
export abstract class ContentFieldsBase {
|
|
4
|
-
constructor(
|
|
8
|
+
constructor(public readonly id: string) {}
|
|
5
9
|
|
|
6
10
|
static getTextByLocale(locale: string, text: TextLocale[]): string {
|
|
7
11
|
const result = text.find(t => t.locale === locale)
|
|
@@ -9,7 +13,12 @@ export abstract class ContentFieldsBase {
|
|
|
9
13
|
}
|
|
10
14
|
|
|
11
15
|
static getImageByLocale(locale: string, image: MediaFileLocale[]): string {
|
|
12
|
-
const result = image.find(
|
|
16
|
+
const result = image.find(i => i.locale === locale)
|
|
13
17
|
return result?.file ?? ''
|
|
14
18
|
}
|
|
19
|
+
|
|
20
|
+
static getVideoByLocale(locale: string, video: VideoLocale[]): string {
|
|
21
|
+
const result = video.find(v => v.locale === locale)
|
|
22
|
+
return result?.url ?? ''
|
|
23
|
+
}
|
|
15
24
|
}
|
|
@@ -12,7 +12,9 @@ export class FlowButton extends ContentFieldsBase {
|
|
|
12
12
|
static fromHubtypeCMS(component: FbButton, locale: string): FlowButton {
|
|
13
13
|
const newButton = new FlowButton(component.id)
|
|
14
14
|
newButton.text = FlowButton.getTextByLocale(locale, component.text)
|
|
15
|
-
newButton.payload = component.target
|
|
15
|
+
newButton.payload = component.target
|
|
16
|
+
? component.target.id
|
|
17
|
+
: component.payload?.find(payload => payload.locale === locale)?.id
|
|
16
18
|
if (component.url) {
|
|
17
19
|
const urlButton = (component.url as any).find(
|
|
18
20
|
url => url.locale === locale
|
|
@@ -22,10 +24,10 @@ export class FlowButton extends ContentFieldsBase {
|
|
|
22
24
|
return newButton
|
|
23
25
|
}
|
|
24
26
|
|
|
25
|
-
renderButton(
|
|
27
|
+
renderButton(id: string, buttonStyle: ButtonStyle): JSX.Element {
|
|
26
28
|
if (buttonStyle === ButtonStyle.QUICK_REPLY) {
|
|
27
29
|
return (
|
|
28
|
-
<Reply payload={this.payload}
|
|
30
|
+
<Reply key={id} payload={this.payload}>
|
|
29
31
|
{this.text}
|
|
30
32
|
</Reply>
|
|
31
33
|
)
|
|
@@ -34,7 +36,7 @@ export class FlowButton extends ContentFieldsBase {
|
|
|
34
36
|
if (this.url) props = { url: this.url }
|
|
35
37
|
return (
|
|
36
38
|
// @ts-ignore
|
|
37
|
-
<Button payload={this.payload}
|
|
39
|
+
<Button key={id} payload={this.payload} {...props}>
|
|
38
40
|
{this.text}
|
|
39
41
|
</Button>
|
|
40
42
|
)
|