@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/browser.js CHANGED
@@ -128,6 +128,15 @@ This software includes platform.js under the following license.
128
128
  */
129
129
  'use strict';
130
130
 
131
+ var global =
132
+ typeof global !== "undefined"
133
+ ? global
134
+ : typeof self !== "undefined"
135
+ ? self
136
+ : typeof window !== "undefined"
137
+ ? window
138
+ : {};
139
+
131
140
  Object.defineProperty(exports, '__esModule', { value: true });
132
141
 
133
142
  require('core-js/modules/es.reflect.to-string-tag.js');
@@ -211,11 +220,13 @@ require('core-js/modules/es.array-buffer.constructor.js');
211
220
  require('isomorphic-form-data');
212
221
  require('core-js/modules/es.array.sort.js');
213
222
  require('core-js/modules/es.string.includes.js');
223
+ require('core-js/modules/es.string.starts-with.js');
214
224
  var deprecationDecorator = require('@twilio/deprecation-decorator');
225
+ require('core-js/modules/es.object.entries.js');
215
226
  require('core-js/modules/es.array.find.js');
216
227
  require('core-js/modules/es.array.splice.js');
217
- require('core-js/modules/es.object.entries.js');
218
228
  var uuid = require('uuid');
229
+ require('core-js/modules/es.object.freeze.js');
219
230
 
220
231
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
221
232
 
@@ -390,9 +401,9 @@ var Logger = /*#__PURE__*/function () {
390
401
  return Logger;
391
402
  }();
392
403
 
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; }
404
+ 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
405
 
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; }
406
+ 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
407
  var TYPING_TIMEOUT = 5;
397
408
  var HTTP_CACHE_LIFETIME = "PT5S";
398
409
  var CONSUMPTION_HORIZON_SENDING_INTERVAL = "PT5S";
@@ -433,7 +444,7 @@ var Configuration = /*#__PURE__*/_createClass__default["default"](function Confi
433
444
  emailBodiesAllowedContentTypes: configurationResponse.options.email_bodies_allowed_mime_types
434
445
  };
435
446
  this.typingIndicatorTimeoutOverride = constructorOptions.typingIndicatorTimeoutOverride;
