@botonic/plugin-flow-builder 0.21.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +1 -0
  2. package/lib/action.d.ts +15 -0
  3. package/lib/action.js +62 -0
  4. package/lib/action.js.map +1 -0
  5. package/lib/content-fields/button.d.ts +10 -0
  6. package/lib/content-fields/button.js +33 -0
  7. package/lib/content-fields/button.js.map +1 -0
  8. package/lib/content-fields/carousel.d.ts +10 -0
  9. package/lib/content-fields/carousel.js +37 -0
  10. package/lib/content-fields/carousel.js.map +1 -0
  11. package/lib/content-fields/content-base.d.ts +10 -0
  12. package/lib/content-fields/content-base.js +15 -0
  13. package/lib/content-fields/content-base.js.map +1 -0
  14. package/lib/content-fields/element.d.ts +11 -0
  15. package/lib/content-fields/element.js +25 -0
  16. package/lib/content-fields/element.js.map +1 -0
  17. package/lib/content-fields/image.d.ts +9 -0
  18. package/lib/content-fields/image.js +28 -0
  19. package/lib/content-fields/image.js.map +1 -0
  20. package/lib/content-fields/text.d.ts +12 -0
  21. package/lib/content-fields/text.js +35 -0
  22. package/lib/content-fields/text.js.map +1 -0
  23. package/lib/functions/conditional-provider.d.ts +4 -0
  24. package/lib/functions/conditional-provider.js +11 -0
  25. package/lib/functions/conditional-provider.js.map +1 -0
  26. package/lib/functions/conditional-queue-status.d.ts +3 -0
  27. package/lib/functions/conditional-queue-status.js +25 -0
  28. package/lib/functions/conditional-queue-status.js.map +1 -0
  29. package/lib/functions/index.d.ts +6 -0
  30. package/lib/functions/index.js +10 -0
  31. package/lib/functions/index.js.map +1 -0
  32. package/lib/handoff.d.ts +2 -0
  33. package/lib/handoff.js +39 -0
  34. package/lib/handoff.js.map +1 -0
  35. package/lib/hubtype-models.d.ts +152 -0
  36. package/lib/hubtype-models.js +50 -0
  37. package/lib/hubtype-models.js.map +1 -0
  38. package/lib/index.d.ts +30 -0
  39. package/lib/index.js +171 -0
  40. package/lib/index.js.map +1 -0
  41. package/lib/utils.d.ts +2 -0
  42. package/lib/utils.js +10 -0
  43. package/lib/utils.js.map +1 -0
  44. package/package.json +53 -0
  45. package/src/action.tsx +62 -0
  46. package/src/content-fields/button.tsx +34 -0
  47. package/src/content-fields/carousel.tsx +42 -0
  48. package/src/content-fields/content-base.ts +15 -0
  49. package/src/content-fields/element.tsx +24 -0
  50. package/src/content-fields/image.tsx +22 -0
  51. package/src/content-fields/text.tsx +35 -0
  52. package/src/functions/conditional-provider.ts +5 -0
  53. package/src/functions/conditional-queue-status.ts +9 -0
  54. package/src/functions/index.ts +7 -0
  55. package/src/handoff.ts +27 -0
  56. package/src/hubtype-models.ts +190 -0
  57. package/src/index.ts +210 -0
  58. package/src/utils.ts +6 -0
