@inploi/plugin-chatbot 3.24.0 → 3.26.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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const index = require("./index-6d177413.cjs");
3
+ const index = require("./index-00f143ae.cjs");
4
4
  require("@inploi/sdk");
5
5
  const isIfBlockConditionMet = (ifBlock, {
6
6
  context,
@@ -430,9 +430,7 @@ async function interpretSubmitNode({
430
430
  });
431
431
  }
432
432
  await chat.sendMessage({
433
- type: "system",
434
- variant: "info",
435
- text: "Submitting…"
433
+ type: "loading"
436
434
  });
437
435
  const {
438
436
  anonymous_id,
@@ -482,17 +480,25 @@ async function interpretSubmitNode({
482
480
  });
483
481
  }).otherwise(() => {
484
482
  });
485
- await index.N(response).with({
486
- ats_data: {
483
+ await index.N(response).with(index._.union({
484
+ ats_data: index._.select("redirect", {
487
485
  redirect_url: index._.string
486
+ })
487
+ }, {
488
+ integration_response: {
489
+ data: index._.select("redirect", {
490
+ redirect_url: index._.string
491
+ })
488
492
  }
489
- }, async (response2) => {
493
+ }), async (response2) => {
494
+ if (response2.redirect === void 0)
495
+ return;
490
496
  await chat.sendMessage({
491
497
  type: "text",
492
498
  author: "bot",
493
499
  text: "Almost there! Please complete your submission here:"
494
500
  });
495
- const href = new URL(response2.ats_data.redirect_url);
501
+ const href = new URL(response2.redirect.redirect_url);
496
502
  if (anonymous_id && !href.searchParams.has("anonymous_id")) {
497
503
  href.searchParams.set("anonymous_id", anonymous_id);
498
504
  }
@@ -501,8 +507,10 @@ async function interpretSubmitNode({
501
507
  href: href.toString(),
502
508
  text: "Complete submission",
503
509
  onClick: () => {
504
- if (!session_id)
505
- return logger.error("session_id not set, cannot log FLOW_REDIRECT event");
510
+ if (!session_id) {
511
+ logger.error("session_id not set, cannot log FLOW_REDIRECT event");
512
+ return;
513
+ }
506
514
  analytics.log({
507
515
  event: "FLOW_REDIRECT",
508
516
  properties: {
@@ -526,17 +534,24 @@ async function interpretSubmitNode({
526
534
  text: "Submission completed!"
527
535
  });
528
536
  next(node.nextId);
529
- }).with({
530
- sucess: false,
531
- ats_data: {
537
+ }).with(index._.union({
538
+ success: false,
539
+ ats_data: index._.select("error", {
532
540
  message: index._.string
541
+ })
542
+ }, {
543
+ integration_response: {
544
+ error: index._.select("error", {
545
+ message: index._.string
546
+ })
533
547
  }
534
- }, async (response2) => {
535
- logger.error(response2.ats_data);
548
+ }), async (response2) => {
549
+ var _a;
550
+ logger.error(response2.error);
536
551
  await chat.sendMessage({
537
552
  type: "system",
538
553
  variant: "error",
539
- text: response2.ats_data.message
554
+ text: ((_a = response2.error) == null ? void 0 : _a.message) || "Failed to submit"
540
555
  });
541
556
  await submit(false);
542
557
  }).otherwise(async (response2) => {
@@ -628,14 +643,24 @@ async function interpretQuestionTextNode({
628
643
  context
629
644
  })
630
645
  });
631
- const reply = await chat.userInput({
646
+ const reply = node.data.format === "phone" ? await chat.userInput({
647
+ key: node.data.key,
648
+ type: "phone",
649
+ config: {
650
+ optional: node.data.optional,
651
+ placeholder: node.data.placeholder,
652
+ maxChars: node.data.maxChars,
653
+ minChars: node.data.minChars
654
+ }
655
+ }) : await chat.userInput({
632
656
  key: node.data.key,
633
657
  type: "text",
634
658
  config: {
635
659
  optional: node.data.optional,
636
660
  placeholder: node.data.placeholder,
637
661
  format: node.data.format,
638
- maxChars: node.data.maxChars
662
+ maxChars: node.data.maxChars,
663
+ minChars: node.data.minChars
639
664
  }
640
665
  });
641
666
  if (reply === null) {
@@ -1232,7 +1257,256 @@ const SkipButton = ({
1232
1257
  })]
1233
1258
  }), "Skip"]
1234
1259
  });
1235
- const countryNames = ["Afghanistan", "Albania", "Algeria", "American Samoa", "Andorra", "Angola", "Anguilla", "Antarctica", "Antigua and Barbuda", "Argentina", "Armenia", "Aruba", "Australia", "Austria", "Azerbaijan", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda", "Bhutan", "Bolivia", "Bosnia and Herzegovina", "Botswana", "Bouvet Island", "Brazil", "British Indian Ocean Territory", "British Virgin Islands", "Brunei", "Bulgaria", "Burkina Faso", "Burundi", "Cabo Verde", "Cambodia", "Cameroon", "Canada", "Caribbean Netherlands", "Cayman Islands", "Central African Republic", "Chad", "Chile", "China", "Christmas Island", "Cocos (Keeling) Islands", "Colombia", "Comoros", "Cook Islands", "Costa Rica", "Croatia", "Cuba", "Curaçao", "Cyprus", "Czechia", "Côte d'Ivoire", "Democratic Republic of the Congo", "Denmark", "Djibouti", "Dominican Republic", "Ecuador", "Egypt", "El Salvador", "Equatorial Guinea", "Eritrea", "Estonia", "Eswatini", "Ethiopia", "Falkland Islands (Islas Malvinas)", "Faroe Islands", "Fiji", "Finland", "France", "French Guiana", "French Polynesia", "French Southern and Antarctic Lands", "Gabon", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Greenland", "Grenada", "Guadeloupe", "Guam", "Guatemala", "Guernsey", "Guinea", "Guinea-Bissau", "Guyana", "Haiti", "Heard Island and McDonald Islands", "Honduras", "Hong Kong", "Hungary", "Iceland", "India", "Indonesia", "Iran", "Iraq", "Ireland", "Isle of Man", "Israel", "Italy", "Jamaica", "Japan", "Jersey", "Jordan", "Kazakhstan", "Kenya", "Kiribati", "Kosovo", "Kuwait", "Kyrgyzstan", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", "Macao", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Marshall Islands", "Martinique", "Mauritania", "Mauritius", "Mayotte", "Mexico", "Micronesia", "Moldova", "Monaco", "Mongolia", "Montenegro", "Montserrat", "Morocco", "Mozambique", "Myanmar (Burma)", "Namibia", "Nauru", "Nepal", "Netherlands", "New Caledonia", "New Zealand", "Nicaragua", "Niger", "Nigeria", "Niue", "Norfolk Island", "North Korea", "North Macedonia", "Northern Mariana Islands", "Norway", "Oman", "Pakistan", "Palau", "Palestine", "Panama", "Papua New Guinea", "Paraguay", "Peru", "Philippines", "Pitcairn Islands", "Poland", "Portugal", "Puerto Rico", "Qatar", "Romania", "Russia", "Rwanda", "Réunion", "Saint Barthélemy", "Saint Helena, Ascension and Tristan da Cunha", "Saint Kitts and Nevis", "Saint Lucia", "Saint Martin", "Saint Pierre and Miquelon", "Saint Vincent and the Grenadines", "Samoa", "San Marino", "Saudi Arabia", "Senegal", "Serbia", "Seychelles", "Sierra Leone", "Singapore", "Sint Maarten", "Slovakia", "Slovenia", "Solomon Islands", "Somalia", "South Africa", "South Georgia and the South Sandwich Islands", "South Korea", "South Sudan", "Spain", "Sri Lanka", "Sudan", "Suriname", "Svalbard and Jan Mayen", "Sweden", "Switzerland", "Syria", "São Tomé and Príncipe", "Taiwan", "Tajikistan", "Tanzania", "Thailand", "The Bahamas", "The Gambia", "Timor-Leste", "Togo", "Tokelau", "Tonga", "Trinidad and Tobago", "Tunisia", "Turkmenistan", "Turks and Caicos Islands", "Tuvalu", "Türkiye", "U.S. Virgin Islands", "Uganda", "Ukraine", "United Arab Emirates", "United Kingdom", "United States", "United States Minor Outlying Islands", "Uruguay", "Uzbekistan", "Vanuatu", "Vatican City", "Venezuela", "Vietnam", "Wallis and Futuna", "Western Sahara", "Yemen", "Zambia", "Zimbabwe", "Åland Islands"];
1260
+ const countries = {
1261
+ Afghanistan: "93",
1262
+ Albania: "355",
1263
+ Algeria: "213",
1264
+ "American Samoa": "1",
1265
+ Andorra: "376",
1266
+ Angola: "244",
1267
+ Anguilla: "1",
1268
+ Antarctica: "672",
1269
+ "Antigua and Barbuda": "1",
1270
+ Argentina: "54",
1271
+ Armenia: "374",
1272
+ Aruba: "297",
1273
+ Australia: "61",
1274
+ Austria: "43",
1275
+ Azerbaijan: "994",
1276
+ Bahrain: "973",
1277
+ Bangladesh: "880",
1278
+ Barbados: "1",
1279
+ Belarus: "375",
1280
+ Belgium: "32",
1281
+ Belize: "501",
1282
+ Benin: "229",
1283
+ Bermuda: "1",
1284
+ Bhutan: "975",
1285
+ Bolivia: "591",
1286
+ "Bosnia and Herzegovina": "387",
1287
+ Botswana: "267",
1288
+ "Bouvet Island": "47",
1289
+ Brazil: "55",
1290
+ "British Indian Ocean Territory": "246",
1291
+ "British Virgin Islands": "1",
1292
+ Brunei: "673",
1293
+ Bulgaria: "359",
1294
+ "Burkina Faso": "226",
1295
+ Burundi: "257",
1296
+ "Cabo Verde": "238",
1297
+ Cambodia: "855",
1298
+ Cameroon: "237",
1299
+ Canada: "1",
1300
+ "Caribbean Netherlands": "599",
1301
+ "Cayman Islands": "1",
1302
+ "Central African Republic": "236",
1303
+ Chad: "235",
1304
+ Chile: "56",
1305
+ China: "86",
1306
+ "Christmas Island": "61",
1307
+ "Cocos (Keeling) Islands": "61",
1308
+ Colombia: "57",
1309
+ Comoros: "269",
1310
+ "Cook Islands": "682",
1311
+ "Costa Rica": "506",
1312
+ Croatia: "385",
1313
+ Cuba: "53",
1314
+ Curaçao: "599",
1315
+ Cyprus: "357",
1316
+ Czechia: "420",
1317
+ "Côte d'Ivoire": "225",
1318
+ "Democratic Republic of the Congo": "243",
1319
+ Denmark: "45",
1320
+ Djibouti: "253",
1321
+ "Dominican Republic": "1",
1322
+ Ecuador: "593",
1323
+ Egypt: "20",
1324
+ "El Salvador": "503",
1325
+ "Equatorial Guinea": "240",
1326
+ Eritrea: "291",
1327
+ Estonia: "372",
1328
+ Eswatini: "268",
1329
+ Ethiopia: "251",
1330
+ "Falkland Islands (Islas Malvinas)": "500",
1331
+ "Faroe Islands": "298",
1332
+ Fiji: "679",
1333
+ Finland: "358",
1334
+ France: "33",
1335
+ "French Guiana": "594",
1336
+ "French Polynesia": "689",
1337
+ "French Southern and Antarctic Lands": "260",
1338
+ Gabon: "241",
1339
+ Georgia: "995",
1340
+ Germany: "49",
1341
+ Ghana: "233",
1342
+ Gibraltar: "350",
1343
+ Greece: "30",
1344
+ Greenland: "299",
1345
+ Grenada: "1",
1346
+ Guadeloupe: "590",
1347
+ Guam: "1",
1348
+ Guatemala: "502",
1349
+ Guernsey: "44",
1350
+ Guinea: "224",
1351
+ "Guinea-Bissau": "245",
1352
+ Guyana: "592",
1353
+ Haiti: "509",
1354
+ "Heard Island and McDonald Islands": "334",
1355
+ Honduras: "504",
1356
+ "Hong Kong": "852",
1357
+ Hungary: "36",
1358
+ Iceland: "354",
1359
+ India: "91",
1360
+ Indonesia: "62",
1361
+ Iran: "98",
1362
+ Iraq: "964",
1363
+ Ireland: "352",
1364
+ "Isle of Man": "44",
1365
+ Israel: "972",
1366
+ Italy: "39",
1367
+ Jamaica: "1",
1368
+ Japan: "81",
1369
+ Jersey: "44",
1370
+ Jordan: "962",
1371
+ Kazakhstan: "7",
1372
+ Kenya: "254",
1373
+ Kiribati: "686",
1374
+ Kosovo: "383",
1375
+ Kuwait: "965",
1376
+ Kyrgyzstan: "996",
1377
+ Laos: "856",
1378
+ Latvia: "371",
1379
+ Lebanon: "961",
1380
+ Lesotho: "266",
1381
+ Liberia: "231",
1382
+ Libya: "218",
1383
+ Liechtenstein: "423",
1384
+ Lithuania: "370",
1385
+ Luxembourg: "352",
1386
+ Macao: "853",
1387
+ Madagascar: "261",
1388
+ Malawi: "265",
1389
+ Malaysia: "60",
1390
+ Maldives: "960",
1391
+ Mali: "223",
1392
+ Malta: "356",
1393
+ "Marshall Islands": "692",
1394
+ Martinique: "596",
1395
+ Mauritania: "222",
1396
+ Mauritius: "230",
1397
+ Mayotte: "262",
1398
+ Mexico: "52",
1399
+ Micronesia: "691",
1400
+ Moldova: "373",
1401
+ Monaco: "377",
1402
+ Mongolia: "976",
1403
+ Montenegro: "382",
1404
+ Montserrat: "1",
1405
+ Morocco: "212",
1406
+ Mozambique: "258",
1407
+ "Myanmar (Burma)": "95",
1408
+ Namibia: "264",
1409
+ Nauru: "674",
1410
+ Nepal: "977",
1411
+ Netherlands: "31",
1412
+ "New Caledonia": "687",
1413
+ "New Zealand": "64",
1414
+ Nicaragua: "505",
1415
+ Niger: "227",
1416
+ Nigeria: "234",
1417
+ Niue: "683",
1418
+ "Norfolk Island": "672",
1419
+ "North Korea": "852",
1420
+ "North Macedonia": "389",
1421
+ "Northern Mariana Islands": "1",
1422
+ Norway: "47",
1423
+ Oman: "968",
1424
+ Pakistan: "92",
1425
+ Palau: "680",
1426
+ Palestine: "970",
1427
+ Panama: "507",
1428
+ "Papua New Guinea": "675",
1429
+ Paraguay: "595",
1430
+ Peru: "51",
1431
+ Philippines: "63",
1432
+ "Pitcairn Islands": "64",
1433
+ Poland: "48",
1434
+ Portugal: "351",
1435
+ "Puerto Rico": "1",
1436
+ Qatar: "974",
1437
+ Romania: "40",
1438
+ Russia: "7",
1439
+ Rwanda: "250",
1440
+ Réunion: "262",
1441
+ "Saint Barthélemy": "590",
1442
+ "Saint Helena, Ascension and Tristan da Cunha": "290",
1443
+ "Saint Kitts and Nevis": "1",
1444
+ "Saint Lucia": "1",
1445
+ "Saint Martin": "590",
1446
+ "Saint Pierre and Miquelon": "508",
1447
+ "Saint Vincent and the Grenadines": "1",
1448
+ Samoa: "685",
1449
+ "San Marino": "378",
1450
+ "Saudi Arabia": "966",
1451
+ Senegal: "221",
1452
+ Serbia: "381",
1453
+ Seychelles: "248",
1454
+ "Sierra Leone": "232",
1455
+ Singapore: "65",
1456
+ "Sint Maarten": "1",
1457
+ Slovakia: "421",
1458
+ Slovenia: "386",
1459
+ "Solomon Islands": "677",
1460
+ Somalia: "252",
1461
+ "South Africa": "27",
1462
+ "South Georgia and the South Sandwich Islands": "500",
1463
+ "South Korea": "82",
1464
+ "South Sudan": "211",
1465
+ Spain: "34",
1466
+ "Sri Lanka": "94",
1467
+ Sudan: "249",
1468
+ Suriname: "597",
1469
+ "Svalbard and Jan Mayen": "47",
1470
+ Sweden: "46",
1471
+ Switzerland: "41",
1472
+ Syria: "963",
1473
+ "São Tomé and Príncipe": "293",
1474
+ Taiwan: "886",
1475
+ Tajikistan: "992",
1476
+ Tanzania: "255",
1477
+ Thailand: "66",
1478
+ "The Bahamas": "1",
1479
+ "The Gambia": "220",
1480
+ "Timor-Leste": "670",
1481
+ Togo: "228",
1482
+ Tokelau: "690",
1483
+ Tonga: "676",
1484
+ "Trinidad and Tobago": "1",
1485
+ Tunisia: "216",
1486
+ Turkmenistan: "993",
1487
+ "Turks and Caicos Islands": "1",
1488
+ Tuvalu: "688",
1489
+ Türkiye: "90",
1490
+ "U.S. Virgin Islands": "1",
1491
+ Uganda: "256",
1492
+ Ukraine: "380",
1493
+ "United Arab Emirates": "971",
1494
+ "United Kingdom": "44",
1495
+ "United States": "1",
1496
+ "United States Minor Outlying Islands": "1",
1497
+ Uruguay: "598",
1498
+ Uzbekistan: "998",
1499
+ Vanuatu: "678",
1500
+ "Vatican City": "379",
1501
+ Venezuela: "58",
1502
+ Vietnam: "84",
1503
+ "Wallis and Futuna": "681",
1504
+ "Western Sahara": "212",
1505
+ Yemen: "967",
1506
+ Zambia: "260",
1507
+ Zimbabwe: "263",
1508
+ "Åland Islands": "358"
1509
+ };
1236
1510
  const keyToAddressComponents = {
1237
1511
  line1: ["street_number", "floor", "room", "premise"],
1238
1512
  line2: ["subpremise", "street_address", "route"],
@@ -1561,6 +1835,7 @@ const ChatInputAddressDetails = ({
1561
1835
  }
1562
1836
  }
1563
1837
  }, []);
1838
+ const countryNames = Object.keys(countries);
1564
1839
  return index.o("form", {
1565
1840
  class: "bg-neutral-1/90 flex flex-col justify-end gap-2 p-2",
1566
1841
  onSubmit: (e) => {
@@ -1589,7 +1864,7 @@ const ChatInputAddressDetails = ({
1589
1864
  children: [key === "country" ? index.o("div", {
1590
1865
  class: "relative",
1591
1866
  children: [index.o("select", {
1592
- class: "text-neutral-12 hover:bg-neutral-4 placeholder:text-neutral-8 focus:bg-neutral-5 w-full flex-1 appearance-none rounded-lg border-solid bg-transparent bg-none px-3 py-1.5 text-base transition-colors focus:outline-none",
1867
+ class: "text-neutral-12 hover:bg-neutral-4 placeholder:text-neutral-8 focus:bg-neutral-5 w-full flex-1 appearance-none rounded-lg border-solid bg-transparent bg-none px-3 py-1.5 text-base transition-colors focus:outline-none",
1593
1868
  name,
1594
1869
  id: labelId,
1595
1870
  defaultValue: addressFields[key],
@@ -1600,10 +1875,10 @@ const ChatInputAddressDetails = ({
1600
1875
  }) : index.o("option", {
1601
1876
  value: "",
1602
1877
  children: "Select a country"
1603
- }), countryNames.map((country) => index.o("option", {
1604
- value: country,
1605
- children: country
1606
- }, country))]
1878
+ }), countryNames.map((countryName) => index.o("option", {
1879
+ value: countryName,
1880
+ children: countryName
1881
+ }, countryName))]
1607
1882
  }), index.o("svg", {
1608
1883
  class: "text-neutral-12 absolute bottom-2.5 right-2 flex items-center justify-center",
1609
1884
  width: "16",
@@ -3434,7 +3709,7 @@ const LABEL_HEIGHT = 27;
3434
3709
  const GAP = 12;
3435
3710
  const PADDING = 10;
3436
3711
  const isMultipleChoiceSubmission = index.isSubmissionOfType("enum");
3437
- const getResolver$2 = (config) => {
3712
+ const getResolver$3 = (config) => {
3438
3713
  const length = {
3439
3714
  min: config.minSelected ?? 0,
3440
3715
  max: config.maxSelected ?? config.options.length
@@ -3488,7 +3763,7 @@ const ChatInputMultipleChoice = ({
3488
3763
  defaultValues: {
3489
3764
  checked: isSingleChoice ? {} : isMultipleChoiceSubmission(submission) ? Object.fromEntries(submission.value.map((key) => [key, true])) : {}
3490
3765
  },
3491
- resolver: getResolver$2(input.config)
3766
+ resolver: getResolver$3(input.config)
3492
3767
  });
3493
3768
  const focusRef = useFocusOnMount();
3494
3769
  if (isBooleanLike) {
@@ -3589,7 +3864,7 @@ const errors$1 = {
3589
3864
  max: (max) => `Please enter a number less than or equal to ${max}`,
3590
3865
  decimalCases: (decimalCases) => `Please enter a number with at most ${decimalCases} decimal cases`
3591
3866
  };
3592
- const getResolver$1 = (config) => {
3867
+ const getResolver$2 = (config) => {
3593
3868
  const min = config.min ?? Number.MIN_SAFE_INTEGER;
3594
3869
  const max = config.max ?? Number.MAX_SAFE_INTEGER;
3595
3870
  const decimalCases = config.decimalCases ?? 0;
@@ -3616,7 +3891,7 @@ const ChatInputNumber = ({
3616
3891
  defaultValues: {
3617
3892
  number: defaultValue ? Number(defaultValue) : isNumberSubmission(submission) ? submission.value : void 0
3618
3893
  },
3619
- resolver: getResolver$1(input.config)
3894
+ resolver: getResolver$2(input.config)
3620
3895
  });
3621
3896
  const {
3622
3897
  ref: setRef,
@@ -3674,6 +3949,115 @@ const ChatInputNumber = ({
3674
3949
  })]
3675
3950
  });
3676
3951
  };
3952
+ const invalidPhoneErrorMessage = "That doesn’t look like a valid phone number";
3953
+ const UK_CODE = "44";
3954
+ const PhoneSchema = index.string(invalidPhoneErrorMessage, [index.regex(/^\+?[0-9 -]+$/, invalidPhoneErrorMessage)]);
3955
+ const getResolver$1 = (config) => {
3956
+ const configErrors = {
3957
+ maxLength: `Please enter no more than ${config.maxChars ?? 999} characters`,
3958
+ minLength: `Please enter ${config.minChars ?? 1} or more characters`
3959
+ };
3960
+ return i(index.object({
3961
+ text: index.transform(PhoneSchema, (value) => value.replace(/[^0-9]/g, ""), [index.minLength(config.minChars ?? 1, configErrors.minLength), index.maxLength(config.maxChars ?? Infinity, configErrors.maxLength)])
3962
+ }));
3963
+ };
3964
+ const isTextSubmission$1 = index.isSubmissionOfType("string");
3965
+ const ChatInputPhoneNumber = ({
3966
+ input,
3967
+ onSubmitSuccess
3968
+ }) => {
3969
+ var _a;
3970
+ const submission = input.key ? (_a = index.store.current$.value.flow) == null ? void 0 : _a.data.submissions[input.key] : void 0;
3971
+ const defaultValue = input.config.defaultValue;
3972
+ const {
3973
+ register,
3974
+ handleSubmit,
3975
+ formState: {
3976
+ errors: errors2
3977
+ }
3978
+ } = useForm({
3979
+ defaultValues: {
3980
+ text: defaultValue ? defaultValue : isTextSubmission$1(submission) ? submission.value : ""
3981
+ },
3982
+ resolver: getResolver$1(input.config)
3983
+ });
3984
+ const {
3985
+ ref: setRef,
3986
+ ...props
3987
+ } = register("text", {
3988
+ required: !input.config.optional
3989
+ });
3990
+ const defaultCode = UK_CODE;
3991
+ const [countryCode, setCountryCode] = index.h(defaultCode);
3992
+ const inputRef = index._$1();
3993
+ const selectRef = index._$1(null);
3994
+ index.y(() => {
3995
+ if (inputRef.current) {
3996
+ inputRef.current.focus();
3997
+ inputRef.current.select();
3998
+ }
3999
+ }, []);
4000
+ return index.o("form", {
4001
+ noValidate: true,
4002
+ class: "flex flex-col gap-1 p-2.5",
4003
+ onSubmit: handleSubmit((submission2) => {
4004
+ onSubmitSuccess({
4005
+ type: "string",
4006
+ value: countryCode + submission2.text
4007
+ });
4008
+ }),
4009
+ children: [index.o("div", {
4010
+ class: "flex items-center gap-2",
4011
+ children: [index.o("div", {
4012
+ class: "relative flex min-w-0 flex-1 flex-grow gap-2",
4013
+ children: [index.o("label", {
4014
+ class: "text-neutral-12 hover:bg-neutral-4 placeholder:text-neutral-8 focus-within:bg-neutral-5 focus-within:outline-accent-7 relative flex h-full w-12 appearance-none items-center justify-center overflow-hidden text-ellipsis whitespace-nowrap rounded-lg border-solid bg-transparent bg-none py-1.5 text-center text-base transition-colors focus-within:outline-none",
4015
+ htmlFor: `isdk_phone_${input.key}`,
4016
+ children: [index.o("span", {
4017
+ children: ["+", countryCode]
4018
+ }), index.o("select", {
4019
+ ref: selectRef,
4020
+ onChange: (e) => {
4021
+ var _a2;
4022
+ const selectedCode = (_a2 = e.currentTarget.selectedOptions[0]) == null ? void 0 : _a2.value;
4023
+ setCountryCode(selectedCode);
4024
+ },
4025
+ required: true,
4026
+ defaultValue: defaultCode,
4027
+ id: `isdk_phone_${input.key}`,
4028
+ class: "absolute inset-0 opacity-0",
4029
+ children: Object.entries(countries).map(([countryName, countryCode2]) => index.o("option", {
4030
+ value: countryCode2,
4031
+ children: [countryName, " (+", countryCode2, ")"]
4032
+ }, countryName))
4033
+ })]
4034
+ }), index.o("input", {
4035
+ ...props,
4036
+ id: "chat-input",
4037
+ type: "tel",
4038
+ inputMode: "tel",
4039
+ autocomplete: "off",
4040
+ autoCapitalize: "off",
4041
+ autoCorrect: "off",
4042
+ autoFocus: true,
4043
+ ref: (element) => {
4044
+ if (element) {
4045
+ inputRef.current = element;
4046
+ }
4047
+ setRef(element);
4048
+ },
4049
+ class: "outline-divider ease-expo-out placeholder:text-neutral-10 text-neutral-12 focus-visible:outline-accent-7 caret-accent-9 bg-lowest flex-1 rounded-full px-3 py-1 text-base outline outline-2 transition-all",
4050
+ placeholder: input.config.placeholder
4051
+ }), input.config.optional && index.o(SkipButton, {
4052
+ class: "absolute right-0 top-0",
4053
+ onClick: () => onSubmitSuccess(null)
4054
+ })]
4055
+ }), index.o(SendButton, {})]
4056
+ }), index.o(InputError, {
4057
+ error: errors2.text
4058
+ })]
4059
+ });
4060
+ };
3677
4061
  const ChatInputSubmit = ({
3678
4062
  input,
3679
4063
  onSubmitSuccess
@@ -3690,7 +4074,7 @@ const ChatInputSubmit = ({
3690
4074
  class: "flex items-center gap-1.5",
3691
4075
  children: [index.o("span", {
3692
4076
  class: "inline-flex items-center text-sm font-medium",
3693
- children: input.config.label
4077
+ children: input.config.label || "Submit"
3694
4078
  }), index.o("svg", {
3695
4079
  stroke: "currentColor",
3696
4080
  "stroke-width": "1.5",
@@ -3715,17 +4099,12 @@ const errors = {
3715
4099
  phone: "That doesn’t look like a valid phone number",
3716
4100
  url: "That doesn’t look like a valid URL"
3717
4101
  };
3718
- const PhoneSchema = index.string(errors.phone, [index.regex(/^\+?[0-9 -]+$/, errors.phone)]);
3719
4102
  const inputFormatToProps = {
3720
4103
  email: {
3721
4104
  type: "email",
3722
4105
  inputMode: "email",
3723
4106
  formNoValidate: true
3724
4107
  },
3725
- phone: {
3726
- type: "tel",
3727
- inputMode: "tel"
3728
- },
3729
4108
  text: {
3730
4109
  type: "text",
3731
4110
  inputMode: "text"
@@ -3738,13 +4117,15 @@ const inputFormatToProps = {
3738
4117
  };
3739
4118
  const isTextSubmission = index.isSubmissionOfType("string");
3740
4119
  const getResolver = (config) => {
3741
- const maxLengthError = `Please enter no more than ${config.maxChars} characters`;
4120
+ const configErrors = {
4121
+ maxLength: `Please enter no more than ${config.maxChars ?? 999} characters`,
4122
+ minLength: `Please enter ${config.minChars ?? 1} or more characters`
4123
+ };
3742
4124
  return i(index.object({
3743
4125
  text: {
3744
- email: index.string(errors.email, [index.email(errors.email), index.maxLength(config.maxChars ?? Infinity, maxLengthError)]),
3745
- phone: index.transform(PhoneSchema, (value) => value.replace(/[^0-9]/g, ""), [index.maxLength(config.maxChars ?? Infinity, maxLengthError)]),
3746
- text: index.string([index.minLength(1, errors.empty), index.maxLength(config.maxChars ?? Infinity, maxLengthError)]),
3747
- url: index.string([index.url(errors.url), index.maxLength(config.maxChars ?? Infinity, maxLengthError)])
4126
+ email: index.string(errors.email, [index.email(errors.email), index.minLength(config.minChars ?? 1, configErrors.minLength), index.maxLength(config.maxChars ?? Infinity, configErrors.maxLength)]),
4127
+ text: index.string([index.minLength(config.minChars ?? 1, configErrors.minLength), index.maxLength(config.maxChars ?? Infinity, configErrors.maxLength)]),
4128
+ url: index.string([index.url(errors.url), index.minLength(config.minChars ?? 1, configErrors.minLength), index.maxLength(config.maxChars ?? Infinity, configErrors.maxLength)])
3748
4129
  }[config.format]
3749
4130
  }));
3750
4131
  };
@@ -3773,11 +4154,11 @@ const ChatInputText = ({
3773
4154
  } = register("text", {
3774
4155
  required: !input.config.optional
3775
4156
  });
3776
- const ref = index._$1();
4157
+ const inputRef = index._$1();
3777
4158
  index.y(() => {
3778
- if (ref.current) {
3779
- ref.current.focus();
3780
- ref.current.select();
4159
+ if (inputRef.current) {
4160
+ inputRef.current.focus();
4161
+ inputRef.current.select();
3781
4162
  }
3782
4163
  }, []);
3783
4164
  return index.o("form", {
@@ -3792,7 +4173,7 @@ const ChatInputText = ({
3792
4173
  children: [index.o("div", {
3793
4174
  class: "flex items-center gap-2",
3794
4175
  children: [index.o("div", {
3795
- class: "relative min-w-0 flex-grow",
4176
+ class: "relative min-w-0 flex-1",
3796
4177
  children: [index.o("input", {
3797
4178
  id: "chat-input",
3798
4179
  ...props,
@@ -3803,7 +4184,7 @@ const ChatInputText = ({
3803
4184
  autoFocus: true,
3804
4185
  ref: (element) => {
3805
4186
  if (element) {
3806
- ref.current = element;
4187
+ inputRef.current = element;
3807
4188
  }
3808
4189
  setRef(element);
3809
4190
  },
@@ -3870,6 +4251,13 @@ const ChatInput = () => {
3870
4251
  }, (props) => index.o(ChatInputText, {
3871
4252
  onSubmitSuccess: chatStore.onSubmitSuccessFn$.value,
3872
4253
  ...props
4254
+ })).with({
4255
+ input: {
4256
+ type: "phone"
4257
+ }
4258
+ }, (props) => index.o(ChatInputPhoneNumber, {
4259
+ onSubmitSuccess: chatStore.onSubmitSuccessFn$.value,
4260
+ ...props
3873
4261
  })).with({
3874
4262
  input: {
3875
4263
  type: "multiple-choice"
@@ -4071,6 +4459,19 @@ const Conversation = ({
4071
4459
  sizeKb: file.fileSizeKb
4072
4460
  }
4073
4461
  });
4462
+ }).with({
4463
+ type: "loading"
4464
+ }, (message2) => {
4465
+ const lastMessage = messages[messages.length - 1];
4466
+ const isLastMessage = message2 === lastMessage;
4467
+ if (!isLastMessage || chatStore.isBotTyping$.value)
4468
+ return null;
4469
+ return index.o("div", {
4470
+ class: "flex flex-grow flex-col items-center justify-center",
4471
+ children: index.o(index.LoadingIndicator, {
4472
+ class: "text-neutral-6 h-8 w-8"
4473
+ })
4474
+ });
4074
4475
  }).exhaustive()
4075
4476
  })
4076
4477
  }, i2);