436
- this.backoffConfiguration = _objectSpread$4({
447
+ this.backoffConfiguration = _objectSpread$5({
437
448
  min: MINIMUM_RETRY_DELAY,
438
449
  max: MAXIMUM_RETRY_DELAY,
439
450
  maxAttemptsCount: MAXIMUM_ATTEMPTS_COUNT
@@ -2547,18 +2558,260 @@ function DetailedDeliveryReceipt(descriptor) {
2547
2558
  this.dateUpdated = descriptor.date_updated;
2548
2559
  });
2549
2560
 
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; }
2561
+ var collectActions = function collectActions(actions) {
2562
+ return actions.map(function (action) {
2563
+ var _action$id, _action$index, _action$phone, _action$url;
2551
2564
 
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; }
2565
+ var rawData = JSON.stringify(action);
2566
+
2567
+ switch (action.type) {
2568
+ case "QUICK_REPLY":
2569
+ return {
2570
+ type: "reply",
2571
+ title: action.title,
2572
+ id: (_action$id = action.id) !== null && _action$id !== void 0 ? _action$id : "",
2573
+ index: (_action$index = action.index) !== null && _action$index !== void 0 ? _action$index : 0,
2574
+ rawData: rawData
2575
+ };
2576
+
2577
+ case "PHONE_NUMBER":
2578
+ return {
2579
+ type: "phone",
2580
+ title: action.title,
2581
+ phone: (_action$phone = action.phone) !== null && _action$phone !== void 0 ? _action$phone : "",
2582
+ rawData: rawData
2583
+ };
2584
+
2585
+ case "URL":
2586
+ return {
2587
+ type: "url",
2588
+ title: action.title,
2589
+ url: (_action$url = action.url) !== null && _action$url !== void 0 ? _action$url : "",
2590
+ rawData: rawData
2591
+ };
2592
+
2593
+ default:
2594
+ return {
2595
+ type: "other",
2596
+ rawData: rawData
2597
+ };
2598
+ }
2599
+ });
2600
+ };
2601
+
2602
+ var parseVariant = function parseVariant(type, data) {
2603
+ var rawData = JSON.stringify(data);
2604
+
2605
+ switch (type) {
2606
+ case "twilio/text":
2607
+ {
2608
+ var variant = data;
2609
+ return {
2610
+ type: "text",
2611
+ body: variant.body,
2612
+ rawData: rawData
2613
+ };
2614
+ }
2615
+
2616
+ case "twilio/media":
2617
+ {
2618
+ var _variant = data;
2619
+ return {
2620
+ type: "media",
2621
+ body: _variant.body,
2622
+ media: _variant.media,
2623
+ rawData: rawData
2624
+ };
2625
+ }
2626
+
2627
+ case "twilio/location":
2628
+ {
2629
+ var _variant2 = data;
2630
+ return {
2631
+ type: "location",
2632
+ longitude: _variant2.longitude,
2633
+ latitude: _variant2.latitude,
2634
+ label: _variant2.label,
2635
+ rawData: rawData
2636
+ };
2637
+ }
2638
+
2639
+ case "twilio/quick-reply":
2640
+ {
2641
+ var _variant3 = data;
2642
+ return {
2643
+ type: "quickReply",
2644
+ body: _variant3.body,
2645
+ replies: _variant3.actions,
2646
+ rawData: rawData
2647
+ };
2648
+ }
2649
+
2650
+ case "twilio/call-to-action":
2651
+ {
2652
+ var _variant4 = data;
2653
+ return {
2654
+ type: "callToAction",
2655
+ body: _variant4.body,
2656
+ actions: collectActions(_variant4.actions),
2657
+ rawData: rawData
2658
+ };
2659
+ }
2660
+
2661
+ case "twilio/list-picker":
2662
+ {
2663
+ var _variant5 = data;
2664
+ return {
2665
+ type: "listPicker",
2666
+ body: _variant5.body,
2667
+ button: _variant5.button,
2668
+ items: _variant5.items,
2669
+ rawData: rawData
2670
+ };
2671
+ }
2672
+
2673
+ case "twilio/card":
2674
+ {
2675
+ var _variant6$media, _variant6$actions;
2676
+
2677
+ var _variant6 = data;
2678
+ return {
2679
+ type: "card",
2680
+ title: _variant6.title,
2681
+ subtitle: _variant6.subtitle,
2682
+ media: (_variant6$media = _variant6.media) !== null && _variant6$media !== void 0 ? _variant6$media : [],
2683
+ actions: collectActions((_variant6$actions = _variant6.actions) !== null && _variant6$actions !== void 0 ? _variant6$actions : []),
2684
+ rawData: rawData
2685
+ };
2686
+ }
2687
+
2688
+ default:
2689
+ return {
2690
+ type: "other",
2691
+ rawData: rawData
2692
+ };
2693
+ }
2694
+ };
2695
+
2696
+ var collectVariants = function collectVariants(variants) {
2697
+ var variantsMap = new Map();
2698
+
2699
+ for (var _i = 0, _Object$entries = Object.entries(variants); _i < _Object$entries.length; _i++) {
2700
+ var _Object$entries$_i = _slicedToArray__default["default"](_Object$entries[_i], 2),
2701
+ key = _Object$entries$_i[0],
2702
+ value = _Object$entries$_i[1];
2703
+
2704
+ variantsMap.set(key, parseVariant(key, value));
2705
+ }
2706
+
2707
+ return variantsMap;
2708
+ };
2709
+ /**
2710
+ * Represents a variable for a content template. See
2711
+ * {@link ContentTemplate.variables}.
2712
+ */
2713
+
2714
+
2715
+ var ContentTemplateVariable = /*#__PURE__*/function () {
2716
+ function ContentTemplateVariable(
2717
+ /**
2718
+ * Name of the variable.
2719
+ */
2720
+ name,
2721
+ /**
2722
+ * Key of the variable
2723
+ */
2724
+ value) {
2725
+ _classCallCheck__default["default"](this, ContentTemplateVariable);
2726
+
2727
+ this.name = name;
2728
+ this.value = value;
2729
+ }
2730
+ /**
2731
+ * Copies the variable with a new value.
2732
+ *
2733
+ * @param value The new value for the variable.
2734
+ */
2735
+
2736
+
2737
+ _createClass__default["default"](ContentTemplateVariable, [{
2738
+ key: "copyWithValue",
2739
+ value: function copyWithValue(value) {
2740
+ return new ContentTemplateVariable(this.name, value);
2741
+ }
2742
+ }]);
2743
+
2744
+ return ContentTemplateVariable;
2745
+ }();
2746
+ /**
2747
+ * A rich content template.
2748
+ *
2749
+ * Use {@Link Client.getContentTemplates} to request all the templates available
2750
+ * for the current account.
2751
+ */
2752
+
2753
+
2754
+ var ContentTemplate = /*#__PURE__*/_createClass__default["default"](
2755
+ /**
2756
+ * The server-assigned unique identifier for the template.
2757
+ */
2758
+
2759
+ /**
2760
+ * Friendly name used to describe the content. Not visible to the recipient.
2761
+ */
2762
+
2763
+ /**
2764
+ * Variables used by this template.
2765
+ */
2766
+
2767
+ /**
2768
+ * Variants of the content. See @{link ContentData}.
2769
+ */
2770
+
2771
+ /**
2772
+ * Date of creation.
2773
+ */
2774
+
2775
+ /**
2776
+ * Date of the last update.
2777
+ */
2778
+
2779
+ /**
2780
+ * @internal
2781
+ */
2782
+ function ContentTemplate(contentTemplateResponse) {
2783
+ _classCallCheck__default["default"](this, ContentTemplate);
2784
+
2785
+ this.sid = contentTemplateResponse.sid;
2786
+ this.friendlyName = contentTemplateResponse.friendly_name;
2787
+ this.variables = Object.entries(JSON.parse(contentTemplateResponse.variables)).map(function (_ref) {
2788
+ var _ref2 = _slicedToArray__default["default"](_ref, 2),
2789
+ key = _ref2[0],
2790
+ value = _ref2[1];
2791
+
2792
+ return new ContentTemplateVariable(key, value);
2793
+ });
2794
+ this.variants = collectVariants(contentTemplateResponse.variants);
2795
+ this.dateCreated = new Date(contentTemplateResponse.date_created);
2796
+ this.dateUpdated = new Date(contentTemplateResponse.date_updated);
2797
+ });
2798
+
2799
+ 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; }
2800
+
2801
+ 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
2802
 
