@twilio/conversations 2.2.2 → 2.3.0-rc.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.
Files changed (76) hide show
  1. package/builds/browser.js +629 -25
  2. package/builds/browser.js.map +1 -1
  3. package/builds/lib.d.ts +501 -3
  4. package/builds/lib.js +620 -25
  5. package/builds/lib.js.map +1 -1
  6. package/builds/twilio-conversations.js +887 -267
  7. package/builds/twilio-conversations.min.js +1 -1
  8. package/dist/aggregated-delivery-receipt.js +9 -0
  9. package/dist/aggregated-delivery-receipt.js.map +1 -1
  10. package/dist/client.js +19 -0
  11. package/dist/client.js.map +1 -1
  12. package/dist/command-executor.js +9 -0
  13. package/dist/command-executor.js.map +1 -1
  14. package/dist/configuration.js +9 -0
  15. package/dist/configuration.js.map +1 -1
  16. package/dist/content-client.js +184 -0
  17. package/dist/content-client.js.map +1 -0
  18. package/dist/content-template.js +310 -0
  19. package/dist/content-template.js.map +1 -0
  20. package/dist/conversation.js +9 -0
  21. package/dist/conversation.js.map +1 -1
  22. package/dist/data/conversations.js +9 -0
  23. package/dist/data/conversations.js.map +1 -1
  24. package/dist/data/messages.js +13 -0
  25. package/dist/data/messages.js.map +1 -1
  26. package/dist/data/participants.js +9 -0
  27. package/dist/data/participants.js.map +1 -1
  28. package/dist/data/users.js +9 -0
  29. package/dist/data/users.js.map +1 -1
  30. package/dist/detailed-delivery-receipt.js +9 -0
  31. package/dist/detailed-delivery-receipt.js.map +1 -1
  32. package/dist/index.js +12 -0
  33. package/dist/index.js.map +1 -1
  34. package/dist/interfaces/attributes.js +9 -0
  35. package/dist/interfaces/attributes.js.map +1 -1
  36. package/dist/interfaces/notification-types.js +9 -0
  37. package/dist/interfaces/notification-types.js.map +1 -1
  38. package/dist/logger.js +9 -0
  39. package/dist/logger.js.map +1 -1
  40. package/dist/media.js +9 -0
  41. package/dist/media.js.map +1 -1
  42. package/dist/message-builder.js +28 -0
  43. package/dist/message-builder.js.map +1 -1
  44. package/dist/message.js +94 -0
  45. package/dist/message.js.map +1 -1
  46. package/dist/node_modules/tslib/tslib.es6.js +9 -0
  47. package/dist/node_modules/tslib/tslib.es6.js.map +1 -1
  48. package/dist/packages/conversations/package.json.js +10 -1
  49. package/dist/packages/conversations/package.json.js.map +1 -1
  50. package/dist/participant.js +9 -0
  51. package/dist/participant.js.map +1 -1
  52. package/dist/push-notification.js +9 -0
  53. package/dist/push-notification.js.map +1 -1
  54. package/dist/rest-paginator.js +9 -0
  55. package/dist/rest-paginator.js.map +1 -1
  56. package/dist/services/network.js +9 -0
  57. package/dist/services/network.js.map +1 -1
  58. package/dist/services/typing-indicator.js +9 -0
  59. package/dist/services/typing-indicator.js.map +1 -1
  60. package/dist/unsent-message.js +9 -0
  61. package/dist/unsent-message.js.map +1 -1
  62. package/dist/user.js +9 -0
  63. package/dist/user.js.map +1 -1
  64. package/dist/util/deferred.js +9 -0
  65. package/dist/util/deferred.js.map +1 -1
  66. package/dist/util/index.js +9 -0
  67. package/dist/util/index.js.map +1 -1
  68. package/docs/assets/js/search.js +1 -1
  69. package/docs/classes/Client.html +24 -0
  70. package/docs/classes/ContentTemplate.html +3116 -0
  71. package/docs/classes/ContentTemplateVariable.html +3116 -0
  72. package/docs/classes/Message.html +47 -0
  73. package/docs/classes/MessageBuilder.html +41 -0
  74. package/docs/index.html +813 -0
  75. package/docs/modules.html +813 -0
  76. package/package.json +9 -8
package/builds/lib.js CHANGED
@@ -211,11 +211,13 @@ require('core-js/modules/es.array-buffer.constructor.js');
211
211
  require('isomorphic-form-data');
212
212
  require('core-js/modules/es.array.sort.js');
213
213
  require('core-js/modules/es.string.includes.js');
214
+ require('core-js/modules/es.string.starts-with.js');
214
215
  var deprecationDecorator = require('@twilio/deprecation-decorator');
