@inploi/plugin-chatbot 3.22.1 → 3.23.1

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-e1616316.cjs");
3
+ const index = require("./index-fa87308a.cjs");
4
4
  require("@inploi/sdk");
5
5
  const isIfBlockConditionMet = (ifBlock, {
6
6
  context,
@@ -442,10 +442,11 @@ async function interpretSubmitNode({
442
442
  const response = await apiClient.fetch(`/flow/submit`, {
443
443
  method: "POST",
444
444
  body: JSON.stringify({
445
- ...context,
445
+ log_submit: false,
446
446
  integration_id: node.data.integrationId,
447
447
  anonymous_id,
448
448
  session_id,
449
+ ...context,
449
450
  submissions: index.getFlowSubmissionsPayload(submissions || {})
450
451
  })
451
452
  }).catch((e) => e);
@@ -454,6 +455,34 @@ async function interpretSubmitNode({
454
455
  type: "integration",
455
456
  value: response
456
457
  });
458
+ index.N(response).with({
459
+ integration_response: index._.select(index._.union({
460
+ status: index._.number,
461
+ data: index._.any
462
+ }, {
463
+ status: index._.number,
464
+ error: {
465
+ message: index._.string,
466
+ data: index._.any
467
+ }
468
+ }))
469
+ }, (integrationResponse) => {
470
+ analytics.log({
471
+ event: "FLOW_SUBMIT",
472
+ properties: {
473
+ flow_id: flow.id,
474
+ flow_version: flow.version,
475
+ flow_session_id: flow.data.flowSessionId,
476
+ flow_build: flow.build,
477
+ response: {
478
+ status: integrationResponse.status,
479
+ payload: "data" in integrationResponse ? integrationResponse.data : integrationResponse.error.data ?? null
480
+ },
481
+ job: flow.job
482
+ }
483
+ });
484
+ }).otherwise(() => {
485
+ });
457
486
  await index.N(response).with({
458
487
  ats_data: {
459
488
  redirect_url: index._.string
@@ -482,7 +511,8 @@ async function interpretSubmitNode({
482
511
  flow_id: flow.id,
483
512
  flow_session_id: session_id,
484
513
  flow_version: flow.version,
485
- href: href.toString()
514
+ href: href.toString(),
515
+ job: flow.job
486
516
  }
487
517
  });
488
518
  }
@@ -527,14 +557,8 @@ async function interpretLinkNode({
527
557
  next,
528
558
  node,
529
559
  submissions,
530
- context,
531
- analytics,
532
- flow,
533
- logger
560
+ context
534
561
  }) {
535
- const {
536
- session_id
537
- } = analytics.getSessionInfo();
538
562
  await chat.sendMessage({
539
563
  type: "link",
540
564
  href: interpolateWithData(node.data.href, {
@@ -544,21 +568,7 @@ async function interpretLinkNode({
544
568
  text: interpolateWithData(node.data.cta, {
545
569
  submissions,
546
570
  context
547
- }),
548
- onClick: () => {
549
- if (!session_id)
550
- return logger.error("session_id not set, cannot log FLOW_REDIRECT event");
551
- analytics.log({
552
- event: "FLOW_REDIRECT",
553
- properties: {
554
- flow_build: flow.build,
555
- flow_id: flow.id,
556
- flow_session_id: session_id,
557
- flow_version: flow.version,
558
- href: node.data.href
559
- }
560
- });
561
- }
571
+ })
562
572
  });
563
573
  next(node.nextId);
564
574
  }
@@ -4077,7 +4087,8 @@ const ChatbotBody = ({
4077
4087
  flow_id: flow.id,
4078
4088
  flow_version: flow.version,
4079
4089
  flow_session_id: currentApplication.data.flowSessionId,
4080
- flow_build: flow.build
4090
+ flow_build: flow.build,
4091
+ job: flow.job
4081
4092
  },
4082
4093
  customProperties: (_a = flow.analytics) == null ? void 0 : _a.customProperties
4083
4094
  });
@@ -4118,7 +4129,8 @@ const ChatbotBody = ({
4118
4129
  flow_build: flow.build,
4119
4130
  to_node_id: node.id,
4120
4131
  sequence: currentState.data.sequence,
4121
- flow_session_id: currentState.data.flowSessionId
4132
+ flow_session_id: currentState.data.flowSessionId,
4133
+ job: flow.job
4122
4134
  },
4123
4135
  customProperties: (_a2 = flow.analytics) == null ? void 0 : _a2.customProperties
4124
4136
  });
@@ -4136,7 +4148,8 @@ const ChatbotBody = ({
4136
4148
  flow_id: flow.id,
4137
4149
  flow_version: flow.version,
4138
4150
  flow_session_id: currentState.data.flowSessionId,
4139
- flow_build: flow.build
4151
+ flow_build: flow.build,
4152
+ job: flow.job
4140
4153
  },
4141
4154
  customProperties: (_a2 = flow.analytics) == null ? void 0 : _a2.customProperties
4142
4155
  });
@@ -1,4 +1,4 @@
1
- import { g as get$1, i as isString$1, k as kbToReadableSize, a as getHeadOrThrow, b as invariant, A as AbortedError, N, c as getFlowSubmissionsPayload, _, 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 debounce$1, m as k, n as k$1, q as getFormSubmitter, r as parse, t as picklist, u as isSubmissionOfType, C as Cn, v as parseAsync, V as ValiError, w as object, x as transform, z as cva, B as maxLength, D as minLength, E as record, G as boolean, H as number, I as minValue, J as maxValue, K as custom, L as string, M as email, O as url, P as regex, Q as ERROR_MESSAGES } from "./index-794ce056.js";
1
+ import { g as get$1, i as isString$1, k as kbToReadableSize, a as getHeadOrThrow, b as invariant, A as AbortedError, N, c as getFlowSubmissionsPayload, _, 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 debounce$1, m as k, n as k$1, q as getFormSubmitter, r as parse, t as picklist, u as isSubmissionOfType, C as Cn, v as parseAsync, V as ValiError, w as object, x as transform, z as cva, B as maxLength, D as minLength, E as record, G as boolean, H as number, I as minValue, J as maxValue, K as custom, L as string, M as email, O as url, P as regex, Q as ERROR_MESSAGES } from "./index-5b559a08.js";
2
2
  import "@inploi/sdk";
3
3
  const isIfBlockConditionMet = (ifBlock, {
4
4
  context,
@@ -440,10 +440,11 @@ async function interpretSubmitNode({
440
440
  const response = await apiClient.fetch(`/flow/submit`, {
441
441
  method: "POST",
442
442
  body: JSON.stringify({
443
- ...context,
443
+ log_submit: false,
444
444
  integration_id: node.data.integrationId,
445
445
  anonymous_id,
446
446
  session_id,
447
+ ...context,
447
448
  submissions: getFlowSubmissionsPayload(submissions || {})
448
449
  })
449
450
  }).catch((e) => e);
@@ -452,6 +453,34 @@ async function interpretSubmitNode({
452
453
  type: "integration",
453
454
  value: response
454
455
  });
456
+ N(response).with({
457
+ integration_response: _.select(_.union({
458
+ status: _.number,
459
+ data: _.any
460
+ }, {
461
+ status: _.number,
462
+ error: {
463
+ message: _.string,
464
+ data: _.any
465
+ }
466
+ }))
467
+ }, (integrationResponse) => {
468
+ analytics.log({
469
+ event: "FLOW_SUBMIT",
470
+ properties: {
471
+ flow_id: flow.id,
472
+ flow_version: flow.version,
473
+ flow_session_id: flow.data.flowSessionId,
474
+ flow_build: flow.build,
475
+ response: {
476
+ status: integrationResponse.status,
477
+ payload: "data" in integrationResponse ? integrationResponse.data : integrationResponse.error.data ?? null
478
+ },
479
+ job: flow.job
480
+ }
481
+ });
482
+ }).otherwise(() => {
483
+ });
455
484
  await N(response).with({
456
485
  ats_data: {
457
486
  redirect_url: _.string
@@ -480,7 +509,8 @@ async function interpretSubmitNode({
480
509
  flow_id: flow.id,
481
510
  flow_session_id: session_id,
482
511
  flow_version: flow.version,
483
- href: href.toString()
512
+ href: href.toString(),
513
+ job: flow.job
484
514
  }
485
515
  });
486
516
  }
@@ -525,14 +555,8 @@ async function interpretLinkNode({
525
555
  next,
526
556
  node,
527
557
  submissions,
528
- context,
529
- analytics,
530
- flow,
531
- logger
558
+ context
532
559
  }) {
533
- const {
534
- session_id
535
- } = analytics.getSessionInfo();
536
560
  await chat.sendMessage({
537
561
  type: "link",
538
562
  href: interpolateWithData(node.data.href, {
@@ -542,21 +566,7 @@ async function interpretLinkNode({
542
566
  text: interpolateWithData(node.data.cta, {
543
567
  submissions,
544
568
  context
545
- }),
546
- onClick: () => {
547
- if (!session_id)
548
- return logger.error("session_id not set, cannot log FLOW_REDIRECT event");
549
- analytics.log({
550
- event: "FLOW_REDIRECT",
551
- properties: {
552
- flow_build: flow.build,
553
- flow_id: flow.id,
554
- flow_session_id: session_id,
555
- flow_version: flow.version,
556
- href: node.data.href
557
- }
558
- });
559
- }
569
+ })
560
570
  });
561
571
  next(node.nextId);
562
572
  }
@@ -4075,7 +4085,8 @@ const ChatbotBody = ({
4075
4085
  flow_id: flow.id,
4076
4086
  flow_version: flow.version,
4077
4087
  flow_session_id: currentApplication.data.flowSessionId,
4078
- flow_build: flow.build
4088
+ flow_build: flow.build,
4089
+ job: flow.job
4079
4090
  },
4080
4091
  customProperties: (_a = flow.analytics) == null ? void 0 : _a.customProperties
4081
4092
  });
@@ -4116,7 +4127,8 @@ const ChatbotBody = ({
4116
4127
  flow_build: flow.build,
4117
4128
  to_node_id: node.id,
4118
4129
  sequence: currentState.data.sequence,
4119
- flow_session_id: currentState.data.flowSessionId
4130
+ flow_session_id: currentState.data.flowSessionId,
4131
+ job: flow.job
4120
4132
  },
4121
4133
  customProperties: (_a2 = flow.analytics) == null ? void 0 : _a2.customProperties
4122
4134
  });
@@ -4134,7 +4146,8 @@ const ChatbotBody = ({
4134
4146
  flow_id: flow.id,
4135
4147
  flow_version: flow.version,
4136
4148
  flow_session_id: currentState.data.flowSessionId,
4137
- flow_build: flow.build
4149
+ flow_build: flow.build,
4150
+ job: flow.job
4138
4151
  },
4139
4152
  customProperties: (_a2 = flow.analytics) == null ? void 0 : _a2.customProperties
4140
4153
  });
package/dist/chatbot.d.ts CHANGED
@@ -22,6 +22,12 @@ export type OpenChatbotParams = {
22
22
  context?: Record<string, unknown>;
23
23
  /** Title to display in the status bar */
24
24
  title: string;
25
+ job?: {
26
+ id: string;
27
+ /** Whether the job id is an internal (inploi) or external.
28
+ * Use `external` if unsure */
29
+ id_type: 'internal' | 'external';
30
+ };
25
31
  };
26
32
  export declare const chatbotPlugin: ({ _internal_domManager: dom, theme, }: {
27
33
  theme: {
@@ -34,7 +40,7 @@ export declare const chatbotPlugin: ({ _internal_domManager: dom, theme, }: {
34
40
  /** @deprecated For internal usage only */
35
41
  _internal_domManager?: ChatbotDomManager;
36
42
  }) => ({ apiClient, logger, analytics }: {
37
- apiClient: import("@inploi/sdk").ApiClient;
43
+ apiClient: import("@inploi/sdk").ApiClient; /** Optionally eagerly renders the interface ahead of needing the chatbot. */
38
44
  logger: Logger;
39
45
  analytics: import("@inploi/sdk").AnalyticsService;
40
46
  }) => {
@@ -46,10 +52,6 @@ export declare const chatbotPlugin: ({ _internal_domManager: dom, theme, }: {
46
52
  fetchFlowByJobId: (jobId: string, additionalProperties?: Partial<OpenChatbotParams>) => Promise<OpenChatbotParams>;
47
53
  fetchFlowById: (flowId: string, additionalProperties?: Partial<OpenChatbotParams>) => Promise<OpenChatbotParams>;
48
54
  open: (params: OpenChatbotParams | Promise<OpenChatbotParams>) => Promise<void>;
49
- /** @deprecated - Please use `open` instead. */
50
- startApplication: never;
51
- /** @deprecated - Please use `close` instead */
52
- closeApplication: never;
53
55
  close: () => Promise<void>;
54
56
  };
55
57
  export {};
@@ -9,6 +9,7 @@ export type StartedFlow = Flow & {
9
9
  data: FlowStateData;
10
10
  startedAt: Date;
11
11
  context: Record<string, unknown>;
12
+ job: OpenChatbotParams['job'];
12
13
  nodeIdToProgress: Record<string, ChatbotFlowProgress>;
13
14
  analytics: OpenChatbotParams['analytics'];
14
15
  };
@@ -33,7 +34,7 @@ export declare const store: {
33
34
  current$: import("@preact/signals").Signal<CurrentFlow>;
34
35
  viewState$: import("@preact/signals").Signal<"maximised" | "minimised" | "closed">;
35
36
  inputHeight$: import("@preact/signals").Signal<number>;
36
- startFlow: ({ flow, context, flowKeys, title, analytics }: OpenChatbotParams) => Promise<void>;
37
+ startFlow: ({ flow, context, flowKeys, title, analytics, job }: OpenChatbotParams) => Promise<void>;
37
38
  cancelCurrentFlow: () => void;
38
39
  markAsFinished: () => void;
39
40
  setCurrentNodeId: (currentNodeId: string) => void;
@@ -4972,7 +4972,8 @@ const store = {
4972
4972
  context = {},
4973
4973
  flowKeys,
4974
4974
  title,
4975
- analytics
4975
+ analytics,
4976
+ job
4976
4977
  }) => {
4977
4978
  const data = await idb.getStateData(flow, flowKeys) ?? initialiseFlowStateData();
4978
4979
  const startedFlow = {
@@ -4986,7 +4987,8 @@ const store = {
4986
4987
  build: flow.build,
4987
4988
  context,
4988
4989
  title,
4989
- analytics
4990
+ analytics,
4991
+ job
4990
4992
  };
4991
4993
  currentFlow.value = {
4992
4994
  state: "loaded",
@@ -5312,7 +5314,7 @@ const StatusBar = ({
5312
5314
  })
5313
5315
  });
5314
5316
  };
5315
- const ChatbotBody = M(() => import("./chatbot-body-8e509812.js").then((module) => module.ChatbotBody));
5317
+ const ChatbotBody = M(() => import("./chatbot-body-91e04292.js").then((module) => module.ChatbotBody));
5316
5318
  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", {
5317
5319
  variants: {
5318
5320
  view: {
@@ -5734,21 +5736,16 @@ const chatbotPlugin = ({
5734
5736
  * @param jobId - The job ID to fetch the flow for. This is the job ID according to the **ATS**, and not the inploi job ID.
5735
5737
  */
5736
5738
  fetchFlowByJobId: async (jobId, additionalProperties) => apiClient.fetch(`/flow/job/${jobId}`).then((res) => {
5737
- var _a;
5738
5739
  const data = parse$1(FlowByJobPayloadSchema, res);
5739
5740
  return {
5740
5741
  flow: data.flow,
5741
5742
  title: `Applying for “${data.job.title}”`,
5742
5743
  flowKeys: [data.job.id, ...(additionalProperties == null ? void 0 : additionalProperties.flowKeys) ?? []],
5743
- ...additionalProperties,
5744
- analytics: {
5745
- customProperties: {
5746
- job_id: data.job.id,
5747
- flow_id: data.flow.id,
5748
- flow_version: data.flow.version,
5749
- ...(_a = additionalProperties == null ? void 0 : additionalProperties.analytics) == null ? void 0 : _a.customProperties
5750
- }
5751
- }
5744
+ job: {
5745
+ id: data.job.id,
5746
+ id_type: "external"
5747
+ },
5748
+ ...additionalProperties
5752
5749
  };
5753
5750
  }),
5754
5751
  fetchFlowById: async (flowId, additionalProperties) => apiClient.fetch(`/flow/id/${flowId}`).then((res) => {
@@ -5806,10 +5803,6 @@ const chatbotPlugin = ({
5806
5803
  logger.error("Error starting flow", error);
5807
5804
  }
5808
5805
  },
5809
- /** @deprecated - Please use `open` instead. */
5810
- startApplication: void 0,
5811
- /** @deprecated - Please use `close` instead */
5812
- closeApplication: void 0,
5813
5806
  close: async () => {
5814
5807
  if (typeof window === "undefined")
5815
5808
  return;
@@ -4973,7 +4973,8 @@ const store = {
4973
4973
  context = {},
4974
4974
  flowKeys,
4975
4975
  title,
4976
- analytics
4976
+ analytics,
4977
+ job
4977
4978
  }) => {
4978
4979
  const data = await idb.getStateData(flow, flowKeys) ?? initialiseFlowStateData();
4979
4980
  const startedFlow = {
@@ -4987,7 +4988,8 @@ const store = {
4987
4988
  build: flow.build,
4988
4989
  context,
4989
4990
  title,
4990
- analytics
4991
+ analytics,
4992
+ job
4991
4993
  };
4992
4994
  currentFlow.value = {
4993
4995
  state: "loaded",
@@ -5313,7 +5315,7 @@ const StatusBar = ({
5313
5315
  })
5314
5316
  });
5315
5317
  };
5316
- const ChatbotBody = M(() => Promise.resolve().then(() => require("./chatbot-body-7dbeea50.cjs")).then((module2) => module2.ChatbotBody));
5318
+ const ChatbotBody = M(() => Promise.resolve().then(() => require("./chatbot-body-36cdbd00.cjs")).then((module2) => module2.ChatbotBody));
5317
5319
  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", {
5318
5320
  variants: {
5319
5321
  view: {
@@ -5735,21 +5737,16 @@ const chatbotPlugin = ({
5735
5737
  * @param jobId - The job ID to fetch the flow for. This is the job ID according to the **ATS**, and not the inploi job ID.
5736
5738
  */
5737
5739
  fetchFlowByJobId: async (jobId, additionalProperties) => apiClient.fetch(`/flow/job/${jobId}`).then((res) => {
5738
- var _a;
5739
5740
  const data = parse$1(FlowByJobPayloadSchema, res);
5740
5741
  return {
5741
5742
  flow: data.flow,
5742
5743
  title: `Applying for “${data.job.title}”`,
5743
5744
  flowKeys: [data.job.id, ...(additionalProperties == null ? void 0 : additionalProperties.flowKeys) ?? []],
5744
- ...additionalProperties,
5745
- analytics: {
5746
- customProperties: {
5747
- job_id: data.job.id,
5748
- flow_id: data.flow.id,
5749
- flow_version: data.flow.version,
5750
- ...(_a = additionalProperties == null ? void 0 : additionalProperties.analytics) == null ? void 0 : _a.customProperties
5751
- }
5752
- }
5745
+ job: {
5746
+ id: data.job.id,
5747
+ id_type: "external"
5748
+ },
5749
+ ...additionalProperties
5753
5750
  };
5754
5751
  }),
5755
5752
  fetchFlowById: async (flowId, additionalProperties) => apiClient.fetch(`/flow/id/${flowId}`).then((res) => {
@@ -5807,10 +5804,6 @@ const chatbotPlugin = ({
5807
5804
  logger.error("Error starting flow", error);
5808
5805
  }
5809
5806
  },
5810
- /** @deprecated - Please use `open` instead. */
5811
- startApplication: void 0,
5812
- /** @deprecated - Please use `close` instead */
5813
- closeApplication: void 0,
5814
5807
  close: async () => {
5815
5808
  if (typeof window === "undefined")
5816
5809
  return;
@@ -35,8 +35,6 @@ type ChatbotInterpreterParams = {
35
35
  flow: StartedFlow;
36
36
  getSubmissions: () => KeyToSubmissionMap | undefined;
37
37
  chatService: ChatService;
38
- /** When interpreter starts */
39
- beforeStart?: (firstNode: FlowNode) => Promise<void>;
40
38
  /** When flow has no more nodes to interpret */
41
39
  onFlowEnd?: (lastNode: FlowNode) => void;
42
40
  /** When node is interpreted */
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const index = require("./index-e1616316.cjs");
3
+ const index = require("./index-fa87308a.cjs");
4
4
  require("@inploi/sdk");
5
5
  exports.chatbotPlugin = index.chatbotPlugin;
@@ -1,4 +1,4 @@
1
- import { R } from "./index-794ce056.js";
1
+ import { R } from "./index-5b559a08.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.22.1",
3
+ "version": "3.23.1",
4
4
  "type": "module",
5
5
  "main": "dist/plugin-chatbot.js",
6
6
  "types": "dist/index.d.ts",
@@ -68,8 +68,8 @@
68
68
  "vite-tsconfig-paths": "^4.2.1",
69
69
  "@inploi/core": "1.14.2",
70
70
  "@inploi/design-tokens": "0.2.1",
71
+ "@inploi/sdk": "1.14.3",
71
72
  "eslint-config-custom": "0.1.0",
72
- "@inploi/sdk": "1.14.1",
73
73
  "tsconfig": "0.1.0"
74
74
  },
75
75
  "msw": {