2554
2803
  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
2804
 
2556
2805
  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
2806
  var log$3 = Logger.scope("Message");
2807
+
2808
+ var XHR = // eslint-disable-next-line @typescript-eslint/no-var-requires
2809
+ global["XMLHttpRequest"] || require("xmlhttprequest").XMLHttpRequest;
2558
2810
  /**
2559
2811
  * A message in a conversation.
2560
2812
  */
2561
2813
 
2814
+
2562
2815
  var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
2563
2816
  _inherits__default["default"](Message, _ReplayEventEmitter);
2564
2817
 
@@ -2588,6 +2841,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
2588
2841
  index: index,
2589
2842
  author: data.author,
2590
2843
  subject: data.subject,
2844
+ contentSid: data.contentSid,
2591
2845
  body: (_data$text = data.text) !== null && _data$text !== void 0 ? _data$text : null,
2592
2846
  timestamp: data.timestamp ? new Date(data.timestamp) : null,
2593
2847
  dateUpdated: data.dateUpdated ? new Date(data.dateUpdated) : null,
@@ -2597,7 +2851,7 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
2597
2851
  media: data.type === "media" && data.media ? new Media(data.media, _this.services) : null,
2598
2852
  medias: data.type === "media" && data.medias ? data.medias.map(function (m) {
2599
2853
  return new Media(m, _this.services);
2600
- }) : data.type === "media" && data.media && !data.medias ? [new Media(_objectSpread$3(_objectSpread$3({}, data.media), {}, {
2854
+ }) : data.type === "media" && data.media && !data.medias ? [new Media(_objectSpread$4(_objectSpread$4({}, data.media), {}, {
2601
2855
  category: "media"
2602
2856
  }), _this.services)] : null,
2603
2857
  participantSid: (_data$memberSid = data.memberSid) !== null && _data$memberSid !== void 0 ? _data$memberSid : null,
@@ -2642,6 +2896,15 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
2642
2896
  get: function get() {
2643
2897
  return this.state.subject;
2644
2898
  }
2899
+ /**
2900
+ * Unique identifier of {@link ContentTemplate} for this message.
2901
+ */
2902
+
2903
+ }, {
2904
+ key: "contentSid",
2905
+ get: function get() {
2906
+ return this.state.contentSid;
2907
+ }
2645
2908
  /**
2646
2909
  * Body of the message.
2647
2910
  */
@@ -3303,6 +3566,147 @@ var Message = /*#__PURE__*/function (_ReplayEventEmitter) {
3303
3566
 
3304
3567
  return _getDetailedDeliveryReceiptsPaginator;
3305
3568
  }()
3569
+ /**
3570
+ * Get the {@link ContentData} for this message. Resolves to `null` when
3571
+ * {@link Message.contentSid} is null.
3572
+ */
3573
+
3574
+ }, {
3575
+ key: "getContentData",
3576
+ value: function getContentData() {
3577
+ var _this6 = this;
3578
+
3579
+ return new mcsClient.CancellablePromise( /*#__PURE__*/function () {
3580
+ var _ref2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee9(resolve, reject, onCancel) {
3581
+ var bodies, twilioPrefix, filteredMedias, contentMedia, urlPromise, url, jsonStringPromise, json, jsonString, dataType;
3582
+ return _regeneratorRuntime__default["default"].wrap(function _callee9$(_context9) {
3583
+ while (1) {
3584
+ switch (_context9.prev = _context9.next) {
3585
+ case 0:
3586
+ if (!(_this6.state.contentSid === null)) {
3587
+ _context9.next = 3;
3588
+ break;
3589
+ }
3590
+
3591
+ resolve(null);
3592
+ return _context9.abrupt("return");
3593
+
3594
+ case 3:
3595
+ bodies = _this6.getMediaByCategories(["body"]);
3596
+
3597
+ if (!(bodies === null)) {
3598
+ _context9.next = 7;
3599
+ break;
3600
+ }
3601
+
3602
+ resolve(null);
3603
+ return _context9.abrupt("return");
3604
+
3605
+ case 7:
3606
+ twilioPrefix = "application/x-vnd.com.twilio.rich.";
3607
+ filteredMedias = bodies.filter(function (media) {
3608
+ return media.contentType.startsWith(twilioPrefix);
3609
+ });
3610
+
3611
+ if (!(filteredMedias.length === 0)) {
3612
+ _context9.next = 12;
3613
+ break;
3614
+ }
3615
+
3616
+ resolve(null);
3617
+ return _context9.abrupt("return");
3618
+
3619
+ case 12:
3620
+ contentMedia = filteredMedias[0];
3621
+ urlPromise = contentMedia.getContentTemporaryUrl();
3622
+ onCancel(function () {
3623
+ urlPromise.cancel();
3624
+ });
3625
+ _context9.prev = 15;
3626
+ _context9.next = 18;
3627
+ return urlPromise;
3628
+
3629
+ case 18:
3630
+ url = _context9.sent;
3631
+ _context9.next = 25;
3632
+ break;
3633
+
3634
+ case 21:
3635
+ _context9.prev = 21;
3636
+ _context9.t0 = _context9["catch"](15);
3637
+ reject(_context9.t0);
3638
+ return _context9.abrupt("return");
3639
+
3640
+ case 25:
3641
+ if (!(url === null)) {
3642
+ _context9.next = 28;
3643
+ break;
3644
+ }
3645
+
3646
+ resolve(null);
3647
+ return _context9.abrupt("return");
3648
+
3649
+ case 28:
3650
+ jsonStringPromise = new Promise(function (resolve, reject) {
3651
+ var _url;
3652
+
3653
+ var isCancelled = false;
3654
+ var xhr = new XHR();
3655
+ xhr.open("GET", (_url = url) !== null && _url !== void 0 ? _url : "", true);
3656
+ xhr.responseType = "text";
3657
+
3658
+ xhr.onreadystatechange = function () {
3659
+ if (xhr.readyState !== 4 || isCancelled) {
3660
+ return;
3661
+ }
3662
+
3663
+ resolve(xhr.responseText);
3664
+ };
3665
+
3666
+ xhr.onerror = function () {
3667
+ reject(xhr.statusText);
3668
+ };
3669
+
3670
+ onCancel(function () {
3671
+ isCancelled = true;
3672
+ xhr.abort();
3673
+ reject(new Error("XHR has been aborted"));
3674
+ });
3675
+ xhr.send();
3676
+ });
3677
+ _context9.prev = 29;
3678
+ _context9.next = 32;
3679
+ return jsonStringPromise;
3680
+
3681
+ case 32:
3682
+ jsonString = _context9.sent;
3683
+ json = JSON.parse(jsonString);
3684
+ _context9.next = 40;
3685
+ break;
3686
+
3687
+ case 36:
3688
+ _context9.prev = 36;
3689
+ _context9.t1 = _context9["catch"](29);
3690
+ reject(_context9.t1);
3691
+ return _context9.abrupt("return");
3692
+
3693
+ case 40:
3694
+ dataType = contentMedia.contentType.replace(twilioPrefix, "").replace(".", "/");
3695
+ resolve(parseVariant(dataType, json.data));
3696
+
3697
+ case 42:
3698
+ case "end":
3699
+ return _context9.stop();
3700
+ }
3701
+ }
3702
+ }, _callee9, null, [[15, 21], [29, 36]]);
3703
+ }));
3704
+
3705
+ return function (_x8, _x9, _x10) {
3706
+ return _ref2.apply(this, arguments);
3707
+ };
3708
+ }());
3709
+ }
3306
3710
  }]);