package/README.md ADDED
@@ -0,0 +1 @@
1
+ # Botonic Plugin Flow Builder
@@ -0,0 +1,15 @@
1
+ import { ActionRequest } from '@botonic/react';
2
+ import React from 'react';
3
+ import { FlowContent } from './content-fields/content-base';
4
+ import { HtHandoffNode } from './hubtype-models';
5
+ export declare const START = "08c7df06-0c7c-4f06-b8c1-4157582efeb2";
6
+ declare type FlowBuilderActionProps = {
7
+ content?: FlowContent[];
8
+ handoffMsg?: HtHandoffNode;
9
+ };
10
+ export default class FlowBuilderAction extends React.Component<FlowBuilderActionProps> {
11
+ static contextType: React.Context<import("@botonic/react").RequestContextInterface>;
12
+ static botonicInit(request: ActionRequest): Promise<any>;
13
+ render(): JSX.Element | JSX.Element[];
14
+ }
15
+ export {};
package/lib/action.js ADDED
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.START = void 0;
16
+ const react_1 = require("@botonic/react");
17
+ const react_2 = __importDefault(require("react"));
18
+ const handoff_1 = require("./handoff");
19
+ // TODO: remove this from here and use the new "start" attribute in the flow
20
+ exports.START = '08c7df06-0c7c-4f06-b8c1-4157582efeb2';
21
+ class FlowBuilderAction extends react_2.default.Component {
22
+ static botonicInit(request) {
23
+ return __awaiter(this, void 0, void 0, function* () {
24
+ const flowBuilderPlugin = request.plugins.hubtypeFlowBuilder;
25
+ let payload = request.input.payload ? request.input.payload : exports.START;
26
+ if (!request.input.payload) {
27
+ const intentPayload = yield flowBuilderPlugin.getPayloadByInput(request.input, 'es-ES');
28
+ if (intentPayload) {
29
+ payload = intentPayload;
30
+ }
31
+ const keywordPayload = yield flowBuilderPlugin.getPayloadByKeyword(request.input, 'es-ES');
32
+ if (keywordPayload) {
33
+ payload = keywordPayload;
34
+ }
35
+ }
36
+ // We use only Spanish because they are the backend examples
37
+ const content = yield flowBuilderPlugin.getContents(payload, 'es-ES');
38
+ if (content.length == 0) {
39
+ const handoffMsg = yield handoff_1.doHandoff(request);
40
+ return { handoffMsg };
41
+ }
42
+ return { content };
43
+ });
44
+ }
45
+ render() {
46
+ // @ts-ignore
47
+ const { content: contents, handoffMsg } = this.props;
48
+ if (handoffMsg) {
49
+ // @ts-ignore
50
+ return react_2.default.createElement(react_1.Text, null, handoffMsg);
51
+ }
52
+ else {
53
+ return contents.map((content, index) => {
54
+ console.log({ content, index });
55
+ return content.toBotonic(index);
56
+ });
57
+ }
58
+ }
59
+ }
60
+ exports.default = FlowBuilderAction;
61
+ FlowBuilderAction.contextType = react_1.RequestContext;
62
+ //# sourceMappingURL=action.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action.js","sourceRoot":"","sources":["../src/action.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,0CAAoE;AACpE,kDAAyB;AAGzB,uCAAqC;AAGrC,4EAA4E;AAC/D,QAAA,KAAK,GAAG,sCAAsC,CAAA;AAO3D,MAAqB,iBAAkB,SAAQ,eAAK,CAAC,SAAiC;IAGpF,MAAM,CAAO,WAAW,CAAC,OAAsB;;YAC7C,MAAM,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,kBAAyB,CAAA;YAEnE,IAAI,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,aAAK,CAAA;YACnE,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE;gBAC1B,MAAM,aAAa,GAAG,MAAM,iBAAiB,CAAC,iBAAiB,CAC7D,OAAO,CAAC,KAAK,EACb,OAAO,CACR,CAAA;gBACD,IAAI,aAAa,EAAE;oBACjB,OAAO,GAAG,aAAa,CAAA;iBACxB;gBACD,MAAM,cAAc,GAAG,MAAM,iBAAiB,CAAC,mBAAmB,CAChE,OAAO,CAAC,KAAK,EACb,OAAO,CACR,CAAA;gBACD,IAAI,cAAc,EAAE;oBAClB,OAAO,GAAG,cAAc,CAAA;iBACzB;aACF;YACD,4DAA4D;YAC5D,MAAM,OAAO,GAAG,MAAM,iBAAiB,CAAC,WAAW,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;YAErE,IAAI,OAAO,CAAC,MAAM,IAAI,CAAC,EAAE;gBACvB,MAAM,UAAU,GAAG,MAAM,mBAAS,CAAC,OAAO,CAAC,CAAA;gBAC3C,OAAO,EAAE,UAAU,EAAE,CAAA;aACtB;YACD,OAAO,EAAE,OAAO,EAAE,CAAA;QACpB,CAAC;KAAA;IAED,MAAM;QACJ,aAAa;QACb,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,KAAK,CAAA;QACpD,IAAI,UAAU,EAAE;YACd,aAAa;YACb,OAAO,8BAAC,YAAI,QAAE,UAAU,CAAQ,CAAA;SACjC;aAAM;YACL,OAAO,QAAS,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE;gBACtC,OAAO,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAA;gBAC/B,OAAO,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;YACjC,CAAC,CAAC,CAAA;SACH;IACH,CAAC;;AA7CH,oCA8CC;AA7CQ,6BAAW,GAAG,sBAAc,CAAA"}
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ import { ButtonStyle, HtButton } from '../hubtype-models';
3
+ import { ContentFieldsBase } from './content-base';
4
+ export declare class FlowButton extends ContentFieldsBase {
5
+ text: string;
6
+ url?: string;
7
+ payload?: string;
8
+ static fromHubtypeCMS(component: HtButton, locale: string): FlowButton;
9
+ renderButton(index: number, buttonStyle: ButtonStyle): JSX.Element;
10
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.FlowButton = void 0;
7
+ const react_1 = require("@botonic/react");
8
+ const react_2 = __importDefault(require("react"));
9
+ const hubtype_models_1 = require("../hubtype-models");
10
+ const content_base_1 = require("./content-base");
11
+ class FlowButton extends content_base_1.ContentFieldsBase {
12
+ constructor() {
13
+ super(...arguments);
14
+ this.text = '';
15
+ }
16
+ static fromHubtypeCMS(component, locale) {
17
+ var _a;
18
+ const newButton = new FlowButton(component.id);
19
+ newButton.text = FlowButton.getTextByLocale(locale, component.text);
20
+ newButton.payload = (_a = component.target) === null || _a === void 0 ? void 0 : _a.id;
21
+ return newButton;
22
+ }
23
+ renderButton(index, buttonStyle) {
24
+ if (buttonStyle == hubtype_models_1.ButtonStyle.QUICK_REPLY) {
25
+ return (react_2.default.createElement(react_1.Reply, { payload: this.payload, key: index }, this.text));
26
+ }
27
+ return (
28
+ // @ts-ignore
29
+ react_2.default.createElement(react_1.Button, { payload: this.payload, key: index }, this.text));
30
+ }
31
+ }
32
+ exports.FlowButton = FlowButton;
33
+ //# sourceMappingURL=button.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"button.js","sourceRoot":"","sources":["../../src/content-fields/button.tsx"],"names":[],"mappings":";;;;;;AAAA,0CAA8C;AAC9C,kDAAyB;AAEzB,sDAAyD;AACzD,iDAAkD;AAElD,MAAa,UAAW,SAAQ,gCAAiB;IAAjD;;QACS,SAAI,GAAG,EAAE,CAAA;IA0BlB,CAAC;IAtBC,MAAM,CAAC,cAAc,CAAC,SAAmB,EAAE,MAAc;;QACvD,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAC9C,SAAS,CAAC,IAAI,GAAG,UAAU,CAAC,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,IAAI,CAAC,CAAA;QACnE,SAAS,CAAC,OAAO,GAAG,MAAA,SAAS,CAAC,MAAM,0CAAE,EAAE,CAAA;QACxC,OAAO,SAAS,CAAA;IAClB,CAAC;IAED,YAAY,CAAC,KAAa,EAAE,WAAwB;QAClD,IAAI,WAAW,IAAI,4BAAW,CAAC,WAAW,EAAE;YAC1C,OAAO,CACL,8BAAC,aAAK,IAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,IACrC,IAAI,CAAC,IAAI,CACJ,CACT,CAAA;SACF;QACD,OAAO;QACL,aAAa;QACb,8BAAC,cAAM,IAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,IACtC,IAAI,CAAC,IAAI,CACH,CACV,CAAA;IACH,CAAC;CACF;AA3BD,gCA2BC"}
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ import { HtCarouselNode } from '../hubtype-models';
3
+ import { ContentFieldsBase } from './content-base';
4
+ import { FlowElement } from './element';
5
+ export declare class FlowCarousel extends ContentFieldsBase {
6
+ code: string;
7
+ elements: FlowElement[];
8
+ static fromHubtypeCMS(component: HtCarouselNode, locale: string): FlowCarousel;
9
+ toBotonic(index: number): JSX.Element;
10
+ }
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.FlowCarousel = void 0;
7
+ const react_1 = require("@botonic/react");
8
+ const react_2 = __importDefault(require("react"));
9
+ const content_base_1 = require("./content-base");
10
+ const element_1 = require("./element");
11
+ class FlowCarousel extends content_base_1.ContentFieldsBase {
12
+ constructor() {
13
+ super(...arguments);
14
+ this.code = '';
15
+ this.elements = [];
16
+ }
17
+ static fromHubtypeCMS(component, locale) {
18
+ const newCarousel = new FlowCarousel(component.id);
19
+ newCarousel.code = component.code;
20
+ newCarousel.elements = component.content.elements.map(ele => element_1.FlowElement.fromHubtypeCMS(ele, locale));
21
+ return newCarousel;
22
+ }
23
+ toBotonic(index) {
24
+ return (react_2.default.createElement(react_1.Carousel, { key: index }, this.elements.map((e, eIndex) => {
25
+ var _a, _b;
26
+ console.log('TO BOTONIC BOTONIC PACKAGES', { e });
27
+ return (react_2.default.createElement(react_1.Element, { key: eIndex },
28
+ react_2.default.createElement(react_1.Pic, { src: e.image }),
29
+ react_2.default.createElement(react_1.Title, { style: '' }, e.title),
30
+ react_2.default.createElement(react_1.Subtitle, { style: '' }, e.subtitle),
31
+ react_2.default.createElement(react_1.Button, { payload: (_a = e.buttons) === null || _a === void 0 ? void 0 : _a.payload }, (_b = e.buttons) === null || _b === void 0 ? void 0 : _b.text),
32
+ ","));
33
+ })));
34
+ }
35
+ }
36
+ exports.FlowCarousel = FlowCarousel;
37
+ //# sourceMappingURL=carousel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"carousel.js","sourceRoot":"","sources":["../../src/content-fields/carousel.tsx"],"names":[],"mappings":";;;;;;AAAA,0CAAgF;AAChF,kDAAyB;AAGzB,iDAAkD;AAClD,uCAAuC;AAEvC,MAAa,YAAa,SAAQ,gCAAiB;IAAnD;;QACS,SAAI,GAAG,EAAE,CAAA;QACT,aAAQ,GAAkB,EAAE,CAAA;IAgCrC,CAAC;IA9BC,MAAM,CAAC,cAAc,CACnB,SAAyB,EACzB,MAAc;QAEd,MAAM,WAAW,GAAG,IAAI,YAAY,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAClD,WAAW,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,CAAA;QACjC,WAAW,CAAC,QAAQ,GAAG,SAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAC1D,qBAAW,CAAC,cAAc,CAAC,GAAG,EAAE,MAAM,CAAC,CACxC,CAAA;QACD,OAAO,WAAW,CAAA;IACpB,CAAC;IAED,SAAS,CAAC,KAAa;QACrB,OAAO,CACL,8BAAC,gBAAQ,IAAC,GAAG,EAAE,KAAK,IACjB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE;;YAC/B,OAAO,CAAC,GAAG,CAAC,6BAA6B,EAAE,EAAE,CAAC,EAAE,CAAC,CAAA;YACjD,OAAO,CACL,8BAAC,eAAO,IAAC,GAAG,EAAE,MAAM;gBAClB,8BAAC,WAAG,IAAC,GAAG,EAAE,CAAC,CAAC,KAAK,GAAI;gBACrB,8BAAC,aAAK,IAAC,KAAK,EAAC,EAAE,IAAE,CAAC,CAAC,KAAK,CAAS;gBACjC,8BAAC,gBAAQ,IAAC,KAAK,EAAC,EAAE,IAAE,CAAC,CAAC,QAAQ,CAAY;gBAE1C,8BAAC,cAAM,IAAC,OAAO,EAAE,MAAA,CAAC,CAAC,OAAO,0CAAE,OAAO,IAAG,MAAA,CAAC,CAAC,OAAO,0CAAE,IAAI,CAAU;oBACvD,CACX,CAAA;QACH,CAAC,CAAC,CACO,CACZ,CAAA;IACH,CAAC;CACF;AAlCD,oCAkCC"}
@@ -0,0 +1,10 @@
1
+ import { HtTextLocale } from '../hubtype-models';
2
+ import { FlowCarousel } from './carousel';
3
+ import { FlowImage } from './image';
4
+ import { FlowText } from './text';
5
+ export declare abstract class ContentFieldsBase {
6
+ private readonly id;
7
+ constructor(id: string);
8
+ static getTextByLocale(locale: string, text: HtTextLocale[]): string;
9
+ }
10
+ export declare type FlowContent = FlowText | FlowImage | FlowCarousel;
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ContentFieldsBase = void 0;
4
+ class ContentFieldsBase {
5
+ constructor(id) {
6
+ this.id = id;
7
+ }
8
+ static getTextByLocale(locale, text) {
9
+ var _a;
10
+ const result = text.find(t => t.locale == locale);
11
+ return (_a = result === null || result === void 0 ? void 0 : result.message) !== null && _a !== void 0 ? _a : '';
12
+ }
13
+ }
14
+ exports.ContentFieldsBase = ContentFieldsBase;
15
+ //# sourceMappingURL=content-base.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"content-base.js","sourceRoot":"","sources":["../../src/content-fields/content-base.ts"],"names":[],"mappings":";;;AAKA,MAAsB,iBAAiB;IACrC,YAA6B,EAAU;QAAV,OAAE,GAAF,EAAE,CAAQ;IAAG,CAAC;IAE3C,MAAM,CAAC,eAAe,CAAC,MAAc,EAAE,IAAoB;;QACzD,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,IAAI,MAAM,CAAC,CAAA;QACjD,OAAO,MAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,OAAO,mCAAI,EAAE,CAAA;IAC9B,CAAC;CACF;AAPD,8CAOC"}
@@ -0,0 +1,11 @@
1
+ import { HtElement } from '../hubtype-models';
2
+ import { FlowButton } from './button';
3
+ import { ContentFieldsBase } from './content-base';
4
+ export declare class FlowElement extends ContentFieldsBase {
5
+ title: string;
6
+ subtitle: string;
7
+ buttons: FlowButton | undefined;
8
+ image: string;
9
+ hidden: boolean;
10
+ static fromHubtypeCMS(component: HtElement, locale: string): FlowElement;
11
+ }
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FlowElement = void 0;
4
+ const utils_1 = require("../utils");
5
+ const button_1 = require("./button");
6
+ const content_base_1 = require("./content-base");
7
+ class FlowElement extends content_base_1.ContentFieldsBase {
8
+ constructor() {
9
+ super(...arguments);
10
+ this.title = '';
11
+ this.subtitle = '';
12
+ this.image = '';
13
+ this.hidden = false;
14
+ }
15
+ static fromHubtypeCMS(component, locale) {
16
+ const newElement = new FlowElement(component.id);
17
+ newElement.title = FlowElement.getTextByLocale(locale, component.title);
18
+ newElement.subtitle = FlowElement.getTextByLocale(locale, component.subtitle);
19
+ newElement.image = utils_1.getImageByLocale(locale, component.image);
20
+ newElement.buttons = button_1.FlowButton.fromHubtypeCMS(component.button, locale);
21
+ return newElement;
22
+ }
23
+ }
24
+ exports.FlowElement = FlowElement;
25
+ //# sourceMappingURL=element.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element.js","sourceRoot":"","sources":["../../src/content-fields/element.tsx"],"names":[],"mappings":";;;AACA,oCAA2C;AAC3C,qCAAqC;AACrC,iDAAkD;AAElD,MAAa,WAAY,SAAQ,gCAAiB;IAAlD;;QACS,UAAK,GAAG,EAAE,CAAA;QACV,aAAQ,GAAG,EAAE,CAAA;QAEb,UAAK,GAAG,EAAE,CAAA;QACV,WAAM,GAAG,KAAK,CAAA;IAavB,CAAC;IAXC,MAAM,CAAC,cAAc,CAAC,SAAoB,EAAE,MAAc;QACxD,MAAM,UAAU,GAAG,IAAI,WAAW,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAChD,UAAU,CAAC,KAAK,GAAG,WAAW,CAAC,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,KAAK,CAAC,CAAA;QACvE,UAAU,CAAC,QAAQ,GAAG,WAAW,CAAC,eAAe,CAC/C,MAAM,EACN,SAAS,CAAC,QAAQ,CACnB,CAAA;QACD,UAAU,CAAC,KAAK,GAAG,wBAAgB,CAAC,MAAM,EAAE,SAAS,CAAC,KAAK,CAAC,CAAA;QAC5D,UAAU,CAAC,OAAO,GAAG,mBAAU,CAAC,cAAc,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QACxE,OAAO,UAAU,CAAA;IACnB,CAAC;CACF;AAlBD,kCAkBC"}
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { HtImageNode } from '../hubtype-models';
3
+ import { ContentFieldsBase } from './content-base';
4
+ export declare class FlowImage extends ContentFieldsBase {
5
+ src: string;
6
+ code: string;
7
+ static fromHubtypeCMS(component: HtImageNode, locale: string): FlowImage;
8
+ toBotonic(index: number): JSX.Element;
9
+ }
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.FlowImage = void 0;
7
+ const react_1 = require("@botonic/react");
8
+ const react_2 = __importDefault(require("react"));
9
+ const utils_1 = require("../utils");
10
+ const content_base_1 = require("./content-base");
11
+ class FlowImage extends content_base_1.ContentFieldsBase {
12
+ constructor() {
13
+ super(...arguments);
14
+ this.src = '';
15
+ this.code = '';
16
+ }
17
+ static fromHubtypeCMS(component, locale) {
18
+ const newImage = new FlowImage(component.id);
19
+ newImage.code = component.code;
20
+ newImage.src = utils_1.getImageByLocale(locale, component.content.image);
21
+ return newImage;
22
+ }
23
+ toBotonic(index) {
24
+ return react_2.default.createElement(react_1.Image, { src: this.src, key: index });
25
+ }
26
+ }
27
+ exports.FlowImage = FlowImage;
28
+ //# sourceMappingURL=image.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"image.js","sourceRoot":"","sources":["../../src/content-fields/image.tsx"],"names":[],"mappings":";;;;;;AAAA,0CAAsC;AACtC,kDAAyB;AAGzB,oCAA2C;AAC3C,iDAAkD;AAElD,MAAa,SAAU,SAAQ,gCAAiB;IAAhD;;QACS,QAAG,GAAG,EAAE,CAAA;QACR,SAAI,GAAG,EAAE,CAAA;IAYlB,CAAC;IAVC,MAAM,CAAC,cAAc,CAAC,SAAsB,EAAE,MAAc;QAC1D,MAAM,QAAQ,GAAG,IAAI,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAC5C,QAAQ,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,CAAA;QAC9B,QAAQ,CAAC,GAAG,GAAG,wBAAgB,CAAC,MAAM,EAAE,SAAS,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAChE,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED,SAAS,CAAC,KAAa;QACrB,OAAO,8BAAC,aAAK,IAAC,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,GAAI,CAAA;IAC7C,CAAC;CACF;AAdD,8BAcC"}
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ import { ButtonStyle, HtTextNode } from '../hubtype-models';
3
+ import { FlowButton } from './button';
4
+ import { ContentFieldsBase } from './content-base';
5
+ export declare class FlowText extends ContentFieldsBase {
6
+ text: string;
7
+ code: string;
8
+ buttons: FlowButton[];
9
+ buttonStyle: ButtonStyle;
10
+ static fromHubtypeCMS(component: HtTextNode, locale: string): FlowText;
11
+ toBotonic(index: number): JSX.Element;
12
+ }
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.FlowText = void 0;
7
+ const react_1 = require("@botonic/react");
8
+ const react_2 = __importDefault(require("react"));
9
+ const hubtype_models_1 = require("../hubtype-models");
10
+ const button_1 = require("./button");
11
+ const content_base_1 = require("./content-base");
12
+ class FlowText extends content_base_1.ContentFieldsBase {
13
+ constructor() {
14
+ super(...arguments);
15
+ this.text = '';
16
+ this.code = '';
17
+ this.buttons = [];
18
+ this.buttonStyle = hubtype_models_1.ButtonStyle.BUTTON;
19
+ }
20
+ static fromHubtypeCMS(component, locale) {
21
+ const newText = new FlowText(component.id);
22
+ newText.code = component.code;
23
+ newText.buttonStyle = component.content.buttons_style || hubtype_models_1.ButtonStyle.BUTTON;
24
+ newText.text = FlowText.getTextByLocale(locale, component.content.text);
25
+ newText.buttons = component.content.buttons.map(button => button_1.FlowButton.fromHubtypeCMS(button, locale));
26
+ return newText;
27
+ }
28
+ toBotonic(index) {
29
+ return (react_2.default.createElement(react_1.Text, { key: index },
30
+ this.text,
31
+ this.buttons.map((button, index) => button.renderButton(index, this.buttonStyle))));
32
+ }
33
+ }
34
+ exports.FlowText = FlowText;
35
+ //# sourceMappingURL=text.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text.js","sourceRoot":"","sources":["../../src/content-fields/text.tsx"],"names":[],"mappings":";;;;;;AAAA,0CAAqC;AACrC,kDAAyB;AAEzB,sDAA2D;AAC3D,qCAAqC;AACrC,iDAAkD;AAElD,MAAa,QAAS,SAAQ,gCAAiB;IAA/C;;QACS,SAAI,GAAG,EAAE,CAAA;QACT,SAAI,GAAG,EAAE,CAAA;QACT,YAAO,GAAiB,EAAE,CAAA;QAC1B,gBAAW,GAAG,4BAAW,CAAC,MAAM,CAAA;IAuBzC,CAAC;IArBC,MAAM,CAAC,cAAc,CAAC,SAAqB,EAAE,MAAc;QACzD,MAAM,OAAO,GAAG,IAAI,QAAQ,CAAC,SAAS,CAAC,EAAE,CAAC,CAAA;QAC1C,OAAO,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,CAAA;QAC7B,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,OAAO,CAAC,aAAa,IAAI,4BAAW,CAAC,MAAM,CAAA;QAC3E,OAAO,CAAC,IAAI,GAAG,QAAQ,CAAC,eAAe,CAAC,MAAM,EAAE,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QACvE,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CACvD,mBAAU,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,CAC1C,CAAA;QACD,OAAO,OAAO,CAAA;IAChB,CAAC;IAED,SAAS,CAAC,KAAa;QACrB,OAAO,CACL,8BAAC,YAAI,IAAC,GAAG,EAAE,KAAK;YACb,IAAI,CAAC,IAAI;YACT,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAClC,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,CAAC,CAC7C,CACI,CACR,CAAA;IACH,CAAC;CACF;AA3BD,4BA2BC"}
@@ -0,0 +1,4 @@
1
+ export declare function conditionalProvider({ session, results }: {
2
+ session: any;
3
+ results: any;
4
+ }): string;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.conditionalProvider = void 0;
4
+ function conditionalProvider({ session, results }) {
5
+ const provider = session.user.provider;
6
+ if (results.includes(provider))
7
+ return provider;
8
+ return 'default';
9
+ }
10
+ exports.conditionalProvider = conditionalProvider;
11
+ //# sourceMappingURL=conditional-provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conditional-provider.js","sourceRoot":"","sources":["../../src/functions/conditional-provider.ts"],"names":[],"mappings":";;;AAAA,SAAgB,mBAAmB,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE;IACtD,MAAM,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAA;IACtC,IAAI,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,OAAO,QAAQ,CAAA;IAC/C,OAAO,SAAS,CAAA;AAClB,CAAC;AAJD,kDAIC"}
@@ -0,0 +1,3 @@
1
+ export declare function conditionalQueueStatus({ queueId }: {
2
+ queueId: any;
3
+ }): Promise<string>;
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.conditionalQueueStatus = void 0;
16
+ const axios_1 = __importDefault(require("axios"));
17
+ function conditionalQueueStatus({ queueId }) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const response = yield axios_1.default.get(`https://api.hubtype.com/v1/queues/${queueId}/availability/`);
20
+ const isAvailable = response.data.available;
21
+ return isAvailable ? 'open' : 'closed';
22
+ });
23
+ }
24
+ exports.conditionalQueueStatus = conditionalQueueStatus;
25
+ //# sourceMappingURL=conditional-queue-status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"conditional-queue-status.js","sourceRoot":"","sources":["../../src/functions/conditional-queue-status.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,kDAAyB;AAEzB,SAAsB,sBAAsB,CAAC,EAAE,OAAO,EAAE;;QACtD,MAAM,QAAQ,GAAG,MAAM,eAAK,CAAC,GAAG,CAC9B,qCAAqC,OAAO,gBAAgB,CAC7D,CAAA;QACD,MAAM,WAAW,GAAG,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAA;QAC3C,OAAO,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAA;IACxC,CAAC;CAAA;AAND,wDAMC"}
@@ -0,0 +1,6 @@
1
+ import { conditionalProvider } from './conditional-provider';
2
+ import { conditionalQueueStatus } from './conditional-queue-status';
3
+ export declare const DEFAULT_FUNCTIONS: {
4
+ 'conditional-queue-status': typeof conditionalQueueStatus;
5
+ 'conditional-provider': typeof conditionalProvider;
6
+ };
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_FUNCTIONS = void 0;
4
+ const conditional_provider_1 = require("./conditional-provider");
5
+ const conditional_queue_status_1 = require("./conditional-queue-status");
6
+ exports.DEFAULT_FUNCTIONS = {
7
+ 'conditional-queue-status': conditional_queue_status_1.conditionalQueueStatus,
8
+ 'conditional-provider': conditional_provider_1.conditionalProvider,
9
+ };
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/functions/index.ts"],"names":[],"mappings":";;;AAAA,iEAA4D;AAC5D,yEAAmE;AAEtD,QAAA,iBAAiB,GAAG;IAC/B,0BAA0B,EAAE,iDAAsB;IAClD,sBAAsB,EAAE,0CAAmB;CAC5C,CAAA"}
@@ -0,0 +1,2 @@
1
+ import { ActionRequest } from '@botonic/react';
2
+ export declare function doHandoff(request: ActionRequest): Promise<any>;
package/lib/handoff.js ADDED
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.doHandoff = void 0;
13
+ const core_1 = require("@botonic/core");
14
+ // TODO: Remove all "getOpenQueues" logic and open/closed messages.
15
+ // This function should just do a basic handoff
16
+ // TODO: add missing options: withNote, withAgent
17
+ function doHandoff(request) {
18
+ var _a;
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ // @ts-ignore
21
+ const flowBuilderPlugin = request.plugins.hubtypeFlowBuilder;
22
+ const handoffContent = yield flowBuilderPlugin.getHandoffContent();
23
+ console.log(handoffContent);
24
+ // @ts-ignore
25
+ let openQueues = yield core_1.getOpenQueues(request.session);
26
+ const queueName = 'Test';
27
+ if (openQueues.queues.indexOf(queueName) !== -1) {
28
+ // @ts-ignore
29
+ const handOffBuilder = new core_1.HandOffBuilder(request.session);
30
+ handOffBuilder.withQueue('Test');
31
+ handOffBuilder.withOnFinishPayload((_a = handoffContent.target) === null || _a === void 0 ? void 0 : _a.id);
32
+ yield handOffBuilder.handOff();
33
+ return handoffContent.content.message[0].message;
34
+ }
35
+ return handoffContent.content.failMessage[0].message;
36
+ });
37
+ }
38
+ exports.doHandoff = doHandoff;
39
+ //# sourceMappingURL=handoff.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handoff.js","sourceRoot":"","sources":["../src/handoff.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,wCAA6D;AAG7D,mEAAmE;AACnE,+CAA+C;AAC/C,iDAAiD;AAEjD,SAAsB,SAAS,CAAC,OAAsB;;;QACpD,aAAa;QACb,MAAM,iBAAiB,GAAG,OAAO,CAAC,OAAO,CAAC,kBAAyB,CAAA;QACnE,MAAM,cAAc,GAAG,MAAM,iBAAiB,CAAC,iBAAiB,EAAE,CAAA;QAClE,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAA;QAC3B,aAAa;QACb,IAAI,UAAU,GAAG,MAAM,oBAAa,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;QACrD,MAAM,SAAS,GAAG,MAAM,CAAA;QACxB,IAAI,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE;YAC/C,aAAa;YACb,MAAM,cAAc,GAAG,IAAI,qBAAc,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;YAC1D,cAAc,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;YAChC,cAAc,CAAC,mBAAmB,CAAC,MAAA,cAAc,CAAC,MAAM,0CAAE,EAAG,CAAC,CAAA;YAC9D,MAAM,cAAc,CAAC,OAAO,EAAE,CAAA;YAE9B,OAAO,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;SACjD;QAED,OAAO,cAAc,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,OAAO,CAAA;;CACrD;AAnBD,8BAmBC"}
@@ -0,0 +1,152 @@
1
+ export declare enum ButtonStyle {
2
+ BUTTON = "button",
3
+ QUICK_REPLY = "quick-reply"
4
+ }
5
+ export declare enum MessageContentType {
6
+ CAROUSEL = "carousel",
7
+ IMAGE = "image",
8
+ TEXT = "text",
9
+ KEYWORD = "keyword",
10
+ HANDOFF = "handoff",
11
+ FUNCTION = "function",
12
+ INTENT = "intent"
13
+ }
14
+ export declare enum NonMessageContentType {
15
+ INTENT = "intent",
16
+ PAYLOAD = "payload",
17
+ QUEUE = "queue",
18
+ URL = "url"
19
+ }
20
+ export declare enum SubContentType {
21
+ BUTTON = "button",
22
+ ELEMENT = "element"
23
+ }
24
+ export declare enum MediaContentType {
25
+ ASSET = "asset"
26
+ }
27
+ export declare enum StartFieldsType {
28
+ STARTUP = "startUp"
29
+ }
30
+ export declare enum InputContentType {
31
+ INPUT = "user-input"
32
+ }
33
+ export declare enum InputType {
34
+ INTENTS = "intents",
35
+ KEYWORDS = "keywords"
36
+ }
37
+ export declare const NodeContentType: {
38
+ INPUT: InputContentType.INPUT;
39
+ CAROUSEL: MessageContentType.CAROUSEL;
40
+ IMAGE: MessageContentType.IMAGE;
41
+ TEXT: MessageContentType.TEXT;
42
+ KEYWORD: MessageContentType.KEYWORD;
43
+ HANDOFF: MessageContentType.HANDOFF;
44
+ FUNCTION: MessageContentType.FUNCTION;
45
+ INTENT: MessageContentType.INTENT;
46
+ };
47
+ export declare type NodeContentType = MessageContentType | InputContentType;
48
+ export interface HtFlowBuilderData {
49
+ version: string;
50
+ name: string;
51
+ locales: string[];
52
+ nodes: HtNodeComponent[];
53
+ }
54
+ export interface HtNodeLink {
55
+ id: string;
56
+ type: NodeContentType;
57
+ }
58
+ export interface HtBaseNode {
59
+ id: string;
60
+ code: string;
61
+ meta: {
62
+ x: number;
63
+ y: number;
64
+ };
65
+ follow_up?: HtNodeLink;
66
+ target?: HtNodeLink;
67
+ }
68
+ export interface HtTextLocale {
69
+ message: string;
70
+ locale: string;
71
+ }
72
+ export interface HtInputLocale {
73
+ values: string[];
74
+ locale: string;
75
+ }
76
+ export interface HtMediaFileLocale {
77
+ id: string;
78
+ file: string;
79
+ locale: string;
80
+ }
81
+ export interface HtTextNode extends HtBaseNode {
82
+ type: MessageContentType.TEXT;
83
+ content: {
84
+ text: HtTextLocale[];
85
+ buttons_style?: ButtonStyle;
86
+ buttons: HtButton[];
87
+ };
88
+ }
89
+ export interface HtButton {
90
+ id: string;
91
+ text: HtTextLocale[];
92
+ target?: HtNodeLink;
93
+ hidden: string[];
94
+ }
95
+ export interface HtImageNode extends HtBaseNode {
96
+ type: MessageContentType.IMAGE;
97
+ content: {
98
+ image: HtMediaFileLocale[];
99
+ };
100
+ }
101
+ export interface HtCarouselNode extends HtBaseNode {
102
+ type: MessageContentType.CAROUSEL;
103
+ content: {
104
+ elements: HtElement[];
105
+ };
106
+ }
107
+ export interface HtElement {
108
+ id: string;
109
+ title: HtTextLocale[];
110
+ subtitle: HtTextLocale[];
111
+ image: HtMediaFileLocale[];
112
+ button: HtButton;
113
+ hidden: string[];
114
+ }
115
+ export interface HtIntentNode extends HtBaseNode {
116
+ type: MessageContentType.INTENT;
117
+ content: {
118
+ title: HtTextLocale[];
119
+ intents: HtInputLocale[];
120
+ confidence: number;
121
+ };
122
+ }
123
+ export interface HtKeywordNode extends HtBaseNode {
124
+ type: MessageContentType.KEYWORD;
125
+ content: {
126
+ title: HtTextLocale[];
127
+ keywords: HtInputLocale[];
128
+ };
129
+ }
130
+ export interface HtHandoffNode extends HtBaseNode {
131
+ type: MessageContentType.HANDOFF;
132
+ content: {
133
+ queue: HtQueueLocale[];
134
+ message: HtTextLocale[];
135
+ failMessage: HtTextLocale[];
136
+ };
137
+ }
138
+ export interface HtQueueLocale {
139
+ id: string;
140
+ name: string;
141
+ locale: string;
142
+ }
143
+ export interface HtFunctionNode extends HtBaseNode {
144
+ type: MessageContentType.FUNCTION;
145
+ content: {
146
+ subtype: string;
147
+ action: string;
148
+ arguments: Array<any>;
149
+ result_mapping: Array<any>;
150
+ };
151
+ }
152
+ export declare type HtNodeComponent = HtTextNode | HtImageNode | HtCarouselNode | HtIntentNode | HtKeywordNode | HtHandoffNode | HtFunctionNode;