@twilio/conversations 3.0.0-rc.9 → 3.0.1-rc.102
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.
- package/README.md +38 -28
- package/builds/browser.js +1659 -264
- package/builds/browser.js.map +1 -1
- package/builds/lib.d.ts +650 -25
- package/builds/lib.js +1650 -264
- package/builds/lib.js.map +1 -1
- package/builds/twilio-conversations.js +4300 -1842
- package/builds/twilio-conversations.min.js +1 -1
- package/dist/aggregated-delivery-receipt.js +10 -1
- package/dist/aggregated-delivery-receipt.js.map +1 -1
- package/dist/channel-metadata-client.js +192 -0
- package/dist/channel-metadata-client.js.map +1 -0
- package/dist/client.js +70 -10
- package/dist/client.js.map +1 -1
- package/dist/command-executor.js +48 -6
- package/dist/command-executor.js.map +1 -1
- package/dist/configuration.js +14 -3
- package/dist/configuration.js.map +1 -1
- package/dist/content-client.js +184 -0
- package/dist/content-client.js.map +1 -0
- package/dist/content-template.js +310 -0
- package/dist/content-template.js.map +1 -0
- package/dist/conversation.js +59 -16
- package/dist/conversation.js.map +1 -1
- package/dist/data/conversations.js +25 -3
- package/dist/data/conversations.js.map +1 -1
- package/dist/data/messages.js +23 -6
- package/dist/data/messages.js.map +1 -1
- package/dist/data/participants.js +17 -8
- package/dist/data/participants.js.map +1 -1
- package/dist/data/users.js +9 -0
- package/dist/data/users.js.map +1 -1
- package/dist/detailed-delivery-receipt.js +9 -0
- package/dist/detailed-delivery-receipt.js.map +1 -1
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/notification-types.js +9 -0
- package/dist/interfaces/notification-types.js.map +1 -1
- package/dist/interfaces/{attributes.js → rules.js} +26 -7
- package/dist/interfaces/rules.js.map +1 -0
- package/dist/logger.js +9 -0
- package/dist/logger.js.map +1 -1
- package/dist/media.js +9 -0
- package/dist/media.js.map +1 -1
- package/dist/message-builder.js +77 -6
- package/dist/message-builder.js.map +1 -1
- package/dist/message.js +156 -12
- package/dist/message.js.map +1 -1
- package/dist/node_modules/quick-lru/index.js +265 -0
- package/dist/node_modules/quick-lru/index.js.map +1 -0
- package/dist/node_modules/tslib/tslib.es6.js +9 -0
- package/dist/node_modules/tslib/tslib.es6.js.map +1 -1
- package/dist/packages/conversations/package.json.js +10 -1
- package/dist/packages/conversations/package.json.js.map +1 -1
- package/dist/participant.js +11 -2
- package/dist/participant.js.map +1 -1
- package/dist/push-notification.js +9 -0
- package/dist/push-notification.js.map +1 -1
- package/dist/rest-paginator.js +9 -0
- package/dist/rest-paginator.js.map +1 -1
- package/dist/services/network.js +9 -0
- package/dist/services/network.js.map +1 -1
- package/dist/services/typing-indicator.js +9 -0
- package/dist/services/typing-indicator.js.map +1 -1
- package/dist/unsent-message.js +9 -0
- package/dist/unsent-message.js.map +1 -1
- package/dist/user.js +20 -3
- package/dist/user.js.map +1 -1
- package/dist/util/deferred.js +9 -0
- package/dist/util/deferred.js.map +1 -1
- package/dist/util/index.js +9 -0
- package/dist/util/index.js.map +1 -1
- package/docs/assets/js/search.js +1 -1
- package/docs/classes/AggregatedDeliveryReceipt.html +1 -1
- package/docs/classes/ChannelMetadata.html +3050 -0
- package/docs/classes/Client.html +64 -25
- package/docs/classes/ContentTemplate.html +3116 -0
- package/docs/classes/ContentTemplateVariable.html +3116 -0
- package/docs/classes/Conversation.html +14 -9
- package/docs/classes/Message.html +76 -5
- package/docs/classes/MessageBuilder.html +41 -0
- package/docs/classes/Participant.html +2 -2
- package/docs/index.html +849 -25
- package/docs/interfaces/ClientOptions.html +16 -0
- package/docs/modules.html +848 -24
- package/package.json +18 -14
- package/CHANGELOG.md +0 -509
- package/dist/interfaces/attributes.js.map +0 -1
@@ -0,0 +1,184 @@
|
|
1
|
+
/*
|
2
|
+
@license
|
3
|
+
The following license applies to all parts of this software except as
|
4
|
+
documented below.
|
5
|
+
|
6
|
+
Copyright (c) 2019, Twilio, inc.
|
7
|
+
All rights reserved.
|
8
|
+
|
9
|
+
Redistribution and use in source and binary forms, with or without
|
10
|
+
modification, are permitted provided that the following conditions are
|
11
|
+
met:
|
12
|
+
|
13
|
+
1. Redistributions of source code must retain the above copyright
|
14
|
+
notice, this list of conditions and the following disclaimer.
|
15
|
+
|
16
|
+
2. Redistributions in binary form must reproduce the above copyright
|
17
|
+
notice, this list of conditions and the following disclaimer in
|
18
|
+
the documentation and/or other materials provided with the
|
19
|
+
distribution.
|
20
|
+
|
21
|
+
3. Neither the name of Twilio nor the names of its contributors may
|
22
|
+
be used to endorse or promote products derived from this software
|
23
|
+
without specific prior written permission.
|
24
|
+
|
25
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
26
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
27
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
28
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
29
|
+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
30
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
31
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
32
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
33
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
34
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
35
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
36
|
+
|
37
|
+
This software includes javascript-state-machine under the following license.
|
38
|
+
|
39
|
+
Copyright (c) 2012, 2013, 2014, 2015, Jake Gordon and contributors
|
40
|
+
|
41
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
42
|
+
of this software and associated documentation files (the "Software"), to deal
|
43
|
+
in the Software without restriction, including without limitation the rights
|
44
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
45
|
+
copies of the Software, and to permit persons to whom the Software is
|
46
|
+
furnished to do so, subject to the following conditions:
|
47
|
+
|
48
|
+
The above copyright notice and this permission notice shall be included in all
|
49
|
+
copies or substantial portions of the Software.
|
50
|
+
|
51
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
52
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
53
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
54
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
55
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
56
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
57
|
+
|
58
|
+
This software includes loglevel under the following license.
|
59
|
+
|
60
|
+
Copyright (c) 2013 Tim Perry
|
61
|
+
|
62
|
+
Permission is hereby granted, free of charge, to any person
|
63
|
+
obtaining a copy of this software and associated documentation
|
64
|
+
files (the "Software"), to deal in the Software without
|
65
|
+
restriction, including without limitation the rights to use,
|
66
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
67
|
+
copies of the Software, and to permit persons to whom the
|
68
|
+
Software is furnished to do so, subject to the following
|
69
|
+
conditions:
|
70
|
+
|
71
|
+
The above copyright notice and this permission notice shall be
|
72
|
+
included in all copies or substantial portions of the Software.
|
73
|
+
|
74
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
75
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
76
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
77
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
78
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
79
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
80
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
81
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
82
|
+
|
83
|
+
This software includes q under the following license.
|
84
|
+
|
85
|
+
Copyright 2009–2014 Kristopher Michael Kowal. All rights reserved.
|
86
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
87
|
+
of this software and associated documentation files (the "Software"), to
|
88
|
+
deal in the Software without restriction, including without limitation the
|
89
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
90
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
91
|
+
furnished to do so, subject to the following conditions:
|
92
|
+
|
93
|
+
The above copyright notice and this permission notice shall be included in
|
94
|
+
all copies or substantial portions of the Software.
|
95
|
+
|
96
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
97
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
98
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
99
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
100
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
101
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
102
|
+
IN THE SOFTWARE.
|
103
|
+
|
104
|
+
This software includes platform.js under the following license.
|
105
|
+
|
106
|
+
Copyright 2014 Benjamin Tan <https://d10.github.io/>
|
107
|
+
Copyright 2011-2015 John-David Dalton <http://allyoucanleet.com/>
|
108
|
+
|
109
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
110
|
+
a copy of this software and associated documentation files (the
|
111
|
+
"Software"), to deal in the Software without restriction, including
|
112
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
113
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
114
|
+
permit persons to whom the Software is furnished to do so, subject to
|
115
|
+
the following conditions:
|
116
|
+
|
117
|
+
The above copyright notice and this permission notice shall be
|
118
|
+
included in all copies or substantial portions of the Software.
|
119
|
+
|
120
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
121
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
122
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
123
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
124
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
125
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
126
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
127
|
+
|
128
|
+
*/
|
129
|
+
'use strict';
|
130
|
+
|
131
|
+
var global =
|
132
|
+
typeof global !== "undefined"
|
133
|
+
? global
|
134
|
+
: typeof self !== "undefined"
|
135
|
+
? self
|
136
|
+
: typeof window !== "undefined"
|
137
|
+
? window
|
138
|
+
: {};
|
139
|
+
|
140
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
141
|
+
|
142
|
+
var contentTemplate = require('./content-template.js');
|
143
|
+
var index = require('./util/index.js');
|
144
|
+
|
145
|
+
class ContentClient {
|
146
|
+
constructor(_services, _pageSize = 100, _cacheTtlMs = 5000) {
|
147
|
+
this._services = _services;
|
148
|
+
this._pageSize = _pageSize;
|
149
|
+
this._cacheTtlMs = _cacheTtlMs;
|
150
|
+
this._cachedTemplates = null;
|
151
|
+
}
|
152
|
+
async getContentTemplates() {
|
153
|
+
if (this._cachedTemplates !== null) {
|
154
|
+
return this._cachedTemplates;
|
155
|
+
}
|
156
|
+
let [templatesPage, nextToken] = await this._fetchContentTemplates();
|
157
|
+
let templates = templatesPage;
|
158
|
+
while (nextToken !== null) {
|
159
|
+
[templatesPage, nextToken] = await this._fetchContentTemplates(nextToken);
|
160
|
+
templates = [...templates, ...templatesPage];
|
161
|
+
}
|
162
|
+
this._cachedTemplates = Object.freeze(templates);
|
163
|
+
setTimeout(() => {
|
164
|
+
this._cachedTemplates = null;
|
165
|
+
}, this._cacheTtlMs);
|
166
|
+
return templates;
|
167
|
+
}
|
168
|
+
async _fetchContentTemplates(pageToken) {
|
169
|
+
const contentTemplatesUrl = "Client/v2/ContentTemplates";
|
170
|
+
const url = new index.UriBuilder(contentTemplatesUrl);
|
171
|
+
url.arg("PageSize", this._pageSize);
|
172
|
+
if (pageToken !== undefined) {
|
173
|
+
url.arg("PageToken", pageToken);
|
174
|
+
}
|
175
|
+
const response = await this._services.commandExecutor.fetchResource(url.build());
|
176
|
+
return [
|
177
|
+
response.templates.map((template) => new contentTemplate.ContentTemplate(template)),
|
178
|
+
response.meta.next_token,
|
179
|
+
];
|
180
|
+
}
|
181
|
+
}
|
182
|
+
|
183
|
+
exports.ContentClient = ContentClient;
|
184
|
+
//# sourceMappingURL=content-client.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"content-client.js","sources":["../src/content-client.ts"],"sourcesContent":["import { CommandExecutor } from \"./command-executor\";\nimport { ContentTemplate } from \"./content-template\";\nimport { ContentTemplatesResponse } from \"./interfaces/commands/content-templates-response\";\nimport { UriBuilder } from \"./util\";\n\ntype ContentClientServices = {\n commandExecutor: CommandExecutor;\n};\n\nclass ContentClient {\n private _cachedTemplates: Readonly<ContentTemplate[]> | null = null;\n\n public constructor(\n private readonly _services: ContentClientServices,\n private readonly _pageSize: number = 100,\n private readonly _cacheTtlMs: number = 5_000\n ) {}\n\n public async getContentTemplates(): Promise<Readonly<ContentTemplate[]>> {\n if (this._cachedTemplates !== null) {\n return this._cachedTemplates;\n }\n\n let [templatesPage, nextToken] = await this._fetchContentTemplates();\n let templates = templatesPage;\n\n while (nextToken !== null) {\n [templatesPage, nextToken] = await this._fetchContentTemplates(nextToken);\n templates = [...templates, ...templatesPage];\n }\n\n this._cachedTemplates = Object.freeze(templates);\n\n setTimeout(() => {\n this._cachedTemplates = null;\n }, this._cacheTtlMs);\n\n return templates;\n }\n\n private async _fetchContentTemplates(\n pageToken?: string\n ): Promise<[ContentTemplate[], string?]> {\n const contentTemplatesUrl = \"Client/v2/ContentTemplates\";\n const url = new UriBuilder(contentTemplatesUrl);\n\n url.arg(\"PageSize\", this._pageSize);\n\n if (pageToken !== undefined) {\n url.arg(\"PageToken\", pageToken);\n }\n\n const response = await this._services.commandExecutor.fetchResource<\n void,\n ContentTemplatesResponse\n >(url.build());\n\n return [\n response.templates.map((template) => new ContentTemplate(template)),\n response.meta.next_token,\n ];\n }\n}\n\nexport { ContentClient };\n"],"names":["UriBuilder","ContentTemplate"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA,MAAM,aAAa,CAAA;AAGjB,IAAA,WAAA,CACmB,SAAgC,EAChC,SAAA,GAAoB,GAAG,EACvB,cAAsB,IAAK,EAAA;QAF3B,IAAS,CAAA,SAAA,GAAT,SAAS,CAAuB;QAChC,IAAS,CAAA,SAAA,GAAT,SAAS,CAAc;QACvB,IAAW,CAAA,WAAA,GAAX,WAAW,CAAgB;QALtC,IAAgB,CAAA,gBAAA,GAA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AC,SAAS,CAAC,GAAG,CAAC,CAAC,QAAQ,KAAK,IAAIC,+BAAe,CAAC,QAAQ,CAAC,CAAC;YACnE,QAAQ,CAAC,IAAI,CAAC,UAAU;SACzB,CAAC;KACH;AACF;;;;"}
|
@@ -0,0 +1,310 @@
|
|
1
|
+
/*
|
2
|
+
@license
|
3
|
+
The following license applies to all parts of this software except as
|
4
|
+
documented below.
|
5
|
+
|
6
|
+
Copyright (c) 2019, Twilio, inc.
|
7
|
+
All rights reserved.
|
8
|
+
|
9
|
+
Redistribution and use in source and binary forms, with or without
|
10
|
+
modification, are permitted provided that the following conditions are
|
11
|
+
met:
|
12
|
+
|
13
|
+
1. Redistributions of source code must retain the above copyright
|
14
|
+
notice, this list of conditions and the following disclaimer.
|
15
|
+
|
16
|
+
2. Redistributions in binary form must reproduce the above copyright
|
17
|
+
notice, this list of conditions and the following disclaimer in
|
18
|
+
the documentation and/or other materials provided with the
|
19
|
+
distribution.
|
20
|
+
|
21
|
+
3. Neither the name of Twilio nor the names of its contributors may
|
22
|
+
be used to endorse or promote products derived from this software
|
23
|
+
without specific prior written permission.
|
24
|
+
|
25
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
26
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
27
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
28
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
29
|
+
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
30
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
31
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
32
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
33
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
34
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
35
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
36
|
+
|
37
|
+
This software includes javascript-state-machine under the following license.
|
38
|
+
|
39
|
+
Copyright (c) 2012, 2013, 2014, 2015, Jake Gordon and contributors
|
40
|
+
|
41
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
42
|
+
of this software and associated documentation files (the "Software"), to deal
|
43
|
+
in the Software without restriction, including without limitation the rights
|
44
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
45
|
+
copies of the Software, and to permit persons to whom the Software is
|
46
|
+
furnished to do so, subject to the following conditions:
|
47
|
+
|
48
|
+
The above copyright notice and this permission notice shall be included in all
|
49
|
+
copies or substantial portions of the Software.
|
50
|
+
|
51
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
52
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
53
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
54
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
55
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
56
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
57
|
+
|
58
|
+
This software includes loglevel under the following license.
|
59
|
+
|
60
|
+
Copyright (c) 2013 Tim Perry
|
61
|
+
|
62
|
+
Permission is hereby granted, free of charge, to any person
|
63
|
+
obtaining a copy of this software and associated documentation
|
64
|
+
files (the "Software"), to deal in the Software without
|
65
|
+
restriction, including without limitation the rights to use,
|
66
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
67
|
+
copies of the Software, and to permit persons to whom the
|
68
|
+
Software is furnished to do so, subject to the following
|
69
|
+
conditions:
|
70
|
+
|
71
|
+
The above copyright notice and this permission notice shall be
|
72
|
+
included in all copies or substantial portions of the Software.
|
73
|
+
|
74
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
75
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
76
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
77
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
78
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
79
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
80
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
81
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
82
|
+
|
83
|
+
This software includes q under the following license.
|
84
|
+
|
85
|
+
Copyright 2009–2014 Kristopher Michael Kowal. All rights reserved.
|
86
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
87
|
+
of this software and associated documentation files (the "Software"), to
|
88
|
+
deal in the Software without restriction, including without limitation the
|
89
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
90
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
91
|
+
furnished to do so, subject to the following conditions:
|
92
|
+
|
93
|
+
The above copyright notice and this permission notice shall be included in
|
94
|
+
all copies or substantial portions of the Software.
|
95
|
+
|
96
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
97
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
98
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
99
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
100
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
101
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
102
|
+
IN THE SOFTWARE.
|
103
|
+
|
104
|
+
This software includes platform.js under the following license.
|
105
|
+
|
106
|
+
Copyright 2014 Benjamin Tan <https://d10.github.io/>
|
107
|
+
Copyright 2011-2015 John-David Dalton <http://allyoucanleet.com/>
|
108
|
+
|
109
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
110
|
+
a copy of this software and associated documentation files (the
|
111
|
+
"Software"), to deal in the Software without restriction, including
|
112
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
113
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
114
|
+
permit persons to whom the Software is furnished to do so, subject to
|
115
|
+
the following conditions:
|
116
|
+
|
117
|
+
The above copyright notice and this permission notice shall be
|
118
|
+
included in all copies or substantial portions of the Software.
|
119
|
+
|
120
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
121
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
122
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
123
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
124
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
125
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
126
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
127
|
+
|
128
|
+
*/
|
129
|
+
'use strict';
|
130
|
+
|
131
|
+
var global =
|
132
|
+
typeof global !== "undefined"
|
133
|
+
? global
|
134
|
+
: typeof self !== "undefined"
|
135
|
+
? self
|
136
|
+
: typeof window !== "undefined"
|
137
|
+
? window
|
138
|
+
: {};
|
139
|
+
|
140
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
141
|
+
|
142
|
+
const collectActions = (actions) => {
|
143
|
+
return actions.map((action) => {
|
144
|
+
var _a, _b, _c, _d;
|
145
|
+
const rawData = JSON.stringify(action);
|
146
|
+
switch (action.type) {
|
147
|
+
case "QUICK_REPLY":
|
148
|
+
return {
|
149
|
+
type: "reply",
|
150
|
+
title: action.title,
|
151
|
+
id: (_a = action.id) !== null && _a !== void 0 ? _a : "",
|
152
|
+
index: (_b = action.index) !== null && _b !== void 0 ? _b : 0,
|
153
|
+
rawData,
|
154
|
+
};
|
155
|
+
case "PHONE_NUMBER":
|
156
|
+
return {
|
157
|
+
type: "phone",
|
158
|
+
title: action.title,
|
159
|
+
phone: (_c = action.phone) !== null && _c !== void 0 ? _c : "",
|
160
|
+
rawData,
|
161
|
+
};
|
162
|
+
case "URL":
|
163
|
+
return {
|
164
|
+
type: "url",
|
165
|
+
title: action.title,
|
166
|
+
url: (_d = action.url) !== null && _d !== void 0 ? _d : "",
|
167
|
+
rawData,
|
168
|
+
};
|
169
|
+
default:
|
170
|
+
return {
|
171
|
+
type: "other",
|
172
|
+
rawData,
|
173
|
+
};
|
174
|
+
}
|
175
|
+
});
|
176
|
+
};
|
177
|
+
const parseVariant = (type, data) => {
|
178
|
+
var _a, _b;
|
179
|
+
const rawData = JSON.stringify(data);
|
180
|
+
switch (type) {
|
181
|
+
case "twilio/text": {
|
182
|
+
const variant = data;
|
183
|
+
return {
|
184
|
+
type: "text",
|
185
|
+
body: variant.body,
|
186
|
+
rawData,
|
187
|
+
};
|
188
|
+
}
|
189
|
+
case "twilio/media": {
|
190
|
+
const variant = data;
|
191
|
+
return {
|
192
|
+
type: "media",
|
193
|
+
body: variant.body,
|
194
|
+
media: variant.media,
|
195
|
+
rawData,
|
196
|
+
};
|
197
|
+
}
|
198
|
+
case "twilio/location": {
|
199
|
+
const variant = data;
|
200
|
+
return {
|
201
|
+
type: "location",
|
202
|
+
longitude: variant.longitude,
|
203
|
+
latitude: variant.latitude,
|
204
|
+
label: variant.label,
|
205
|
+
rawData,
|
206
|
+
};
|
207
|
+
}
|
208
|
+
case "twilio/quick-reply": {
|
209
|
+
const variant = data;
|
210
|
+
return {
|
211
|
+
type: "quickReply",
|
212
|
+
body: variant.body,
|
213
|
+
replies: variant.actions,
|
214
|
+
rawData,
|
215
|
+
};
|
216
|
+
}
|
217
|
+
case "twilio/call-to-action": {
|
218
|
+
const variant = data;
|
219
|
+
return {
|
220
|
+
type: "callToAction",
|
221
|
+
body: variant.body,
|
222
|
+
actions: collectActions(variant.actions),
|
223
|
+
rawData,
|
224
|
+
};
|
225
|
+
}
|
226
|
+
case "twilio/list-picker": {
|
227
|
+
const variant = data;
|
228
|
+
return {
|
229
|
+
type: "listPicker",
|
230
|
+
body: variant.body,
|
231
|
+
button: variant.button,
|
232
|
+
items: variant.items,
|
233
|
+
rawData,
|
234
|
+
};
|
235
|
+
}
|
236
|
+
case "twilio/card": {
|
237
|
+
const variant = data;
|
238
|
+
return {
|
239
|
+
type: "card",
|
240
|
+
title: variant.title,
|
241
|
+
subtitle: variant.subtitle,
|
242
|
+
media: (_a = variant.media) !== null && _a !== void 0 ? _a : [],
|
243
|
+
actions: collectActions((_b = variant.actions) !== null && _b !== void 0 ? _b : []),
|
244
|
+
rawData,
|
245
|
+
};
|
246
|
+
}
|
247
|
+
default:
|
248
|
+
return {
|
249
|
+
type: "other",
|
250
|
+
rawData,
|
251
|
+
};
|
252
|
+
}
|
253
|
+
};
|
254
|
+
const collectVariants = (variants) => {
|
255
|
+
const variantsMap = new Map();
|
256
|
+
for (const [key, value] of Object.entries(variants)) {
|
257
|
+
variantsMap.set(key, parseVariant(key, value));
|
258
|
+
}
|
259
|
+
return variantsMap;
|
260
|
+
};
|
261
|
+
/**
|
262
|
+
* Represents a variable for a content template. See
|
263
|
+
* {@link ContentTemplate.variables}.
|
264
|
+
*/
|
265
|
+
class ContentTemplateVariable {
|
266
|
+
constructor(
|
267
|
+
/**
|
268
|
+
* Name of the variable.
|
269
|
+
*/
|
270
|
+
name,
|
271
|
+
/**
|
272
|
+
* Key of the variable
|
273
|
+
*/
|
274
|
+
value) {
|
275
|
+
this.name = name;
|
276
|
+
this.value = value;
|
277
|
+
}
|
278
|
+
/**
|
279
|
+
* Copies the variable with a new value.
|
280
|
+
*
|
281
|
+
* @param value The new value for the variable.
|
282
|
+
*/
|
283
|
+
copyWithValue(value) {
|
284
|
+
return new ContentTemplateVariable(this.name, value);
|
285
|
+
}
|
286
|
+
}
|
287
|
+
/**
|
288
|
+
* A rich content template.
|
289
|
+
*
|
290
|
+
* Use {@Link Client.getContentTemplates} to request all the templates available
|
291
|
+
* for the current account.
|
292
|
+
*/
|
293
|
+
class ContentTemplate {
|
294
|
+
/**
|
295
|
+
* @internal
|
296
|
+
*/
|
297
|
+
constructor(contentTemplateResponse) {
|
298
|
+
this.sid = contentTemplateResponse.sid;
|
299
|
+
this.friendlyName = contentTemplateResponse.friendly_name;
|
300
|
+
this.variables = Object.entries(JSON.parse(contentTemplateResponse.variables)).map(([key, value]) => new ContentTemplateVariable(key, value));
|
301
|
+
this.variants = collectVariants(contentTemplateResponse.variants);
|
302
|
+
this.dateCreated = new Date(contentTemplateResponse.date_created);
|
303
|
+
this.dateUpdated = new Date(contentTemplateResponse.date_updated);
|
304
|
+
}
|
305
|
+
}
|
306
|
+
|
307
|
+
exports.ContentTemplate = ContentTemplate;
|
308
|
+
exports.ContentTemplateVariable = ContentTemplateVariable;
|
309
|
+
exports.parseVariant = parseVariant;
|
310
|
+
//# sourceMappingURL=content-template.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"content-template.js","sources":["../src/content-template.ts"],"sourcesContent":["import {\n ContentDataCallToActionResponse,\n ContentDataCardResponse,\n ContentDataListPickerResponse,\n ContentDataLocationResponse,\n ContentDataMediaResponse,\n ContentDataQuickReplyResponse,\n ContentDataTextResponse,\n ContentTemplateResponse,\n} from \"./interfaces/commands/content-templates-response\";\n\n/**\n * Shows a button that sends back a predefined text. Used in\n * {@link ContentDataQuickReply}.\n */\ntype ContentDataReply = {\n /**\n * Display value of the action. This is the message that will be sent back\n * when the user taps on the button.\n */\n readonly title: string;\n\n /**\n * Postback payload. This field is not visible to the end user.\n */\n readonly id?: string;\n};\n\n/**\n * Shows a button that redirects recipient to a predefined URL.\n */\ntype ContentDataActionUrl = {\n /**\n * The type discriminant.\n */\n readonly type: \"url\";\n\n /**\n * Display value for the action.\n */\n readonly title: string;\n\n /**\n * URL to direct to when the recipient taps the button.\n */\n readonly url: string;\n\n /**\n * Full data as a stringified JSON. This could be used for future content\n * types and fields which are not yet supported by the newest version of\n * the Conversations SDK, or for using newer types in the older versions of\n * the SDK.\n */\n readonly rawData: string;\n};\n\n/**\n * Shows a button that calls a phone number.\n */\ntype ContentDataActionPhone = {\n /**\n * The type discriminant.\n */\n readonly type: \"phone\";\n\n /**\n * Display value for the action.\n */\n readonly title: string;\n\n /**\n * Phone number to call when the recipient taps the button.\n */\n readonly phone: string;\n\n /**\n * Full data as a stringified JSON. This could be used for future content\n * types and fields which are not yet supported by the newest version of\n * the Conversations SDK, or for using newer types in the older versions of\n * the SDK.\n */\n readonly rawData: string;\n};\n\n/**\n * Shows a button that sends back a predefined text.\n */\ntype ContentDataActionReply = {\n /**\n * The type discriminant.\n */\n readonly type: \"reply\";\n\n /**\n * Display value for the action. This is the message that will be sent back\n * when the user taps on the button.\n */\n readonly title: string;\n\n /**\n * Postback payload. This field is not visible to the end user.\n */\n readonly id?: string;\n\n /**\n * Index for the action.\n */\n readonly index: number;\n\n /**\n * Full data as a stringified JSON. This could be used for future content\n * types and fields which are not yet supported by the newest version of\n * the Conversations SDK, or for using newer types in the older versions of\n * the SDK.\n */\n readonly rawData: string;\n};\n\n/**\n * Used for unknown action types which aren't present in the current version of\n * the Conversations SDK.\n */\ntype ContentDataActionOther = {\n /**\n * The type discriminant.\n */\n readonly type: \"other\";\n\n /**\n * Full data as a stringified JSON. This could be used for future content\n * types and fields which are not yet supported by the newest version of\n * the Conversations SDK, or for using newer types in the older versions of\n * the SDK.\n */\n readonly rawData: string;\n};\n\n/**\n * A union of possible actions used in {@link ContentDataCallToAction} and\n * {@link ContentDataCard}.\n */\ntype ContentDataAction =\n | ContentDataActionUrl\n | ContentDataActionPhone\n | ContentDataActionReply\n | ContentDataActionOther;\n\n/**\n * Represents an item in the {@link ContentDataListPicker}.\n */\ntype ContentDataListItem = {\n /**\n * Unique item identifier. Not visible to the recipient.\n */\n readonly id: string;\n\n /**\n * Display value of the item.\n */\n readonly item: string;\n\n /**\n * Description of the item.\n */\n readonly description?: string;\n};\n\n/**\n * Contains only the plain text-based content. Represents the twilio/text\n * content type.\n */\ntype ContentDataText = {\n /**\n * The type discriminant.\n */\n readonly type: \"text\";\n\n /**\n * The text of the message you want to send.\n */\n readonly body: string;\n\n /**\n * Full data as a stringified JSON. This could be used for future content\n * types and fields which are not yet supported by the newest version of\n * the Conversations SDK, or for using newer types in the older versions of\n * the SDK.\n */\n readonly rawData: string;\n};\n\n/**\n * Used to send file attachments, or to send long texts via MMS in the US and\n * Canada. Represents the twilio/media content type.\n */\ntype ContentDataMedia = {\n /**\n * The type discriminant.\n */\n readonly type: \"media\";\n\n /**\n * The text of the message you want to send.\n */\n readonly body?: string;\n\n /**\n * URLs of the media you want to send.\n */\n readonly media: string[];\n\n /**\n * Full data as a stringified JSON. This could be used for future content\n * types and fields which are not yet supported by the newest version of\n * the Conversations SDK, or for using newer types in the older versions of\n * the SDK.\n */\n readonly rawData: string;\n};\n\n/**\n * Contains a location pin and an optional label, which can be used to enhance\n * delivery notifications or connect recipients to physical experiences you\n * offer. Represents the twilio/location content type.\n */\ntype ContentDataLocation = {\n /**\n * The type discriminant.\n */\n readonly type: \"location\";\n\n /**\n * The longitude value of the location pin you want to send.\n */\n readonly longitude: number;\n\n /**\n * The latitude value of the location pin you want to send.\n */\n readonly latitude: number;\n\n /**\n * The label to be displayed to the end user alongside the location pin.\n */\n readonly label?: string;\n\n /**\n * Full data as a stringified JSON. This could be used for future content\n * types and fields which are not yet supported by the newest version of\n * the Conversations SDK, or for using newer types in the older versions of\n * the SDK.\n */\n readonly rawData: string;\n};\n\n/**\n * Let recipients tap, rather than type, to respond to the message. Represents\n * the twilio/quick-reply content type.\n */\ntype ContentDataQuickReply = {\n /**\n * The type discriminant.\n */\n readonly type: \"quickReply\";\n\n /**\n * The text of the message you want to send. This is included as a regular\n * text message.\n */\n readonly body: string;\n\n /**\n * Up to 3 buttons can be created for quick reply. See\n * {@link ContentDataReply}.\n */\n readonly replies: ContentDataReply[];\n\n /**\n * Full data as a stringified JSON. This could be used for future content\n * types and fields which are not yet supported by the newest version of\n * the Conversations SDK, or for using newer types in the older versions of\n * the SDK.\n */\n readonly rawData: string;\n};\n\n/**\n * Buttons that let recipients tap to trigger actions such as launching a\n * website or making a phone call. Represents the twilio/call-to-action content\n * type.\n */\ntype ContentDataCallToAction = {\n /**\n * The type discriminant.\n */\n readonly type: \"callToAction\";\n\n /**\n * The text of the message you want to send. This is included as a regular\n * text message.\n */\n readonly body: string;\n\n /**\n * Buttons that recipients can tap on to act on the message.\n */\n readonly actions: ContentDataAction[];\n\n /**\n * Full data as a stringified JSON. This could be used for future content\n * types and fields which are not yet supported by the newest version of\n * the Conversations SDK, or for using newer types in the older versions of\n * the SDK.\n */\n readonly rawData: string;\n};\n\n/**\n * Shows a menu of up to 10 options, which offers a simple way for users to make\n * a selection. Represents the twilio/list-picker content type.\n */\ntype ContentDataListPicker = {\n /**\n * The type discriminant.\n */\n readonly type: \"listPicker\";\n\n /**\n * The text of the message you want to send. This is rendered as the body of\n * the message.\n */\n readonly body: string;\n\n /**\n * Display value of the primary button.\n */\n readonly button: string;\n\n /**\n * List item objects displayed in the list. See {@link ContentDataListItem}.\n */\n readonly items: ContentDataListItem[];\n\n /**\n * Full data as a stringified JSON. This could be used for future content\n * types and fields which are not yet supported by the newest version of\n * the Conversations SDK, or for using newer types in the older versions of\n * the SDK.\n */\n readonly rawData: string;\n};\n\n/**\n * Shows a menu of up to 10 options, which offers a simple way for users to make\n * a selection. Represents the twilio/card content type.\n */\ntype ContentDataCard = {\n /**\n * The type discriminant.\n */\n readonly type: \"card\";\n\n /**\n * Title of the card.\n */\n readonly title: string;\n\n /**\n * Subtitle of the card.\n */\n readonly subtitle?: string;\n\n /**\n * URLs of the media to send with the message.\n */\n readonly media: string[];\n\n /**\n * Buttons that the recipients can tap on to act on the message.\n */\n readonly actions: ContentDataAction[];\n\n /**\n * Full data as a stringified JSON. This could be used for future content\n * types and fields which are not yet supported by the newest version of\n * the Conversations SDK, or for using newer types in the older versions of\n * the SDK.\n */\n readonly rawData: string;\n};\n\n/**\n * Used for unknown content types which aren't present in the current version of\n * the Conversations SDK.\n */\ntype ContentDataOther = {\n /**\n * The type discriminant.\n */\n readonly type: \"other\";\n\n /**\n * Full data as a stringified JSON. This could be used for future content\n * types and fields which are not yet supported by the newest version of\n * the Conversations SDK, or for using newer types in the older versions of\n * the SDK.\n */\n readonly rawData: string;\n};\n\n/**\n * A union of possible data types in rich content templates.\n */\ntype ContentData =\n | ContentDataText\n | ContentDataMedia\n | ContentDataLocation\n | ContentDataQuickReply\n | ContentDataCallToAction\n | ContentDataListPicker\n | ContentDataCard\n | ContentDataOther;\n\nconst collectActions = (\n actions: ContentDataCallToActionResponse[\"actions\"]\n): ContentDataAction[] => {\n return actions.map((action) => {\n const rawData = JSON.stringify(action);\n\n switch (action.type) {\n case \"QUICK_REPLY\":\n return {\n type: \"reply\",\n title: action.title,\n id: action.id ?? \"\",\n index: action.index ?? 0,\n rawData,\n };\n case \"PHONE_NUMBER\":\n return {\n type: \"phone\",\n title: action.title,\n phone: action.phone ?? \"\",\n rawData,\n };\n case \"URL\":\n return {\n type: \"url\",\n title: action.title,\n url: action.url ?? \"\",\n rawData,\n };\n default:\n return {\n type: \"other\",\n rawData,\n };\n }\n });\n};\n\nconst parseVariant = (type: string, data: unknown): ContentData => {\n const rawData = JSON.stringify(data);\n\n switch (type) {\n case \"twilio/text\": {\n const variant = data as ContentDataTextResponse;\n return {\n type: \"text\",\n body: variant.body,\n rawData,\n };\n }\n case \"twilio/media\": {\n const variant = data as ContentDataMediaResponse;\n return {\n type: \"media\",\n body: variant.body,\n media: variant.media,\n rawData,\n };\n }\n case \"twilio/location\": {\n const variant = data as ContentDataLocationResponse;\n return {\n type: \"location\",\n longitude: variant.longitude,\n latitude: variant.latitude,\n label: variant.label,\n rawData,\n };\n }\n case \"twilio/quick-reply\": {\n const variant = data as ContentDataQuickReplyResponse;\n return {\n type: \"quickReply\",\n body: variant.body,\n replies: variant.actions,\n rawData,\n };\n }\n case \"twilio/call-to-action\": {\n const variant = data as ContentDataCallToActionResponse;\n return {\n type: \"callToAction\",\n body: variant.body,\n actions: collectActions(variant.actions),\n rawData,\n };\n }\n case \"twilio/list-picker\": {\n const variant = data as ContentDataListPickerResponse;\n return {\n type: \"listPicker\",\n body: variant.body,\n button: variant.button,\n items: variant.items,\n rawData,\n };\n }\n case \"twilio/card\": {\n const variant = data as ContentDataCardResponse;\n return {\n type: \"card\",\n title: variant.title,\n subtitle: variant.subtitle,\n media: variant.media ?? [],\n actions: collectActions(variant.actions ?? []),\n rawData,\n };\n }\n default:\n return {\n type: \"other\",\n rawData,\n };\n }\n};\n\nconst collectVariants = (\n variants: ContentTemplateResponse[\"variants\"]\n): Map<string, ContentData> => {\n const variantsMap = new Map<string, ContentData>();\n\n for (const [key, value] of Object.entries(variants)) {\n variantsMap.set(key, parseVariant(key, value));\n }\n\n return variantsMap;\n};\n\n/**\n * Represents a variable for a content template. See\n * {@link ContentTemplate.variables}.\n */\nclass ContentTemplateVariable {\n public constructor(\n /**\n * Name of the variable.\n */\n public readonly name: string,\n\n /**\n * Key of the variable\n */\n public readonly value: string\n ) {}\n\n /**\n * Copies the variable with a new value.\n *\n * @param value The new value for the variable.\n */\n public copyWithValue(value: string) {\n return new ContentTemplateVariable(this.name, value);\n }\n}\n\n/**\n * A rich content template.\n *\n * Use {@Link Client.getContentTemplates} to request all the templates available\n * for the current account.\n */\nclass ContentTemplate {\n /**\n * The server-assigned unique identifier for the template.\n */\n public readonly sid: string;\n\n /**\n * Friendly name used to describe the content. Not visible to the recipient.\n */\n public readonly friendlyName: string;\n\n /**\n * Variables used by this template.\n */\n public readonly variables: ContentTemplateVariable[];\n\n /**\n * Variants of the content. See {@link ContentData}.\n */\n public readonly variants: Map<string, ContentData>;\n\n /**\n * Date of creation.\n */\n public readonly dateCreated: Date;\n\n /**\n * Date of the last update.\n */\n public readonly dateUpdated: Date;\n\n /**\n * @internal\n */\n public constructor(contentTemplateResponse: ContentTemplateResponse) {\n this.sid = contentTemplateResponse.sid;\n this.friendlyName = contentTemplateResponse.friendly_name;\n this.variables = Object.entries(\n JSON.parse(contentTemplateResponse.variables) as Record<string, string>\n ).map(([key, value]) => new ContentTemplateVariable(key, value));\n this.variants = collectVariants(contentTemplateResponse.variants);\n this.dateCreated = new Date(contentTemplateResponse.date_created);\n this.dateUpdated = new Date(contentTemplateResponse.date_updated);\n }\n}\n\nexport {\n ContentDataActionUrl,\n ContentDataActionPhone,\n ContentDataActionReply,\n ContentDataActionOther,\n ContentDataAction,\n ContentDataText,\n ContentDataMedia,\n ContentDataLocation,\n ContentDataReply,\n ContentDataQuickReply,\n ContentDataCallToAction,\n ContentDataListPicker,\n ContentDataListItem,\n ContentDataCard,\n ContentDataOther,\n ContentData,\n ContentTemplate,\n ContentTemplateVariable,\n parseVariant,\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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