3307
3711
 
3308
3712
  return Message;
@@ -3326,6 +3730,10 @@ __decorate([declarativeTypeValidator.validateTypesAsync(declarativeTypeValidator
3326
3730
 
3327
3731
  __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
3732
 
3733
+ 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; }
3734
+
3735
+ 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; }
3736
+
3329
3737
  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
3738
 
3331
3739
  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 +4008,11 @@ var Messages = /*#__PURE__*/function (_ReplayEventEmitter) {
3600
4008
  media_sids: media.map(function (m) {
3601
4009
  return m.sid;
3602
4010
  }),
3603
- attributes: typeof message.attributes !== "undefined" ? JSON.stringify(message.attributes) : undefined
4011
+ attributes: typeof message.attributes !== "undefined" ? JSON.stringify(message.attributes) : undefined,
4012
+ content_sid: message.contentSid,
4013
+ content_variables: typeof message.contentVariables !== "undefined" ? JSON.stringify(message.contentVariables.reduce(function (accum, current) {
4014
+ return _objectSpread$3(_objectSpread$3({}, accum), {}, _defineProperty__default["default"]({}, current.name, current.value));
4015
+ }, {})) : undefined
3604
4016
  });
3605
4017
  _context3.prev = 34;
3606
4018
  _context3.t4 = resolve;