216
+ require('core-js/modules/es.object.entries.js');
215
217
  require('core-js/modules/es.array.find.js');
216
218
  require('core-js/modules/es.array.splice.js');
217
- require('core-js/modules/es.object.entries.js');
218
219
  var uuid = require('uuid');
220
+ require('core-js/modules/es.object.freeze.js');
219
221
 
220
222
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
221
223
 
@@ -390,9 +392,9 @@ var Logger = /*#__PURE__*/function () {
390
392
  return Logger;
391
393
  }();
392
394
 
393
- function ownKeys$4(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
395
+ function ownKeys$5(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
394
396
 
395
- function _objectSpread$4(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$4(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$4(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
397
+ function _objectSpread$5(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$5(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$5(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
396
398
  var TYPING_TIMEOUT = 5;
397
399
  var HTTP_CACHE_LIFETIME = "PT5S";
398
400
  var CONSUMPTION_HORIZON_SENDING_INTERVAL = "PT5S";
@@ -433,7 +435,7 @@ var Configuration = /*#__PURE__*/_createClass__default["default"](function Confi
433
435
  emailBodiesAllowedContentTypes: configurationResponse.options.email_bodies_allowed_mime_types
434
436
  };
435
437
  this.typingIndicatorTimeoutOverride = constructorOptions.typingIndicatorTimeoutOverride;
436
- this.backoffConfiguration = _objectSpread$4({
438
+ this.backoffConfiguration = _objectSpread$5({
437
439
  min: MINIMUM_RETRY_DELAY,
438
440
  max: MAXIMUM_RETRY_DELAY,
439
441
  maxAttemptsCount: MAXIMUM_ATTEMPTS_COUNT
@@ -2547,18 +2549,260 @@ function DetailedDeliveryReceipt(descriptor) {
2547
2549
  this.dateUpdated = descriptor.date_updated;
2548
2550
  });
2549
2551
 
2550
- function ownKeys$3(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2552
+ var collectActions = function collectActions(actions) {
2553
+ return actions.map(function (action) {
2554
+ var _action$id, _action$index, _action$phone, _action$url;
2551
2555
 
2552
- function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$3(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2556
+ var rawData = JSON.stringify(action);
2557
+
2558
+ switch (action.type) {
2559
+ case "QUICK_REPLY":
2560
+ return {
2561
+ type: "reply",
2562
+ title: action.title,
2563
+ id: (_action$id = action.id) !== null && _action$id !== void 0 ? _action$id : "",
2564
+ index: (_action$index = action.index) !== null && _action$index !== void 0 ? _action$index : 0,
2565
+ rawData: rawData
2566
+ };
2567
+
2568
+ case "PHONE_NUMBER":
2569
+ return {
2570
+ type: "phone",
2571
+ title: action.title,
2572
+ phone: (_action$phone = action.phone) !== null && _action$phone !== void 0 ? _action$phone : "",
2573
+ rawData: rawData
2574
+ };
2575
+
2576
+ case "URL":
2577
+ return {
2578
+ type: "url",
2579
+ title: action.title,
2580
+ url: (_action$url = action.url) !== null && _action$url !== void 0 ? _action$url : "",
2581
+ rawData: rawData
2582
+ };
2583
+
2584
+ default:
2585
+ return {
2586
+ type: "other",
2587
+ rawData: rawData
2588
+ };
2589
+ }
2590
+ });
2591
+ };
2592
+
2593
+ var parseVariant = function parseVariant(type, data) {
2594
+ var rawData = JSON.stringify(data);
2595
+
2596
+ switch (type) {
2597
+ case "twilio/text":
2598
+ {
2599
+ var variant = data;
2600
+ return {
2601
+ type: "text",
2602
+ body: variant.body,
2603
+ rawData: rawData
2604
+ };
2605
+ }
2606
+
2607
+ case "twilio/media":
2608
+ {
2609
+ var _variant = data;
2610
+ return {
2611
+ type: "media",
2612
+ body: _variant.body,
2613
+ media: _variant.media,
2614
+ rawData: rawData
2615
+ };
2616
+ }
2617
+
2618
+ case "twilio/location":
2619
+ {
2620
+ var _variant2 = data;
2621
+ return {
2622
+ type: "location",
2623
+ longitude: _variant2.longitude,
2624
+ latitude: _variant2.latitude,
2625
+ label: _variant2.label,
2626
+ rawData: rawData
2627
+ };
2628
+ }
2629
+
2630
+ case "twilio/quick-reply":
2631
+ {
2632
+ var _variant3 = data;
2633
+ return {
2634
+ type: "quickReply",
2635
+ body: _variant3.body,
2636
+ replies: _variant3.actions,
2637
+ rawData: rawData
2638
+ };
2639
+ }
2640
+
2641
+ case "twilio/call-to-action":
2642
+ {
2643
+ var _variant4 = data;
2644
+ return {
2645
+ type: "callToAction",
2646
+ body: _variant4.body,
2647
+ actions: collectActions(_variant4.actions),
2648
+ rawData: rawData
2649
+ };
2650
+ }
2651
+
2652
+ case "twilio/list-picker":
2653
+ {
2654
+ var _variant5 = data;
2655
+ return {
2656
+ type: "listPicker",
2657
+ body: _variant5.body,
2658
+ button: _variant5.button,
2659
+ items: _variant5.items,
2660
+ rawData: rawData
2661
+ };
2662
+ }
2663
+
2664
+ case "twilio/card":
2665
+ {
2666
+ var _variant6$media, _variant6$actions;
2667
+
2668
+ var _variant6 = data;
2669
+ return {
2670
+ type: "card",
2671
+ title: _variant6.title,
2672
+ subtitle: _variant6.subtitle,
2673
+ media: (_variant6$media = _variant6.media) !== null && _variant6$media !== void 0 ? _variant6$media : [],
2674
+ actions: collectActions((_variant6$actions = _variant6.actions) !== null && _variant6$actions !== void 0 ? _variant6$actions : []),
2675
+ rawData: rawData
2676
+ };
2677
+ }
2678
+
2679
+ default:
2680
+ return {
2681
+ type: "other",
2682
+ rawData: rawData
2683
+ };
2684
+ }
2685
+ };
2686
+
2687
+ var collectVariants = function collectVariants(variants) {
2688
+ var variantsMap = new Map();
2689
+
2690
+ for (var _i = 0, _Object$entries = Object.entries(variants); _i < _Object$entries.length; _i++) {
2691
+ var _Object$entries$_i = _slicedToArray__default["default"](_Object$entries[_i], 2),
2692
+ key = _Object$entries$_i[0],
2693
+ value = _Object$entries$_i[1];
2694
+
2695
+ variantsMap.set(key, parseVariant(key, value));
2696
+ }
2697
+
2698
+ return variantsMap;
2699
+ };
2700
+ /**
2701
+ * Represents a variable for a content template. See
2702
+ * {@link ContentTemplate.variables}.
2703
+ */
2704
+
2705
+
2706
+ var ContentTemplateVariable = /*#__PURE__*/function () {
2707
+ function ContentTemplateVariable(
2708
+ /**
2709
+ * Name of the variable.
2710
+ */
2711
+ name,
2712
+ /**
2713
+ * Key of the variable
2714
+ */
2715
+ value) {
2716
+ _classCallCheck__default["default"](this, ContentTemplateVariable);
2717
+
2718
+ this.name = name;
2719
+ this.value = value;
2720
+ }
2721
+ /**
2722
+ * Copies the variable with a new value.
2723
+ *
2724
+ * @param value The new value for the variable.
2725
+ */
2726
+
2727
+
2728
+ _createClass__default["default"](ContentTemplateVariable, [{
2729
+ key: "copyWithValue",
2730
+ value: function copyWithValue(value) {
2731
+ return new ContentTemplateVariable(this.name, value);
2732
+ }
2733
+ }]);
2734
+
2735
+ return ContentTemplateVariable;
2736
+ }();
2737
+ /**
2738
+ * A rich content template.
2739
+ *
2740
+ * Use {@Link Client.getContentTemplates} to request all the templates available
2741
+ * for the current account.
2742
+ */
2743
+
2744
+
2745
+ var ContentTemplate = /*#__PURE__*/_createClass__default["default"](
2746
+ /**
2747
+ * The server-assigned unique identifier for the template.
2748
+ */
2749
+
2750
+ /**
2751
+ * Friendly name used to describe the content. Not visible to the recipient.
2752
+ */
2753
+
2754
+ /**
2755
+ * Variables used by this template.
2756
+ */
2757
+
2758
+ /**
2759
+ * Variants of the content. See @{link ContentData}.
2760
+ */
2761
+
2762
+ /**
2763
+ * Date of creation.
2764
+ */
2765
+
2766
+ /**
2767
+ * Date of the last update.
2768
+ */
2769
+
2770
+ /**
2771
+ * @internal
2772
+ */
2773
+ function ContentTemplate(contentTemplateResponse) {
2774
+ _classCallCheck__default["default"](this, ContentTemplate);
2775
+
2776
+ this.sid = contentTemplateResponse.sid;
2777
+ this.friendlyName = contentTemplateResponse.friendly_name;
2778
+ this.variables = Object.entries(JSON.parse(contentTemplateResponse.variables)).map(function (_ref) {
2779
+ var _ref2 = _slicedToArray__default["default"](_ref, 2),
2780
+ key = _ref2[0],
2781
+ value = _ref2[1];
2782
+
2783
+ return new ContentTemplateVariable(key, value);
2784
+ });
2785
+ this.variants = collectVariants(contentTemplateResponse.variants);
2786
+ this.dateCreated = new Date(contentTemplateResponse.date_created);
2787
+ this.dateUpdated = new Date(contentTemplateResponse.date_updated);
2788
+ });
2789
+
2790
+ function ownKeys$4(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2791
+
2792
+ function _objectSpread$4(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$4(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$4(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
2553
2793
 
2554
2794
  function _createSuper$5(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct$5(); return function _createSuperInternal() { var Super = _getPrototypeOf__default["default"](Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf__default["default"](this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn__default["default"](this, result); }; }
2555
2795
 
2556
2796
  function _isNativeReflectConstruct$5() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
2557
2797
  var log$3 = Logger.scope("Message");
2798
+
2799
+ var XHR = // eslint-disable-next-line @typescript-eslint/no-var-requires
2800
+ global["XMLHttpRequest"] || require("xmlhttprequest").XMLHttpRequest;
2558
2801
  /**
2559
2802
  * A message in a conversation.
2560
2803
  */
2561
2804
 
2805
+
2562
2806
  var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
2563
2807
  _inherits__default["default"](Message, _ReplayEventEmitter);
2564
2808
 
@@ -2588,6 +2832,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
2588
2832
  index: index,
2589
2833
  author: data.author,
2590
2834
  subject: data.subject,
2835
+ contentSid: data.contentSid,
2591
2836
  body: (_data$text = data.text) !== null && _data$text !== void 0 ? _data$text : null,
2592
2837
  timestamp: data.timestamp ? new Date(data.timestamp) : null,
2593
2838
  dateUpdated: data.dateUpdated ? new Date(data.dateUpdated) : null,
@@ -2597,7 +2842,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
2597
2842
  media: data.type === "media" && data.media ? new Media(data.media, _this.services) : null,
2598
2843
  medias: data.type === "media" && data.medias ? data.medias.map(function (m) {
2599
2844
  return new Media(m, _this.services);
2600
- }) : data.type === "media" && data.media && !data.medias ? [new Media(_objectSpread$3(_objectSpread$3({}, data.media), {}, {
2845
+ }) : data.type === "media" && data.media && !data.medias ? [new Media(_objectSpread$4(_objectSpread$4({}, data.media), {}, {
2601
2846
  category: "media"
2602
2847
  }), _this.services)] : null,
2603
2848
  participantSid: (_data$memberSid = data.memberSid) !== null && _data$memberSid !== void 0 ? _data$memberSid : null,
@@ -2642,6 +2887,15 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
2642
2887
  get: function get() {
2643
2888
  return this.state.subject;
2644
2889
  }
2890
+ /**
2891
+ * Unique identifier of {@link ContentTemplate} for this message.
2892
+ */
2893
+
2894
+ }, {
2895
+ key: "contentSid",
2896
+ get: function get() {
2897
+ return this.state.contentSid;
2898
+ }
2645
2899
  /**
2646
2900
  * Body of the message.
2647
2901
  */
@@ -3303,6 +3557,147 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3303
3557
 
3304
3558
  return _getDetailedDeliveryReceiptsPaginator;
3305
3559
  }()
3560
+ /**
3561
+ * Get the {@link ContentData} for this message. Resolves to `null` when
3562
+ * {@link Message.contentSid} is null.
3563
+ */
3564
+
3565
+ }, {
3566
+ key: "getContentData",
3567
+ value: function getContentData() {
3568
+ var _this6 = this;
3569
+
3570
+ return new mcsClient.CancellablePromise( /*#__PURE__*/function () {
3571
+ var _ref2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee9(resolve, reject, onCancel) {
3572
+ var bodies, twilioPrefix, filteredMedias, contentMedia, urlPromise, url, jsonStringPromise, json, jsonString, dataType;
3573
+ return _regeneratorRuntime__default["default"].wrap(function _callee9$(_context9) {
3574
+ while (1) {
3575
+ switch (_context9.prev = _context9.next) {
3576
+ case 0:
3577
+ if (!(_this6.state.contentSid === null)) {
3578
+ _context9.next = 3;
3579
+ break;
3580
+ }
3581
+
3582
+ resolve(null);
3583
+ return _context9.abrupt("return");
3584
+
3585
+ case 3:
3586
+ bodies = _this6.getMediaByCategories(["body"]);
3587
+
3588
+ if (!(bodies === null)) {
3589
+ _context9.next = 7;
3590
+ break;
3591
+ }
3592
+
3593
+ resolve(null);
3594
+ return _context9.abrupt("return");
3595
+
3596
+ case 7:
3597
+ twilioPrefix = "application/x-vnd.com.twilio.rich.";
3598
+ filteredMedias = bodies.filter(function (media) {
3599
+ return media.contentType.startsWith(twilioPrefix);
3600
+ });
3601
+
3602
+ if (!(filteredMedias.length === 0)) {
3603
+ _context9.next = 12;
3604
+ break;
3605
+ }
3606
+
3607
+ resolve(null);
3608
+ return _context9.abrupt("return");
3609
+
3610
+ case 12:
3611
+ contentMedia = filteredMedias[0];
3612
+ urlPromise = contentMedia.getContentTemporaryUrl();
3613
+ onCancel(function () {
3614
+ urlPromise.cancel();
3615
+ });
3616
+ _context9.prev = 15;
3617
+ _context9.next = 18;
3618
+ return urlPromise;
3619
+
3620
+ case 18:
3621
+ url = _context9.sent;
3622
+ _context9.next = 25;
3623
+ break;
3624
+
3625
+ case 21:
3626
+ _context9.prev = 21;
3627
+ _context9.t0 = _context9["catch"](15);
3628
+ reject(_context9.t0);
3629
+ return _context9.abrupt("return");
3630
+
3631
+ case 25:
3632
+ if (!(url === null)) {
3633
+ _context9.next = 28;
3634
+ break;
3635
+ }
3636
+
3637
+ resolve(null);
3638
+ return _context9.abrupt("return");
3639
+
3640
+ case 28:
3641
+ jsonStringPromise = new Promise(function (resolve, reject) {
3642
+ var _url;
3643
+
3644
+ var isCancelled = false;
3645
+ var xhr = new XHR();
3646
+ xhr.open("GET", (_url = url) !== null && _url !== void 0 ? _url : "", true);
3647
+ xhr.responseType = "text";
3648
+
3649
+ xhr.onreadystatechange = function () {
3650
+ if (xhr.readyState !== 4 || isCancelled) {
3651
+ return;
3652
+ }
3653
+
3654
+ resolve(xhr.responseText);
3655
+ };
3656
+
3657
+ xhr.onerror = function () {
3658
+ reject(xhr.statusText);
3659
+ };
3660
+
3661
+ onCancel(function () {
3662
+ isCancelled = true;
3663
+ xhr.abort();
3664
+ reject(new Error("XHR has been aborted"));
3665
+ });
3666
+ xhr.send();
3667
+ });
3668
+ _context9.prev = 29;
3669
+ _context9.next = 32;
3670
+ return jsonStringPromise;
3671
+
3672
+ case 32:
3673
+ jsonString = _context9.sent;
3674
+ json = JSON.parse(jsonString);
3675
+ _context9.next = 40;
3676
+ break;
3677
+
3678
+ case 36:
3679
+ _context9.prev = 36;
3680
+ _context9.t1 = _context9["catch"](29);
3681
+ reject(_context9.t1);
3682
+ return _context9.abrupt("return");
3683
+
3684
+ case 40:
3685
+ dataType = contentMedia.contentType.replace(twilioPrefix, "").replace(".", "/");
3686
+ resolve(parseVariant(dataType, json.data));
3687
+
3688
+ case 42:
3689
+ case "end":
3690
+ return _context9.stop();
3691
+ }
3692
+ }
3693
+ }, _callee9, null, [[15, 21], [29, 36]]);
3694
+ }));
3695
+
3696
+ return function (_x8, _x9, _x10) {
3697
+ return _ref2.apply(this, arguments);
3698
+ };
3699
+ }());
3700
+ }
3306
3701
  }]);
3307
3702
 
3308
3703
  return Message;
@@ -3326,6 +3721,10 @@ __decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator
3326
3721
 
3327
3722
  __decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator.nonEmptyArray("strings", "string")), __metadata("design:type", Function), __metadata("design:paramtypes", [Array]), __metadata("design:returntype", mcsClient.CancellablePromise)], Message.prototype, "getTemporaryContentUrlsForMediaSids", null);
3328
3723
 
3724
+ function ownKeys$3(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3725
+
3726
+ function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$3(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$3(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
3727
+
3329
3728
  function _createForOfIteratorHelper$2(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$2(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
3330
3729
 
3331
3730
  function _unsupportedIterableToArray$2(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$2(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$2(o, minLen); }
@@ -3600,7 +3999,11 @@ var Messages = /*#__PURE__*/function (_ReplayEventEmitter) {
3600
3999
  media_sids: media.map(function (m) {
3601
4000
  return m.sid;
3602
4001
  }),
3603
- attributes: typeof message.attributes !== "undefined" ? JSON.stringify(message.attributes) : undefined
4002
+ attributes: typeof message.attributes !== "undefined" ? JSON.stringify(message.attributes) : undefined,
4003
+ content_sid: message.contentSid,
4004
+ content_variables: typeof message.contentVariables !== "undefined" ? JSON.stringify(message.contentVariables.reduce(function (accum, current) {
4005
+ return _objectSpread$3(_objectSpread$3({}, accum), {}, _defineProperty__default["default"]({}, current.name, current.value));
4006
+ }, {})) : undefined
3604
4007
  });
3605
4008
  _context3.prev = 34;
3606
4009
  _context3.t4 = resolve;
@@ -4071,6 +4474,29 @@ var MessageBuilder = /*#__PURE__*/function () {
4071
4474
  this.emailHistories.set(contentType, history);
4072
4475
  return this;
4073
4476
  }
4477
+ /**
4478
+ * Adds {@link ContentTemplate} SID for the message alongside optional
4479
+ * variables. When no variables provided, the default values will be used.
4480
+ *
4481
+ * Adding the content SID converts the message to a rich message. In this
4482
+ * case, other fields are ignored and the message is sent using the content
4483
+ * from the the {@link ContentTemplate}.
4484
+ *
4485
+ * Use {@link Client.getContentTemplates} to request all available
4486
+ * {@link ContentTemplate}s.
4487
+ *
4488
+ * @param contentSid SID of the {@link ContentTemplate}
4489
+ * @param variables Custom variables to resolve the template.
4490
+ */
4491
+
4492
+ }, {
4493
+ key: "setContentTemplate",
4494
+ value: function setContentTemplate(contentSid) {
4495
+ var contentVariables = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
4496
+ this.message.contentSid = contentSid;
4497
+ this.message.contentVariables = contentVariables;
4498
+ return this;
4499
+ }
4074
4500
  /**
4075
4501
  * Adds media to the message.
4076
4502
  * @param payload Media to add.
@@ -7329,7 +7755,7 @@ function PushNotification(data) {
7329
7755
  this.data = data.data || {};
7330
7756
  });
7331
7757
 
7332
- var version = "2.2.2";
7758
+ var version = "2.3.0-rc.1";
7333
7759
 
7334
7760
  function ownKeys$1(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
7335
7761
 
@@ -7532,6 +7958,135 @@ var CommandExecutor = /*#__PURE__*/function () {
7532
7958
  return CommandExecutor;
7533
7959
  }();
7534
7960
 
7961
+ var ContentClient = /*#__PURE__*/function () {
7962
+ function ContentClient(_services) {
7963
+ var _pageSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100;
7964
+
7965
+ var _cacheTtlMs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 5000;
7966
+
7967
+ _classCallCheck__default["default"](this, ContentClient);
7968
+
7969
+ _defineProperty__default["default"](this, "_cachedTemplates", null);
7970
+
7971
+ this._services = _services;
7972
+ this._pageSize = _pageSize;
7973
+ this._cacheTtlMs = _cacheTtlMs;
7974
+ }
7975
+
7976
+ _createClass__default["default"](ContentClient, [{
7977
+ key: "getContentTemplates",
7978
+ value: function () {
7979
+ var _getContentTemplates = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
7980
+ var _this = this;
7981
+
7982
+ var _yield$this$_fetchCon, _yield$this$_fetchCon2, templatesPage, nextToken, templates, _yield$this$_fetchCon3, _yield$this$_fetchCon4;
7983
+
7984
+ return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
7985
+ while (1) {
7986
+ switch (_context.prev = _context.next) {
7987
+ case 0:
7988
+ if (!(this._cachedTemplates !== null)) {
7989
+ _context.next = 2;
7990
+ break;
7991
+ }
7992
+
7993
+ return _context.abrupt("return", this._cachedTemplates);
7994
+
7995
+ case 2:
7996
+ _context.next = 4;
7997
+ return this._fetchContentTemplates();
7998
+
7999
+ case 4:
8000
+ _yield$this$_fetchCon = _context.sent;
8001
+ _yield$this$_fetchCon2 = _slicedToArray__default["default"](_yield$this$_fetchCon, 2);
8002
+ templatesPage = _yield$this$_fetchCon2[0];
8003
+ nextToken = _yield$this$_fetchCon2[1];
8004
+ templates = templatesPage;
8005
+
8006
+ case 9:
8007
+ if (!(nextToken !== null)) {
8008
+ _context.next = 19;
8009
+ break;
8010
+ }
8011
+
8012
+ _context.next = 12;
8013
+ return this._fetchContentTemplates(nextToken);
8014
+
8015
+ case 12:
8016
+ _yield$this$_fetchCon3 = _context.sent;
8017
+ _yield$this$_fetchCon4 = _slicedToArray__default["default"](_yield$this$_fetchCon3, 2);
8018
+ templatesPage = _yield$this$_fetchCon4[0];
8019
+ nextToken = _yield$this$_fetchCon4[1];
8020
+ templates = [].concat(_toConsumableArray__default["default"](templates), _toConsumableArray__default["default"](templatesPage));
8021
+ _context.next = 9;
8022
+ break;
8023
+
8024
+ case 19:
8025
+ this._cachedTemplates = Object.freeze(templates);
8026
+ setTimeout(function () {
8027
+ _this._cachedTemplates = null;
8028
+ }, this._cacheTtlMs);
8029
+ return _context.abrupt("return", templates);
8030
+
8031
+ case 22:
8032
+ case "end":
8033
+ return _context.stop();
8034
+ }
8035
+ }
8036
+ }, _callee, this);
8037
+ }));
8038
+
8039
+ function getContentTemplates() {
8040
+ return _getContentTemplates.apply(this, arguments);
8041
+ }
8042
+
8043
+ return getContentTemplates;
8044
+ }()
8045
+ }, {
8046
+ key: "_fetchContentTemplates",
8047
+ value: function () {
8048
+ var _fetchContentTemplates2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(pageToken) {
8049
+ var contentTemplatesUrl, url, response;
8050
+ return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
8051
+ while (1) {
8052
+ switch (_context2.prev = _context2.next) {
8053
+ case 0:
8054
+ contentTemplatesUrl = "Client/v2/ContentTemplates";
8055
+ url = new UriBuilder(contentTemplatesUrl);
8056
+ url.arg("PageSize", this._pageSize);
8057
+
8058
+ if (pageToken !== undefined) {
8059
+ url.arg("PageToken", pageToken);
8060
+ }
8061
+
8062
+ _context2.next = 6;
8063
+ return this._services.commandExecutor.fetchResource(url.build());
8064
+
8065
+ case 6:
8066
+ response = _context2.sent;
8067
+ return _context2.abrupt("return", [response.templates.map(function (template) {
8068
+ return new ContentTemplate(template);
8069
+ }), response.meta.next_token]);
8070
+
8071
+ case 8:
8072
+ case "end":
8073
+ return _context2.stop();
8074
+ }
8075
+ }
8076
+ }, _callee2, this);
8077
+ }));
8078
+
8079
+ function _fetchContentTemplates(_x) {
8080
+ return _fetchContentTemplates2.apply(this, arguments);
8081
+ }
8082
+
8083
+ return _fetchContentTemplates;
8084
+ }()
8085
+ }]);
8086
+
8087
+ return ContentClient;
8088
+ }();
8089
+
7535
8090
  var _class;
7536
8091
 
7537
8092
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
@@ -7921,6 +8476,7 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
7921
8476
  _this._services.commandExecutor = new CommandExecutor(baseUrl, {
7922
8477
  transport: _this._options.transport
7923
8478
  }, productId);
8479
+ _this._services.contentClient = new ContentClient(_this._services);
7924
8480
 
7925
8481
  var emitFailed = function emitFailed(error) {
7926
8482
  _this._rejectEnsureReady(error);
@@ -8693,6 +9249,43 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
8693
9249
  });
8694
9250
  return this.getTemporaryContentUrlsForMediaSids(sids);
8695
9251
  }
9252
+ /**
9253
+ * Returns rich content templates belonging to the account. Rich content
9254
+ * templates can be created via the Twilio console or the REST API.
9255
+ */
9256
+
9257
+ }, {
9258
+ key: "getContentTemplates",
9259
+ value: function () {
9260
+ var _getContentTemplates = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee16() {
9261
+ return _regeneratorRuntime__default["default"].wrap(function _callee16$(_context16) {
9262
+ while (1) {
9263
+ switch (_context16.prev = _context16.next) {
9264
+ case 0:
9265
+ _context16.next = 2;
9266
+ return this._ensureReady;
9267
+
9268
+ case 2:
9269
+ _context16.next = 4;
9270
+ return this._services.contentClient.getContentTemplates();
9271
+
9272
+ case 4:
9273
+ return _context16.abrupt("return", _context16.sent);
9274
+
9275
+ case 5:
9276
+ case "end":
9277
+ return _context16.stop();
9278
+ }
9279
+ }
9280
+ }, _callee16, this);
9281
+ }));
9282
+
9283
+ function getContentTemplates() {
9284
+ return _getContentTemplates.apply(this, arguments);
9285
+ }
9286
+
9287
+ return getContentTemplates;
9288
+ }()
8696
9289
  /**
8697
9290
  * Initialize the client.
8698
9291
  */
@@ -8700,19 +9293,19 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
8700
9293
  }, {
8701
9294
  key: "_initialize",
8702
9295
  value: function () {
8703
- var _initialize2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee16() {
9296
+ var _initialize2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee17() {
8704
9297
  var _this3 = this;
8705
9298
 
8706
9299
  var configurationResponse;
8707
- return _regeneratorRuntime__default["default"].wrap(function _callee16$(_context16) {
9300
+ return _regeneratorRuntime__default["default"].wrap(function _callee17$(_context17) {
8708
9301
  while (1) {
8709
- switch (_context16.prev = _context16.next) {
9302
+ switch (_context17.prev = _context17.next) {
8710
9303
  case 0:
8711
- _context16.next = 2;
9304
+ _context17.next = 2;
8712
9305
  return this._services.commandExecutor.fetchResource("Client/v2/Configuration");
8713
9306
 
8714
9307
  case 2:
8715
- configurationResponse = _context16.sent;
9308
+ configurationResponse = _context17.sent;
8716
9309
  this._configuration = new Configuration(this._options, configurationResponse, Client_1._logger);
8717
9310
 
8718
9311
  this._myself._resolveInitialization(this._configuration, this._configuration.userIdentity, this._configuration.userInfo, true);
@@ -8792,7 +9385,7 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
8792
9385
  }).catch(function (error) {
8793
9386
  throw error;
8794
9387
  });
8795
- _context16.next = 28;
9388
+ _context17.next = 28;
8796
9389
  return this._services.users.myself._ensureFetched();
8797
9390
 
8798
9391
  case 28:
@@ -8813,10 +9406,10 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
8813
9406
 
8814
9407
  case 34:
8815
9408
  case "end":
8816
- return _context16.stop();
9409
+ return _context17.stop();
8817
9410
  }
8818
9411
  }
8819
- }, _callee16, this);
9412
+ }, _callee17, this);
8820
9413
  }));
8821
9414
 
8822
9415
  function _initialize() {
@@ -8856,14 +9449,14 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
8856
9449
  }], [{
8857
9450
  key: "create",
8858
9451
  value: function () {
8859
- var _create = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee17(token, options) {
9452
+ var _create = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee18(token, options) {
8860
9453
  var client;
8861
- return _regeneratorRuntime__default["default"].wrap(function _callee17$(_context17) {
9454
+ return _regeneratorRuntime__default["default"].wrap(function _callee18$(_context18) {
8862
9455
  while (1) {
8863
- switch (_context17.prev = _context17.next) {
9456
+ switch (_context18.prev = _context18.next) {
8864
9457
  case 0:
8865
9458
  if (!(options !== null && options !== void 0 && options.twilsockClient)) {
8866
- _context17.next = 2;
9459
+ _context18.next = 2;
8867
9460
  break;
8868
9461
  }
8869
9462
 
@@ -8871,18 +9464,18 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
8871
9464
 
8872
9465
  case 2:
8873
9466
  client = new Client_1(token, options);
8874
- _context17.next = 5;
9467
+ _context18.next = 5;
8875
9468
  return client._ensureReady;
8876
9469
 
8877
9470
  case 5:
8878
- return _context17.abrupt("return", client);
9471
+ return _context18.abrupt("return", client);
8879
9472
 
8880
9473
  case 6:
8881
9474
  case "end":
8882
- return _context17.stop();
9475
+ return _context18.stop();
8883
9476
  }
8884
9477
  }
8885
- }, _callee17);
9478
+ }, _callee18);
8886
9479
  }));
8887
9480
 
8888
9481
  function create(_x16, _x17) {
@@ -9066,6 +9659,8 @@ Object.defineProperty(exports, 'CancellablePromise', {
9066
9659
  get: function () { return mcsClient.CancellablePromise; }
9067
9660
  });
9068
9661
  exports.AggregatedDeliveryReceipt = AggregatedDeliveryReceipt;
9662
+ exports.ContentTemplate = ContentTemplate;
9663
+ exports.ContentTemplateVariable = ContentTemplateVariable;
9069
9664
  exports.Conversation = Conversation;
9070
9665
  exports.DetailedDeliveryReceipt = DetailedDeliveryReceipt;
9071
9666
  exports.Media = Media;