@inploi/plugin-chatbot 3.28.3 → 3.28.5

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 (45) hide show
  1. package/cdn/index.js +7 -7
  2. package/dist/{chatbot-body-b09f390e.cjs → chatbot-body-37310a05.cjs} +79 -49
  3. package/dist/{chatbot-body-dd8b2ce7.js → chatbot-body-3937530b.js} +79 -49
  4. package/dist/chatbot.api.d.ts +220 -22
  5. package/dist/chatbot.utils.d.ts +20 -2
  6. package/dist/components/chat-bubble.d.ts +10 -0
  7. package/dist/components/chat-error.d.ts +3 -0
  8. package/dist/components/chat-input/chat-input.address.d.ts +16 -0
  9. package/dist/components/chat-input/chat-input.boolean.d.ts +21 -0
  10. package/dist/components/chat-input/chat-input.constants.d.ts +249 -0
  11. package/dist/components/chat-input/chat-input.d.ts +18 -0
  12. package/dist/components/chat-input/chat-input.file.d.ts +18 -0
  13. package/dist/components/chat-input/chat-input.multiple-choice.d.ts +16 -0
  14. package/dist/components/chat-input/chat-input.number.d.ts +16 -0
  15. package/dist/components/chat-input/chat-input.phone-number.d.ts +15 -0
  16. package/dist/components/chat-input/chat-input.phone-number.utils.d.ts +4 -0
  17. package/dist/components/chat-input/chat-input.submit.d.ts +10 -0
  18. package/dist/components/chat-input/chat-input.text.d.ts +17 -0
  19. package/dist/components/chat-loading.d.ts +1 -0
  20. package/dist/components/chatbot-body.d.ts +8 -0
  21. package/dist/components/chatbot.d.ts +8 -0
  22. package/dist/components/conversation.d.ts +4 -0
  23. package/dist/components/input-error.d.ts +5 -0
  24. package/dist/components/loading-indicator.d.ts +2 -0
  25. package/dist/components/message.link.d.ts +4 -0
  26. package/dist/components/palette-debugger.d.ts +1 -0
  27. package/dist/components/send-button.d.ts +2 -0
  28. package/dist/components/skip-button.d.ts +2 -0
  29. package/dist/components/status-bar.d.ts +4 -0
  30. package/dist/components/transition.d.ts +1 -0
  31. package/dist/components/typing-indicator.d.ts +2 -0
  32. package/dist/components/useChatService.d.ts +14 -0
  33. package/dist/components/useFocus.d.ts +1 -0
  34. package/dist/{index-70d48f50.cjs → index-a5203fc5.cjs} +1 -1
  35. package/dist/{index-430056cf.js → index-d86fb8f9.js} +1 -1
  36. package/dist/mocks/browser.d.ts +1 -0
  37. package/dist/mocks/flows.mocks.d.ts +71 -0
  38. package/dist/mocks/handlers.d.ts +14 -0
  39. package/dist/mocks/mocks.utils.d.ts +3 -0
  40. package/dist/plugin-chatbot.cjs +1 -1
  41. package/dist/plugin-chatbot.js +1 -1
  42. package/dist/style/theme.d.ts +2 -0
  43. package/dist/style/theme.utils.d.ts +5 -0
  44. package/dist/style/tokens.d.ts +88 -0
  45. package/package.json +3 -3
@@ -1,12 +1,14 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const index = require("./index-70d48f50.cjs");
3
+ const index = require("./index-a5203fc5.cjs");
4
4
  require("@inploi/sdk");