@@ -4071,6 +4483,29 @@ var MessageBuilder = /*#__PURE__*/function () {
4071
4483
  this.emailHistories.set(contentType, history);
4072
4484
  return this;
4073
4485
  }
4486
+ /**
4487
+ * Adds {@link ContentTemplate} SID for the message alongside optional
4488
+ * variables. When no variables provided, the default values will be used.
4489
+ *
4490
+ * Adding the content SID converts the message to a rich message. In this
4491
+ * case, other fields are ignored and the message is sent using the content
4492
+ * from the the {@link ContentTemplate}.
4493
+ *
4494
+ * Use {@link Client.getContentTemplates} to request all available
4495
+ * {@link ContentTemplate}s.
4496
+ *
4497
+ * @param contentSid SID of the {@link ContentTemplate}
4498
+ * @param variables Custom variables to resolve the template.
4499
+ */
4500
+
4501
+ }, {
4502
+ key: "setContentTemplate",
4503
+ value: function setContentTemplate(contentSid) {
4504
+ var contentVariables = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
4505
+ this.message.contentSid = contentSid;
4506
+ this.message.contentVariables = contentVariables;
4507
+ return this;
4508
+ }
4074
4509
  /**
4075
4510
  * Adds media to the message.
4076
4511
  * @param payload Media to add.
@@ -7329,7 +7764,7 @@ function PushNotification(data) {
7329
7764
  this.data = data.data || {};
7330
7765
  });
7331
7766
 
7332
- var version = "2.2.2";
7767
+ var version = "2.3.0-rc.1";
7333
7768
 
7334
7769
  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
7770
 
@@ -7532,6 +7967,135 @@ var CommandExecutor = /*#__PURE__*/function () {
7532
7967
  return CommandExecutor;
7533
7968
  }();
7534
7969
 
7970
+ var ContentClient = /*#__PURE__*/function () {
7971
+ function ContentClient(_services) {
7972
+ var _pageSize = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100;
7973
+
7974
+ var _cacheTtlMs = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 5000;
7975
+
7976
+ _classCallCheck__default["default"](this, ContentClient);
7977
+
7978
+ _defineProperty__default["default"](this, "_cachedTemplates", null);
7979
+
7980
+ this._services = _services;
7981
+ this._pageSize = _pageSize;
7982
+ this._cacheTtlMs = _cacheTtlMs;
7983
+ }
7984
+
7985
+ _createClass__default["default"](ContentClient, [{
7986
+ key: "getContentTemplates",
7987
+ value: function () {
7988
+ var _getContentTemplates = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee() {
7989
+ var _this = this;
7990
+
7991
+ var _yield$this$_fetchCon, _yield$this$_fetchCon2, templatesPage, nextToken, templates, _yield$this$_fetchCon3, _yield$this$_fetchCon4;
7992
+
7993
+ return _regeneratorRuntime__default["default"].wrap(function _callee$(_context) {
7994
+ while (1) {
7995
+ switch (_context.prev = _context.next) {
7996
+ case 0:
7997
+ if (!(this._cachedTemplates !== null)) {
7998
+ _context.next = 2;
7999
+ break;
8000
+ }
8001
+
8002
+ return _context.abrupt("return", this._cachedTemplates);
8003
+
8004
+ case 2:
8005
+ _context.next = 4;
8006
+ return this._fetchContentTemplates();
8007
+
8008
+ case 4:
8009
+ _yield$this$_fetchCon = _context.sent;
8010
+ _yield$this$_fetchCon2 = _slicedToArray__default["default"](_yield$this$_fetchCon, 2);
8011
+ templatesPage = _yield$this$_fetchCon2[0];
8012
+ nextToken = _yield$this$_fetchCon2[1];
8013
+ templates = templatesPage;
8014
+
8015
+ case 9:
8016
+ if (!(nextToken !== null)) {
8017
+ _context.next = 19;
8018
+ break;
8019
+ }
8020
+
8021
+ _context.next = 12;
8022
+ return this._fetchContentTemplates(nextToken);
8023
+
8024
+ case 12:
8025
+ _yield$this$_fetchCon3 = _context.sent;
8026
+ _yield$this$_fetchCon4 = _slicedToArray__default["default"](_yield$this$_fetchCon3, 2);
8027
+ templatesPage = _yield$this$_fetchCon4[0];
8028
+ nextToken = _yield$this$_fetchCon4[1];
8029
+ templates = [].concat(_toConsumableArray__default["default"](templates), _toConsumableArray__default["default"](templatesPage));
8030
+ _context.next = 9;
8031
+ break;
8032
+
8033
+ case 19:
8034
+ this._cachedTemplates = Object.freeze(templates);
8035
+ setTimeout(function () {
8036
+ _this._cachedTemplates = null;
8037
+ }, this._cacheTtlMs);
8038
+ return _context.abrupt("return", templates);
8039
+
8040
+ case 22:
8041
+ case "end":
8042
+ return _context.stop();
8043
+ }
8044
+ }
8045
+ }, _callee, this);
8046
+ }));
8047
+
8048
+ function getContentTemplates() {
8049
+ return _getContentTemplates.apply(this, arguments);
8050
+ }
8051
+
8052
+ return getContentTemplates;
8053
+ }()
8054
+ }, {
8055
+ key: "_fetchContentTemplates",
8056
+ value: function () {
8057
+ var _fetchContentTemplates2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee2(pageToken) {
8058
+ var contentTemplatesUrl, url, response;
8059
+ return _regeneratorRuntime__default["default"].wrap(function _callee2$(_context2) {
8060
+ while (1) {
8061
+ switch (_context2.prev = _context2.next) {
8062
+ case 0:
8063
+ contentTemplatesUrl = "Client/v2/ContentTemplates";
8064
+ url = new UriBuilder(contentTemplatesUrl);
8065
+ url.arg("PageSize", this._pageSize);
8066
+
8067
+ if (pageToken !== undefined) {
8068
+ url.arg("PageToken", pageToken);
8069
+ }
8070
+
8071
+ _context2.next = 6;
8072
+ return this._services.commandExecutor.fetchResource(url.build());
8073
+
8074
+ case 6:
8075
+ response = _context2.sent;
8076
+ return _context2.abrupt("return", [response.templates.map(function (template) {
8077
+ return new ContentTemplate(template);
8078
+ }), response.meta.next_token]);
8079
+
8080
+ case 8:
8081
+ case "end":
8082
+ return _context2.stop();
8083
+ }
8084
+ }
8085
+ }, _callee2, this);
8086
+ }));
8087
+
8088
+ function _fetchContentTemplates(_x) {
8089
+ return _fetchContentTemplates2.apply(this, arguments);
8090
+ }
8091
+
8092
+ return _fetchContentTemplates;
8093
+ }()
8094
+ }]);
8095
+
8096
+ return ContentClient;
8097
+ }();
8098
+
7535
8099
  var _class;
