@inploi/plugin-chatbot 3.28.4 → 3.28.6

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const index = require("./index-251fe248.cjs");
3
+ const index = require("./index-1bbddc51.cjs");
4
4
  require("@inploi/sdk");
5
5
  const isConditionMet = ({
6
6
  condition,
@@ -452,6 +452,13 @@ async function interpret(params) {
452
452
  throw new Error(`Unknown node: ${JSON.stringify(node)}`);
453
453
  }
454
454
  }
455
+ const getSubmissionValue = (submissions, key) => {
456
+ var _a;
457
+ const value = (_a = submissions[key]) == null ? void 0 : _a.value;
458
+ if (typeof value !== "string" && typeof value !== "number")
459
+ throw new Error(`Submission at “${key}” is not a string or number`);
460
+ return value;
461
+ };
455
462
  async function interpretIdentifyNode({
456
463
  next,
457
464
  node,
@@ -459,21 +466,28 @@ async function interpretIdentifyNode({
459
466
  submissions,
460
467
  logger
461
468
  }) {
462
- var _a;
463
469
  if (!submissions)
464
470
  return next(node.nextId);
465
- const identifier = (_a = submissions[node.data.key]) == null ? void 0 : _a.value;
466
- if (typeof identifier !== "string" && typeof identifier !== "number") {
467
- logger.warn(`Failed to identify user, key “${node.data.key}” is not a string or number`);
468
- return next(node.nextId);
471
+ try {
472
+ analytics.log({
473
+ event: "IDENTIFY",
474
+ properties: {
475
+ identifier: getSubmissionValue(submissions, node.data.key).toString(),
476
+ first_name: node.data.firstName ? getSubmissionValue(submissions, node.data.firstName).toString() : void 0,
477
+ last_name: node.data.lastName ? getSubmissionValue(submissions, node.data.lastName).toString() : void 0,
478
+ email: node.data.email ? getSubmissionValue(submissions, node.data.email).toString() : void 0,
479
+ phone_number: node.data.phoneNumber ? getSubmissionValue(submissions, node.data.phoneNumber).toString() : void 0,
480
+ custom_traits: node.data.customTraits ? Object.fromEntries(Object.entries(node.data.customTraits).map(([key, value]) => {
481
+ var _a;
482
+ return [key, (_a = submissions[value]) == null ? void 0 : _a.value];
483
+ })) : void 0
484
+ }
485
+ });
486
+ } catch (e) {
487
+ logger.error(e);
488
+ } finally {
489
+ next(node.nextId);
469
490
  }
470
- analytics.log({
471
- event: "IDENTIFY",
472
- properties: {
473
- identifier: identifier.toString()
474
- }
475
- });
476
- next(node.nextId);
477
491
  }
478
492
  async function interpretJumpNode({
479
493
  next,
@@ -597,32 +611,41 @@ async function interpretSubmitNode({
597
611
  author: "bot",
598
612
  text: response2.redirect.message ?? "Almost there! Please complete your submission here:"
599
613
  });
600
- const href = new URL(response2.redirect.redirect_url);
601
- if (anonymous_id && !href.searchParams.has("anonymous_id")) {
602
- href.searchParams.set("anonymous_id", anonymous_id);
603
- }
604
- await chat.sendMessage({
605
- type: "link",
606
- href: href.toString(),
607
- text: response2.redirect.button_text ?? "Complete submission",
608
- onClick: () => {
609
- if (!session_id) {
610
- logger.error("session_id not set, cannot log FLOW_REDIRECT event");
611
- return;
612
- }
613
- analytics.log({
614
- event: "FLOW_REDIRECT",
615
- properties: {
616
- flow_build: flow.build,
617
- flow_id: flow.id,
618
- flow_session_id: session_id,
619
- flow_version: flow.version,
620
- href: href.toString(),
621
- job: flow.job
622
- }
623
- });
614
+ try {
615
+ const href = new URL(response2.redirect.redirect_url);
616
+ if (anonymous_id && !href.searchParams.has("anonymous_id")) {
617
+ href.searchParams.set("anonymous_id", anonymous_id);
624
618
  }
625
- });
619
+ await chat.sendMessage({
620
+ type: "link",
621
+ href: href.toString(),
622
+ text: response2.redirect.button_text ?? "Complete submission",
623
+ onClick: () => {
624
+ if (!session_id) {
625
+ logger.error("session_id not set, cannot log FLOW_REDIRECT event");
626
+ return;
627
+ }
628
+ analytics.log({
629
+ event: "FLOW_REDIRECT",
630
+ properties: {
631
+ flow_build: flow.build,
632
+ flow_id: flow.id,
633
+ flow_session_id: session_id,
634
+ flow_version: flow.version,
635
+ href: href.toString(),
636
+ job: flow.job
637
+ }
638
+ });
639
+ }
640
+ });
641
+ } catch (e) {
642
+ logger.error(`Invalid redirect URL: ${response2.redirect.redirect_url}`, e);
643
+ chat.sendMessage({
644
+ type: "system",
645
+ variant: "error",
646
+ text: "Couldn’t get the redirect URL."
647
+ });
648
+ }
626
649
  next(node.nextId);
627
650
  }).with({
628
651
  success: true
@@ -1,4 +1,4 @@
1
- import { g as get$1, i as isString$2, k as kbToReadableSize, a as getHeadOrThrow, b as invariant, A as AbortedError, c as getFlowSubmissionsPayload, N, _, d as getDefaultExportFromCjs, h, e as _$1, p, F, o as o$1, f as clsx, y, s as store, j as a$2, l as k, m as k$1, n as getFormSubmitter, q as parse, r as picklist, t as isSubmissionOfType, C as Cn, u as parseAsync, V as ValiError, v as object, w as transform, x as cva, z as maxLength, B as minLength, D as record, E as boolean, G as number, H as minValue, I as maxValue, J as custom, K as string, L as regex, M as email, O as url, P as LoadingIndicator, Q as ERROR_MESSAGES } from "./index-5e2a3998.js";
1
+ import { g as get$1, i as isString$2, k as kbToReadableSize, a as getHeadOrThrow, b as invariant, A as AbortedError, c as getFlowSubmissionsPayload, N, _, d as getDefaultExportFromCjs, h, e as _$1, p, F, o as o$1, f as clsx, y, s as store, j as a$2, l as k, m as k$1, n as getFormSubmitter, q as parse, r as picklist, t as isSubmissionOfType, C as Cn, u as parseAsync, V as ValiError, v as object, w as transform, x as cva, z as maxLength, B as minLength, D as record, E as boolean, G as number, H as minValue, I as maxValue, J as custom, K as string, L as regex, M as email, O as url, P as LoadingIndicator, Q as ERROR_MESSAGES } from "./index-a103d43c.js";
2
2
  import "@inploi/sdk";
3
3
  const isConditionMet = ({
4
4
  condition,
@@ -450,6 +450,13 @@ async function interpret(params) {
450
450
  throw new Error(`Unknown node: ${JSON.stringify(node)}`);
451
451
  }
452
452
  }
453
+ const getSubmissionValue = (submissions, key) => {
454
+ var _a;
455
+ const value = (_a = submissions[key]) == null ? void 0 : _a.value;
456
+ if (typeof value !== "string" && typeof value !== "number")
457
+ throw new Error(`Submission at “${key}” is not a string or number`);
458
+ return value;
459
+ };
453
460
  async function interpretIdentifyNode({
454
461
  next,
455
462
  node,
@@ -457,21 +464,28 @@ async function interpretIdentifyNode({
457
464
  submissions,
458
465
  logger
459
466
  }) {
460
- var _a;
461
467
  if (!submissions)
462
468
  return next(node.nextId);
463
- const identifier = (_a = submissions[node.data.key]) == null ? void 0 : _a.value;
464
- if (typeof identifier !== "string" && typeof identifier !== "number") {
465
- logger.warn(`Failed to identify user, key “${node.data.key}” is not a string or number`);
466
- return next(node.nextId);
469
+ try {
470
+ analytics.log({
471
+ event: "IDENTIFY",
472
+ properties: {
473
+ identifier: getSubmissionValue(submissions, node.data.key).toString(),
474
+ first_name: node.data.firstName ? getSubmissionValue(submissions, node.data.firstName).toString() : void 0,
475
+ last_name: node.data.lastName ? getSubmissionValue(submissions, node.data.lastName).toString() : void 0,
476
+ email: node.data.email ? getSubmissionValue(submissions, node.data.email).toString() : void 0,
477
+ phone_number: node.data.phoneNumber ? getSubmissionValue(submissions, node.data.phoneNumber).toString() : void 0,
478
+ custom_traits: node.data.customTraits ? Object.fromEntries(Object.entries(node.data.customTraits).map(([key, value]) => {
479
+ var _a;
480
+ return [key, (_a = submissions[value]) == null ? void 0 : _a.value];
481
+ })) : void 0
482
+ }
483
+ });
484
+ } catch (e) {
485
+ logger.error(e);
486
+ } finally {
487
+ next(node.nextId);
467
488
  }
468
- analytics.log({
469
- event: "IDENTIFY",
470
- properties: {
471
- identifier: identifier.toString()
472
- }
473
- });
474
- next(node.nextId);
475
489
  }
476
490
  async function interpretJumpNode({
477
491
  next,
@@ -595,32 +609,41 @@ async function interpretSubmitNode({
595
609
  author: "bot",
596
610
  text: response2.redirect.message ?? "Almost there! Please complete your submission here:"
597
611
  });
598
- const href = new URL(response2.redirect.redirect_url);
599
- if (anonymous_id && !href.searchParams.has("anonymous_id")) {
600
- href.searchParams.set("anonymous_id", anonymous_id);
601
- }
602
- await chat.sendMessage({
603
- type: "link",
604
- href: href.toString(),
605
- text: response2.redirect.button_text ?? "Complete submission",
606
- onClick: () => {
607
- if (!session_id) {
608
- logger.error("session_id not set, cannot log FLOW_REDIRECT event");
609
- return;
610
- }
611
- analytics.log({
612
- event: "FLOW_REDIRECT",
613
- properties: {
614
- flow_build: flow.build,
615
- flow_id: flow.id,
616
- flow_session_id: session_id,
617
- flow_version: flow.version,
618
- href: href.toString(),
619
- job: flow.job
620
- }
621
- });
612
+ try {
613
+ const href = new URL(response2.redirect.redirect_url);
614
+ if (anonymous_id && !href.searchParams.has("anonymous_id")) {
615
+ href.searchParams.set("anonymous_id", anonymous_id);
622
616
  }
623
- });
617
+ await chat.sendMessage({
618
+ type: "link",
619
+ href: href.toString(),
620
+ text: response2.redirect.button_text ?? "Complete submission",
621
+ onClick: () => {
622
+ if (!session_id) {
623
+ logger.error("session_id not set, cannot log FLOW_REDIRECT event");
624
+ return;
625
+ }
626
+ analytics.log({
627
+ event: "FLOW_REDIRECT",
628
+ properties: {
629
+ flow_build: flow.build,
630
+ flow_id: flow.id,
631
+ flow_session_id: session_id,
632
+ flow_version: flow.version,
633
+ href: href.toString(),
634
+ job: flow.job
635
+ }
636
+ });
637
+ }
638
+ });
639
+ } catch (e) {
640
+ logger.error(`Invalid redirect URL: ${response2.redirect.redirect_url}`, e);
641
+ chat.sendMessage({
642
+ type: "system",
643
+ variant: "error",
644
+ text: "Couldn’t get the redirect URL."
645
+ });
646
+ }
624
647
  next(node.nextId);
625
648
  }).with({
626
649
  success: true
@@ -203,6 +203,11 @@ export declare const FlowSchema: import("valibot").ObjectSchema<{
203
203
  } | {
204
204
  data: {
205
205
  key: string;
206
+ firstName?: string | undefined;
207
+ lastName?: string | undefined;
208
+ phoneNumber?: string | undefined;
209
+ email?: string | undefined;
210
+ customTraits?: Record<string, any> | undefined;
206
211
  };
207
212
  type: "identify";
208
213
  id: string;
@@ -400,6 +405,11 @@ export declare const FlowSchema: import("valibot").ObjectSchema<{
400
405
  } | {
401
406
  data: {
402
407
  key: string;
408
+ firstName?: string | undefined;
409
+ lastName?: string | undefined;
410
+ phoneNumber?: string | undefined;
411
+ email?: string | undefined;
412
+ customTraits?: Record<string, any> | undefined;
403
413
  };
404
414
  type: "identify";
405
415
  id: string;
@@ -624,6 +634,11 @@ export declare const FlowSchema: import("valibot").ObjectSchema<{
624
634
  } | {
625
635
  data: {
626
636
  key: string;
637
+ firstName?: string | undefined;
638
+ lastName?: string | undefined;
639
+ phoneNumber?: string | undefined;
640
+ email?: string | undefined;
641
+ customTraits?: Record<string, any> | undefined;
627
642
  };
628
643
  type: "identify";
629
644
  id: string;
@@ -835,6 +850,11 @@ export declare const FlowByIdPayloadSchema: import("valibot").ObjectSchema<{
835
850
  } | {
836
851
  data: {
837
852
  key: string;
853
+ firstName?: string | undefined;
854
+ lastName?: string | undefined;
855
+ phoneNumber?: string | undefined;
856
+ email?: string | undefined;
857
+ customTraits?: Record<string, any> | undefined;
838
858
  };
839
859
  type: "identify";
840
860
  id: string;
@@ -1032,6 +1052,11 @@ export declare const FlowByIdPayloadSchema: import("valibot").ObjectSchema<{
1032
1052
  } | {
1033
1053
  data: {
1034
1054
  key: string;
1055
+ firstName?: string | undefined;
1056
+ lastName?: string | undefined;
1057
+ phoneNumber?: string | undefined;
1058
+ email?: string | undefined;
1059
+ customTraits?: Record<string, any> | undefined;
1035
1060
  };
1036
1061
  type: "identify";
1037
1062
  id: string;
@@ -1256,6 +1281,11 @@ export declare const FlowByIdPayloadSchema: import("valibot").ObjectSchema<{
1256
1281
  } | {
1257
1282
  data: {
1258
1283
  key: string;
1284
+ firstName?: string | undefined;
1285
+ lastName?: string | undefined;
1286
+ phoneNumber?: string | undefined;
1287
+ email?: string | undefined;
1288
+ customTraits?: Record<string, any> | undefined;
1259
1289
  };
1260
1290
  type: "identify";
1261
1291
  id: string;
@@ -1466,6 +1496,11 @@ export declare const FlowByIdPayloadSchema: import("valibot").ObjectSchema<{
1466
1496
  } | {
1467
1497
  data: {
1468
1498
  key: string;
1499
+ firstName?: string | undefined;
1500
+ lastName?: string | undefined;
1501
+ phoneNumber?: string | undefined;
1502
+ email?: string | undefined;
1503
+ customTraits?: Record<string, any> | undefined;
1469
1504
  };
1470
1505
  type: "identify";
1471
1506
  id: string;
@@ -1682,6 +1717,11 @@ export declare const FlowByJobPayloadSchema: import("valibot").ObjectSchema<{
1682
1717
  } | {
1683
1718
  data: {
1684
1719
  key: string;
1720
+ firstName?: string | undefined;
1721
+ lastName?: string | undefined;
1722
+ phoneNumber?: string | undefined;
1723
+ email?: string | undefined;
1724
+ customTraits?: Record<string, any> | undefined;
1685
1725
  };
1686
1726
  type: "identify";
1687
1727
  id: string;
@@ -1879,6 +1919,11 @@ export declare const FlowByJobPayloadSchema: import("valibot").ObjectSchema<{
1879
1919
  } | {
1880
1920
  data: {
1881
1921
  key: string;
1922
+ firstName?: string | undefined;
1923
+ lastName?: string | undefined;
1924
+ phoneNumber?: string | undefined;
1925
+ email?: string | undefined;
1926
+ customTraits?: Record<string, any> | undefined;
1882
1927
  };
1883
1928
  type: "identify";
1884
1929
  id: string;
@@ -2103,6 +2148,11 @@ export declare const FlowByJobPayloadSchema: import("valibot").ObjectSchema<{
2103
2148
  } | {
2104
2149
  data: {
2105
2150
  key: string;
2151
+ firstName?: string | undefined;
2152
+ lastName?: string | undefined;
2153
+ phoneNumber?: string | undefined;
2154
+ email?: string | undefined;
2155
+ customTraits?: Record<string, any> | undefined;
2106
2156
  };
2107
2157
  type: "identify";
2108
2158
  id: string;
@@ -2320,6 +2370,11 @@ export declare const FlowByJobPayloadSchema: import("valibot").ObjectSchema<{
2320
2370
  } | {
2321
2371
  data: {
2322
2372
  key: string;
2373
+ firstName?: string | undefined;
2374
+ lastName?: string | undefined;
2375
+ phoneNumber?: string | undefined;
2376
+ email?: string | undefined;
2377
+ customTraits?: Record<string, any> | undefined;
2323
2378
  };
2324
2379
  type: "identify";
2325
2380
  id: string;
@@ -194,6 +194,11 @@ export declare const getHeadOrThrow: (nodes: FlowNode[]) => {
194
194
  } | {
195
195
  data: {
196
196
  key: string;
197
+ firstName?: string | undefined;
198
+ lastName?: string | undefined;
199
+ phoneNumber?: string | undefined;
200
+ email?: string | undefined;
201
+ customTraits?: Record<string, any> | undefined;
197
202
  };
198
203
  type: "identify";
199
204
  id: string;
@@ -5321,7 +5321,7 @@ const StatusBar = ({
5321
5321
  };
5322
5322
  function noop() {
5323
5323
  }
5324
- const ChatbotBody = M(() => Promise.resolve().then(() => require("./chatbot-body-30a036fc.cjs")).then((module2) => module2.ChatbotBody));
5324
+ const ChatbotBody = M(() => Promise.resolve().then(() => require("./chatbot-body-a56a7923.cjs")).then((module2) => module2.ChatbotBody));
5325
5325
  const chatbotContentClass = cva("selection:bg-accent-4 selection:text-accent-12 fixed bottom-2 left-2 right-2 isolate mx-auto max-h-full max-w-[450px] focus:outline-none [&:has(.view-switch:active)]:scale-[0.98] transition-all duration-1000 ease-expo-out", {
5326
5326
  variants: {
5327
5327
  view: {
@@ -5320,7 +5320,7 @@ const StatusBar = ({
5320
5320
  };
5321
5321
  function noop() {
5322
5322
  }
5323
- const ChatbotBody = M(() => import("./chatbot-body-51e9bd34.js").then((module) => module.ChatbotBody));
5323
+ const ChatbotBody = M(() => import("./chatbot-body-e28d969c.js").then((module) => module.ChatbotBody));
5324
5324
  const chatbotContentClass = cva("selection:bg-accent-4 selection:text-accent-12 fixed bottom-2 left-2 right-2 isolate mx-auto max-h-full max-w-[450px] focus:outline-none [&:has(.view-switch:active)]:scale-[0.98] transition-all duration-1000 ease-expo-out", {
5325
5325
  variants: {
5326
5326
  view: {
@@ -1,2 +1,3 @@
1
1
  import { FlowNode } from '@inploi/core/flows';
2
2
  export declare const mockGetFlowEndpoint: (nodes: FlowNode[]) => import("msw").HttpHandler;
3
+ export declare const mockSubmitEndpoint: (response: unknown) => import("msw").HttpHandler;
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const index = require("./index-251fe248.cjs");
3
+ const index = require("./index-1bbddc51.cjs");
4
4
  require("@inploi/sdk");
5
5
  exports.chatbotPlugin = index.chatbotPlugin;
@@ -1,4 +1,4 @@
1
- import { R } from "./index-5e2a3998.js";
1
+ import { R } from "./index-a103d43c.js";
2
2
  import "@inploi/sdk";
3
3
  export {
4
4
  R as chatbotPlugin
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@inploi/plugin-chatbot",
3
- "version": "3.28.4",
3
+ "version": "3.28.6",
4
4
  "type": "module",
5
5
  "main": "dist/plugin-chatbot.js",
6
6
  "types": "dist/index.d.ts",
@@ -67,9 +67,9 @@
67
67
  "vite": "^4.4.5",
68
68
  "vite-plugin-dts": "^3.7.0",
69
69
  "vite-tsconfig-paths": "^4.2.1",
70
- "@inploi/core": "1.14.6",
70
+ "@inploi/core": "1.14.7",
71
71
  "@inploi/design-tokens": "0.2.1",
72
- "@inploi/sdk": "1.14.8",
72
+ "@inploi/sdk": "1.14.9",
73
73
  "eslint-config-custom": "0.1.0",
74
74
  "tsconfig": "0.1.0"
75
75
  },