5
- const isIfBlockConditionMet = (ifBlock, {
5
+ const isConditionMet = ({
6
+ condition,
6
7
  context,
7
- submissions
8
+ submissions,
9
+ ifBlock
8
10
  }) => {
9
- const [firstSegment, ...path] = ifBlock.data.compareKey.split(".");
11
+ const [firstSegment, ...path] = condition.compareKey.split(".");
10
12
  if (!firstSegment)
11
13
  return false;
12
14
  const answer = getSubmissionValueToCheck({
@@ -20,19 +22,19 @@ const isIfBlockConditionMet = (ifBlock, {
20
22
  switch (answer.type) {
21
23
  case "address": {
22
24
  const value = index.get(answer.value, path.join("."));
23
- switch (ifBlock.data.compare) {
25
+ switch (condition.compare) {
24
26
  case "equals":
25
- return value === ifBlock.data.compareValue;
27
+ return value === condition.compareValue;
26
28
  case "contains":
27
29
  if (!value)
28
30
  return false;
29
- return value.includes(ifBlock.data.compareValue);
31
+ return value.includes(condition.compareValue);
30
32
  case "notEquals":
31
- return value !== ifBlock.data.compareValue;
33
+ return value !== condition.compareValue;
32
34
  case "notContains":
33
35
  if (!value)
34
36
  return true;
35
- return !value.includes(ifBlock.data.compareValue);
37
+ return !value.includes(condition.compareValue);
36
38
  }
37
39
  break;
38
40
  }
@@ -97,8 +99,8 @@ const isIfBlockConditionMet = (ifBlock, {
97
99
  break;
98
100
  }
99
101
  case "boolean": {
100
- const compareBoolean = ifBlock.data.compareValue === "true";
101
- switch (ifBlock.data.compare) {
102
+ const compareBoolean = condition.compareValue === "true";
103
+ switch (condition.compare) {
102
104
  case "equals":
103
105
  return answer.value === compareBoolean;
104
106
  case "notEquals":
@@ -107,25 +109,25 @@ const isIfBlockConditionMet = (ifBlock, {
107
109
  break;
108
110
  }
109
111
  case "string":
110
- switch (ifBlock.data.compare) {
112
+ switch (condition.compare) {
111
113
  case "equals":
112
- return answer.value === ifBlock.data.compareValue;
114
+ return answer.value === condition.compareValue;
113
115
  case "contains":
114
116
  if (!answer.value)
115
117
  return false;
116
- return answer.value.includes(ifBlock.data.compareValue);
118
+ return answer.value.includes(condition.compareValue);
117
119
  case "notEquals":
118
- return answer.value !== ifBlock.data.compareValue;
120
+ return answer.value !== condition.compareValue;
119
121
  case "notContains":
120
122
  if (!answer.value)
121
123
  return true;
122
- return !answer.value.includes(ifBlock.data.compareValue);
124
+ return !answer.value.includes(condition.compareValue);
123
125
  }
124
126
  break;
125
127
  case "number": {
126
128
  try {
127
- const compareNumber = Number(ifBlock.data.compareValue);
128
- switch (ifBlock.data.compare) {
129
+ const compareNumber = Number(condition.compareValue);
130
+ switch (condition.compare) {
129
131
  case "equals":
130
132
  return answer.value === compareNumber;
131
133
  case "notEquals":
@@ -146,19 +148,38 @@ const isIfBlockConditionMet = (ifBlock, {
146
148
  break;
147
149
  }
148
150
  case "enum":
149
- switch (ifBlock.data.compare) {
151
+ switch (condition.compare) {
150
152
  case "equals":
151
- return answer.value.length === 1 && answer.value[0] === ifBlock.data.compareValue;
153
+ return answer.value.length === 1 && answer.value[0] === condition.compareValue;
152
154
  case "notEquals":
153
- return answer.value.length === 1 && answer.value[0] !== ifBlock.data.compareValue;
155
+ return answer.value.length === 1 && answer.value[0] !== condition.compareValue;
154
156
  case "contains":
155
- return answer.value.includes(ifBlock.data.compareValue);
157
+ return answer.value.includes(condition.compareValue);
156
158
  case "notContains":
157
- return !answer.value.includes(ifBlock.data.compareValue);
159
+ return !answer.value.includes(condition.compareValue);
158
160
  }
159
161
  break;
160
162
  }
161
- return false;
163
+ };
164
+ const isIfBlockConditionMet = (ifBlock, {
165
+ context,
166
+ submissions
167
+ }) => {
168
+ const conditions = "combinator" in ifBlock.data ? ifBlock.data.conditions : [ifBlock.data];
169
+ const combinator = "combinator" in ifBlock.data ? ifBlock.data.combinator : "and";
170
+ for (const condition of conditions) {
171
+ const isMet = isConditionMet({
172
+ condition,
173
+ context,
174
+ submissions,
175
+ ifBlock
176
+ });
177
+ if (combinator === "or" && isMet)
178
+ return true;
179
+ if (combinator === "and" && !isMet)
180
+ return false;
181
+ }
182
+ return true;
162
183
  };
163
184
  const HANDLEBARS_REGEXP = /{{\s*([^}]+?)\s*(?:\|\s*([^}]+?)\s*)?}}/g;
164
185
  const interpolateWithData = (str, {
@@ -576,32 +597,41 @@ async function interpretSubmitNode({
576
597
  author: "bot",
577
598
  text: response2.redirect.message ?? "Almost there! Please complete your submission here:"
578
599
  });
579
- const href = new URL(response2.redirect.redirect_url);
580
- if (anonymous_id && !href.searchParams.has("anonymous_id")) {
581
- href.searchParams.set("anonymous_id", anonymous_id);
582
- }
583
- await chat.sendMessage({
584
- type: "link",
585
- href: href.toString(),
586
- text: response2.redirect.button_text ?? "Complete submission",
587
- onClick: () => {
588
- if (!session_id) {
589
- logger.error("session_id not set, cannot log FLOW_REDIRECT event");
590
- return;
591
- }
592
- analytics.log({
593
- event: "FLOW_REDIRECT",
594
- properties: {
595
- flow_build: flow.build,
596
- flow_id: flow.id,
597
- flow_session_id: session_id,
598
- flow_version: flow.version,
599
- href: href.toString(),
600
- job: flow.job
601
- }
602
- });
600
+ try {
601
+ const href = new URL(response2.redirect.redirect_url);
602
+ if (anonymous_id && !href.searchParams.has("anonymous_id")) {
603
+ href.searchParams.set("anonymous_id", anonymous_id);
603
604
  }
604
- });
605
+ await chat.sendMessage({
606
+ type: "link",
607
+ href: href.toString(),
608
+ text: response2.redirect.button_text ?? "Complete submission",
609
+ onClick: () => {
610
+ if (!session_id) {
611
+ logger.error("session_id not set, cannot log FLOW_REDIRECT event");
612
+ return;
613
+ }
614
+ analytics.log({
615
+ event: "FLOW_REDIRECT",
616
+ properties: {
617
+ flow_build: flow.build,
618
+ flow_id: flow.id,
619
+ flow_session_id: session_id,
620
+ flow_version: flow.version,
621
+ href: href.toString(),
622
+ job: flow.job
623
+ }
624
+ });
625
+ }
626
+ });
627
+ } catch (e) {
628
+ logger.error(`Invalid redirect URL: ${response2.redirect.redirect_url}`, e);
629
+ chat.sendMessage({
630
+ type: "system",
631
+ variant: "error",
632
+ text: "Couldn’t get the redirect URL."
633
+ });
634
+ }
605
635
  next(node.nextId);
606
636
  }).with({
607
637
  success: true
@@ -1,10 +1,12 @@
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-430056cf.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-d86fb8f9.js";
2
2
  import "@inploi/sdk";
3
- const isIfBlockConditionMet = (ifBlock, {
3
+ const isConditionMet = ({
4
+ condition,
4
5
  context,
5
- submissions
6
+ submissions,
7
+ ifBlock
6
8
  }) => {
7
- const [firstSegment, ...path] = ifBlock.data.compareKey.split(".");
9
+ const [firstSegment, ...path] = condition.compareKey.split(".");
8
10
  if (!firstSegment)
9
11
  return false;
10
12
  const answer = getSubmissionValueToCheck({
@@ -18,19 +20,19 @@ const isIfBlockConditionMet = (ifBlock, {
18
20
  switch (answer.type) {
19
21
  case "address": {
20
22
  const value = get$1(answer.value, path.join("."));
21
- switch (ifBlock.data.compare) {
23
+ switch (condition.compare) {
22
24
  case "equals":
23
- return value === ifBlock.data.compareValue;
25
+ return value === condition.compareValue;
24
26
  case "contains":
25
27
  if (!value)
26
28
  return false;
27
- return value.includes(ifBlock.data.compareValue);
29
+ return value.includes(condition.compareValue);
28
30
  case "notEquals":
29
- return value !== ifBlock.data.compareValue;
31
+ return value !== condition.compareValue;
30
32
  case "notContains":
31
33
  if (!value)
32
34
  return true;
33
- return !value.includes(ifBlock.data.compareValue);
35
+ return !value.includes(condition.compareValue);
34
36
  }
35
37
  break;
36
38
  }
@@ -95,8 +97,8 @@ const isIfBlockConditionMet = (ifBlock, {
95
97
  break;
96
98
  }
97
99
  case "boolean": {
98
- const compareBoolean = ifBlock.data.compareValue === "true";
99
- switch (ifBlock.data.compare) {
100
+ const compareBoolean = condition.compareValue === "true";
101
+ switch (condition.compare) {
100
102
  case "equals":
101
103
  return answer.value === compareBoolean;
102
104
  case "notEquals":
@@ -105,25 +107,25 @@ const isIfBlockConditionMet = (ifBlock, {
105
107
  break;
106
108
  }
107
109
  case "string":
108
- switch (ifBlock.data.compare) {
110
+ switch (condition.compare) {
109
111
  case "equals":
110
- return answer.value === ifBlock.data.compareValue;
112
+ return answer.value === condition.compareValue;
111
113
  case "contains":
112
114
  if (!answer.value)
113
115
  return false;
114
- return answer.value.includes(ifBlock.data.compareValue);
116
+ return answer.value.includes(condition.compareValue);
115
117
  case "notEquals":
116
- return answer.value !== ifBlock.data.compareValue;
118
+ return answer.value !== condition.compareValue;
117
119
  case "notContains":
118
120
  if (!answer.value)
119
121
  return true;
120
- return !answer.value.includes(ifBlock.data.compareValue);
122
+ return !answer.value.includes(condition.compareValue);
121
123
  }
122
124
  break;
123
125
  case "number": {
124
126
  try {
125
- const compareNumber = Number(ifBlock.data.compareValue);
126
- switch (ifBlock.data.compare) {
127
+ const compareNumber = Number(condition.compareValue);
128
+ switch (condition.compare) {
127
129
  case "equals":
128
130
  return answer.value === compareNumber;
129
131
  case "notEquals":
@@ -144,19 +146,38 @@ const isIfBlockConditionMet = (ifBlock, {
144
146
  break;
145
147
  }
146
148
  case "enum":
147
- switch (ifBlock.data.compare) {
149
+ switch (condition.compare) {
148
150
  case "equals":
149
- return answer.value.length === 1 && answer.value[0] === ifBlock.data.compareValue;
151
+ return answer.value.length === 1 && answer.value[0] === condition.compareValue;
150
152
  case "notEquals":
151
- return answer.value.length === 1 && answer.value[0] !== ifBlock.data.compareValue;
153
+ return answer.value.length === 1 && answer.value[0] !== condition.compareValue;
152
154
  case "contains":
153
- return answer.value.includes(ifBlock.data.compareValue);
155
+ return answer.value.includes(condition.compareValue);
154
156
  case "notContains":
155
- return !answer.value.includes(ifBlock.data.compareValue);
157
+ return !answer.value.includes(condition.compareValue);
156
158
  }
157
159
  break;
158
160
  }
159
- return false;
161
+ };
162
+ const isIfBlockConditionMet = (ifBlock, {
163
+ context,
164
+ submissions
165
+ }) => {
166
+ const conditions = "combinator" in ifBlock.data ? ifBlock.data.conditions : [ifBlock.data];
167
+ const combinator = "combinator" in ifBlock.data ? ifBlock.data.combinator : "and";
168
+ for (const condition of conditions) {
169
+ const isMet = isConditionMet({
170
+ condition,
171
+ context,
172
+ submissions,
173
+ ifBlock
174
+ });
175
+ if (combinator === "or" && isMet)
176
+ return true;
177
+ if (combinator === "and" && !isMet)
178
+ return false;
179
+ }
180
+ return true;
160
181
  };
161
182
  const HANDLEBARS_REGEXP = /{{\s*([^}]+?)\s*(?:\|\s*([^}]+?)\s*)?}}/g;
162
183
  const interpolateWithData = (str, {
@@ -574,32 +595,41 @@ async function interpretSubmitNode({
574
595
  author: "bot",
575
596
  text: response2.redirect.message ?? "Almost there! Please complete your submission here:"
576
597
  });
577
- const href = new URL(response2.redirect.redirect_url);
578
- if (anonymous_id && !href.searchParams.has("anonymous_id")) {
579
- href.searchParams.set("anonymous_id", anonymous_id);
580
- }
581
- await chat.sendMessage({
582
- type: "link",
583
- href: href.toString(),
584
- text: response2.redirect.button_text ?? "Complete submission",
585
- onClick: () => {
586
- if (!session_id) {
587
- logger.error("session_id not set, cannot log FLOW_REDIRECT event");
588
- return;
589
- }
590
- analytics.log({
591
- event: "FLOW_REDIRECT",
592
- properties: {
593
- flow_build: flow.build,
594
- flow_id: flow.id,
595
- flow_session_id: session_id,
596
- flow_version: flow.version,
597
- href: href.toString(),
598
- job: flow.job
599
- }
600
- });
598
+ try {
599
+ const href = new URL(response2.redirect.redirect_url);
600
+ if (anonymous_id && !href.searchParams.has("anonymous_id")) {
601
+ href.searchParams.set("anonymous_id", anonymous_id);
601
602
  }
602
- });
603
+ await chat.sendMessage({
604
+ type: "link",
605
+ href: href.toString(),
606
+ text: response2.redirect.button_text ?? "Complete submission",
607
+ onClick: () => {
608
+ if (!session_id) {
609
+ logger.error("session_id not set, cannot log FLOW_REDIRECT event");
610
+ return;
611
+ }
612
+ analytics.log({
613
+ event: "FLOW_REDIRECT",
614
+ properties: {
615
+ flow_build: flow.build,
616
+ flow_id: flow.id,
617
+ flow_session_id: session_id,
618
+ flow_version: flow.version,
619
+ href: href.toString(),
620
+ job: flow.job
621
+ }
622
+ });
623
+ }
624
+ });
625
+ } catch (e) {
626
+ logger.error(`Invalid redirect URL: ${response2.redirect.redirect_url}`, e);
627
+ chat.sendMessage({
628
+ type: "system",
629
+ variant: "error",
630
+ text: "Couldn’t get the redirect URL."
631
+ });
632
+ }
603
633
  next(node.nextId);
604
634
  }).with({
605
635
  success: true