7536
8100
 
7537
8101
  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 +8485,7 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
7921
8485
  _this._services.commandExecutor = new CommandExecutor(baseUrl, {
7922
8486
  transport: _this._options.transport
7923
8487
  }, productId);
8488
+ _this._services.contentClient = new ContentClient(_this._services);
7924
8489
 
7925
8490
  var emitFailed = function emitFailed(error) {
7926
8491
  _this._rejectEnsureReady(error);
@@ -8693,6 +9258,43 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
8693
9258
  });
8694
9259
  return this.getTemporaryContentUrlsForMediaSids(sids);
8695
9260
  }
9261
+ /**
9262
+ * Returns rich content templates belonging to the account. Rich content
9263
+ * templates can be created via the Twilio console or the REST API.
9264
+ */
9265
+
9266
+ }, {
9267
+ key: "getContentTemplates",
9268
+ value: function () {
9269
+ var _getContentTemplates = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee16() {
9270
+ return _regeneratorRuntime__default["default"].wrap(function _callee16$(_context16) {
9271
+ while (1) {
9272
+ switch (_context16.prev = _context16.next) {
9273
+ case 0:
9274
+ _context16.next = 2;
9275
+ return this._ensureReady;
9276
+
9277
+ case 2:
9278
+ _context16.next = 4;
9279
+ return this._services.contentClient.getContentTemplates();
9280
+
9281
+ case 4:
9282
+ return _context16.abrupt("return", _context16.sent);
9283
+
9284
+ case 5:
9285
+ case "end":
9286
+ return _context16.stop();
9287
+ }
9288
+ }
9289
+ }, _callee16, this);
9290
+ }));
9291
+
9292
+ function getContentTemplates() {
9293
+ return _getContentTemplates.apply(this, arguments);
9294
+ }
9295
+
9296
+ return getContentTemplates;
9297
+ }()
8696
9298
  /**
8697
9299
  * Initialize the client.
8698
9300
  */
@@ -8700,19 +9302,19 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
8700
9302
  }, {
8701
9303
  key: "_initialize",
8702
9304
  value: function () {
8703
- var _initialize2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee16() {
9305
+ var _initialize2 = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee17() {
8704
9306
  var _this3 = this;
8705
9307
 
8706
9308
  var configurationResponse;
8707
- return _regeneratorRuntime__default["default"].wrap(function _callee16$(_context16) {
9309
+ return _regeneratorRuntime__default["default"].wrap(function _callee17$(_context17) {
8708
9310
  while (1) {
8709
- switch (_context16.prev = _context16.next) {
9311
+ switch (_context17.prev = _context17.next) {
8710
9312
  case 0:
8711
- _context16.next = 2;
9313
+ _context17.next = 2;
8712
9314
  return this._services.commandExecutor.fetchResource("Client/v2/Configuration");
8713
9315
 
8714
9316
  case 2:
8715
- configurationResponse = _context16.sent;
9317
+ configurationResponse = _context17.sent;
8716
9318
  this._configuration = new Configuration(this._options, configurationResponse, Client_1._logger);
8717
9319
 
8718
9320
  this._myself._resolveInitialization(this._configuration, this._configuration.userIdentity, this._configuration.userInfo, true);
@@ -8792,7 +9394,7 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
8792
9394
  }).catch(function (error) {
8793
9395
  throw error;
8794
9396
  });
8795
- _context16.next = 28;
9397
+ _context17.next = 28;
8796
9398
  return this._services.users.myself._ensureFetched();
8797
9399
 
8798
9400
  case 28:
@@ -8813,10 +9415,10 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
8813
9415
 
8814
9416
  case 34:
8815
9417
  case "end":
8816
- return _context16.stop();
9418
+ return _context17.stop();
8817
9419
  }
8818
9420
  }
8819
- }, _callee16, this);
9421
+ }, _callee17, this);
8820
9422
  }));
8821
9423
 
8822
9424
  function _initialize() {
@@ -8856,14 +9458,14 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
8856
9458
  }], [{
8857
9459
  key: "create",
8858
9460
  value: function () {
8859
- var _create = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee17(token, options) {
9461
+ var _create = _asyncToGenerator__default["default"]( /*#__PURE__*/_regeneratorRuntime__default["default"].mark(function _callee18(token, options) {
8860
9462
  var client;
8861
- return _regeneratorRuntime__default["default"].wrap(function _callee17$(_context17) {
9463
+ return _regeneratorRuntime__default["default"].wrap(function _callee18$(_context18) {
8862
9464
  while (1) {
8863
- switch (_context17.prev = _context17.next) {
9465
+ switch (_context18.prev = _context18.next) {
8864
9466
  case 0:
8865
9467
  if (!(options !== null && options !== void 0 && options.twilsockClient)) {
8866
- _context17.next = 2;
9468
+ _context18.next = 2;
8867
9469
  break;
8868
9470
  }
8869
9471
 
@@ -8871,18 +9473,18 @@ exports.Client = Client_1 = (_class = /*#__PURE__*/function (_ReplayEventEmitter
8871
9473
 
8872
9474
  case 2:
8873
9475
  client = new Client_1(token, options);
8874
- _context17.next = 5;
9476
+ _context18.next = 5;
8875
9477
  return client._ensureReady;
8876
9478
 
8877
9479
  case 5:
8878
- return _context17.abrupt("return", client);
9480
+ return _context18.abrupt("return", client);
8879
9481
 
8880
9482
  case 6:
8881
9483
  case "end":
8882
- return _context17.stop();
9484
+ return _context18.stop();
8883
9485
  }
8884
9486
  }
8885
- }, _callee17);
9487
+ }, _callee18);
8886
9488
  }));
8887
9489
 
8888
9490
  function create(_x16, _x17) {
@@ -9066,6 +9668,8 @@ Object.defineProperty(exports, 'CancellablePromise', {
9066
9668
  get: function () { return mcsClient.CancellablePromise; }
9067
9669
  });
9068
9670
  exports.AggregatedDeliveryReceipt = AggregatedDeliveryReceipt;
9671
+ exports.ContentTemplate = ContentTemplate;
9672
+ exports.ContentTemplateVariable = ContentTemplateVariable;
9069
9673
  exports.Conversation = Conversation;
9070
9674
  exports.DetailedDeliveryReceipt = DetailedDeliveryReceipt;
9071
9675
  exports.Media = Media;