@unboundcx/sdk 4.13.30 → 4.13.32

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/index.js CHANGED
@@ -22,6 +22,7 @@ import { PortalsService } from './services/portals.js';
22
22
  import { DealRegistrationsService } from './services/dealRegistrations.js';
23
23
  import { SipEndpointsService } from './services/sipEndpoints.js';
24
24
  import { WebchatService } from './services/webchat.js';
25
+ import { MessageTemplatesService } from './services/messageTemplates.js';
25
26
  import { ExternalOAuthService } from './services/externalOAuth.js';
26
27
  import { GoogleCalendarService } from './services/googleCalendar.js';
27
28
  import { DriveService } from './services/drive.js';
@@ -109,6 +110,7 @@ class UnboundSDK extends BaseSDK {
109
110
  this.dealRegistrations = new DealRegistrationsService(this);
110
111
  this.sipEndpoints = new SipEndpointsService(this);
111
112
  this.webchat = new WebchatService(this);
113
+ this.messageTemplates = new MessageTemplatesService(this);
112
114
  this.externalOAuth = new ExternalOAuthService(this);
113
115
  this.googleCalendar = new GoogleCalendarService(this);
114
116
  this.drive = new DriveService(this);
@@ -303,6 +305,7 @@ export { PortalsService } from './services/portals.js';
303
305
  export { DealRegistrationsService } from './services/dealRegistrations.js';
304
306
  export { SipEndpointsService } from './services/sipEndpoints.js';
305
307
  export { WebchatService, WebchatWidgetsService } from './services/webchat.js';
308
+ export { MessageTemplatesService } from './services/messageTemplates.js';
306
309
  export { WebchatVisitorService } from './services/webchat/VisitorService.js';
307
310
  export { ExternalOAuthService } from './services/externalOAuth.js';
308
311
  export { GoogleCalendarService } from './services/googleCalendar.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@unboundcx/sdk",
3
- "version": "4.13.30",
3
+ "version": "4.13.32",
4
4
  "description": "Official JavaScript SDK for the Unbound API - A comprehensive toolkit for integrating with Unbound's communication, AI, and data management services",
5
5
  "main": "index.js",
6
6
  "type": "module",
@@ -0,0 +1,245 @@
1
+ import { internalRequest } from '../base.js';
2
+
3
+ /**
4
+ * Account-level stored message template groups. Distinct from SMS
5
+ * `/messaging/templates/` (messagesSmsMmsTemplates) and email campaign
6
+ * templates. Widget enablement is `sdk.webchat.widgets.update(widgetId,
7
+ * { slashConfig })` — two-arg; no extra widget method here.
8
+ */
9
+ export class MessageTemplateGroupsService {
10
+ constructor(sdk) {
11
+ this.sdk = sdk;
12
+ }
13
+
14
+ /**
15
+ * List stored message template groups (ACL-filtered).
16
+ * @returns {Promise<{results: Object[]}>}
17
+ */
18
+ async list() {
19
+ return internalRequest(this.sdk, '/messageTemplates/groups', 'GET');
20
+ }
21
+
22
+ /**
23
+ * Get a stored message template group by id.
24
+ * @param {string} id
25
+ * @returns {Promise<Object>}
26
+ */
27
+ async get(id) {
28
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
29
+ return internalRequest(this.sdk, `/messageTemplates/groups/${id}`, 'GET');
30
+ }
31
+
32
+ /**
33
+ * Create a stored message template group.
34
+ * @param {Object} options
35
+ * @param {string} options.name
36
+ * @param {'active'|'archived'} [options.status]
37
+ * @param {number} [options.sortOrder]
38
+ * @param {string|null} [options.recordTypeId]
39
+ * @returns {Promise<Object>}
40
+ */
41
+ async create(options) {
42
+ this.sdk.validateParams(
43
+ { name: options?.name },
44
+ { name: { type: 'string', required: true } },
45
+ );
46
+
47
+ return internalRequest(this.sdk, '/messageTemplates/groups', 'POST', {
48
+ body: { ...options },
49
+ });
50
+ }
51
+
52
+ /**
53
+ * Update a stored message template group. Changing recordTypeId
54
+ * cascades to child templates on the API.
55
+ * @param {string} id
56
+ * @param {Object} options
57
+ * @returns {Promise<Object>}
58
+ */
59
+ async update(id, options) {
60
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
61
+
62
+ return internalRequest(this.sdk, `/messageTemplates/groups/${id}`, 'PUT', {
63
+ body: { ...options },
64
+ });
65
+ }
66
+
67
+ /**
68
+ * Soft-delete a group and cascade-soft-delete its templates.
69
+ * @param {string} id
70
+ * @returns {Promise<{id: string, deleted: boolean}>}
71
+ */
72
+ async delete(id) {
73
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
74
+ return internalRequest(
75
+ this.sdk,
76
+ `/messageTemplates/groups/${id}`,
77
+ 'DELETE',
78
+ );
79
+ }
80
+ }
81
+
82
+ /**
83
+ * Stored message templates (composer slash replies). Bodies are included
84
+ * on CRUD; the slash catalog omits them — use expand() to interpolate.
85
+ */
86
+ export class MessageTemplatesCrudService {
87
+ constructor(sdk) {
88
+ this.sdk = sdk;
89
+ }
90
+
91
+ /**
92
+ * List stored message templates (ACL-filtered).
93
+ * @param {Object} [options]
94
+ * @param {string} [options.groupId]
95
+ * @returns {Promise<{results: Object[]}>}
96
+ */
97
+ async list(options = {}) {
98
+ const { groupId } = options;
99
+ // Omit unset groupId — URLSearchParams would send "undefined" and
100
+ // the API would 404 looking up that string as a group id.
101
+ const params = {};
102
+ if (groupId !== undefined && groupId !== null && groupId !== '') {
103
+ params.query = { groupId };
104
+ }
105
+ return internalRequest(this.sdk, '/messageTemplates/templates', 'GET', params);
106
+ }
107
+
108
+ /**
109
+ * Get a stored message template by id (includes body).
110
+ * @param {string} id
111
+ * @returns {Promise<Object>}
112
+ */
113
+ async get(id) {
114
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
115
+ return internalRequest(
116
+ this.sdk,
117
+ `/messageTemplates/templates/${id}`,
118
+ 'GET',
119
+ );
120
+ }
121
+
122
+ /**
123
+ * Create a stored message template. slug must be unique among
124
+ * non-deleted templates account-wide.
125
+ * @param {Object} options
126
+ * @param {string} options.groupId
127
+ * @param {string} options.name
128
+ * @param {string} options.slug
129
+ * @param {string} options.body
130
+ * @param {'draft'|'active'} [options.status]
131
+ * @param {number} [options.sortOrder]
132
+ * @returns {Promise<Object>}
133
+ */
134
+ async create(options) {
135
+ this.sdk.validateParams(
136
+ {
137
+ groupId: options?.groupId,
138
+ name: options?.name,
139
+ slug: options?.slug,
140
+ body: options?.body,
141
+ },
142
+ {
143
+ groupId: { type: 'string', required: true },
144
+ name: { type: 'string', required: true },
145
+ slug: { type: 'string', required: true },
146
+ body: { type: 'string', required: true },
147
+ },
148
+ );
149
+
150
+ return internalRequest(this.sdk, '/messageTemplates/templates', 'POST', {
151
+ body: { ...options },
152
+ });
153
+ }
154
+
155
+ /**
156
+ * Update a stored message template.
157
+ * @param {string} id
158
+ * @param {Object} options
159
+ * @returns {Promise<Object>}
160
+ */
161
+ async update(id, options) {
162
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
163
+
164
+ return internalRequest(
165
+ this.sdk,
166
+ `/messageTemplates/templates/${id}`,
167
+ 'PUT',
168
+ { body: { ...options } },
169
+ );
170
+ }
171
+
172
+ /**
173
+ * Soft-delete a stored message template.
174
+ * @param {string} id
175
+ * @returns {Promise<{id: string, deleted: boolean}>}
176
+ */
177
+ async delete(id) {
178
+ this.sdk.validateParams({ id }, { id: { type: 'string', required: true } });
179
+ return internalRequest(
180
+ this.sdk,
181
+ `/messageTemplates/templates/${id}`,
182
+ 'DELETE',
183
+ );
184
+ }
185
+ }
186
+
187
+ export class MessageTemplatesService {
188
+ constructor(sdk) {
189
+ this.sdk = sdk;
190
+ this.groups = new MessageTemplateGroupsService(sdk);
191
+ this.templates = new MessageTemplatesCrudService(sdk);
192
+ }
193
+
194
+ /**
195
+ * Agent slash palette for a surface. Catalog rows omit body.
196
+ * Webchat requires engagementSessionId and widget match.
197
+ * @param {Object} options
198
+ * @param {'webchat'|'sms'|'email'|'whatsapp'} options.channel
199
+ * @param {string} options.configId
200
+ * @param {string} options.engagementSessionId
201
+ * @returns {Promise<{commands: Object[], templates: Object[]}>}
202
+ */
203
+ async slashCatalog({ channel, configId, engagementSessionId }) {
204
+ this.sdk.validateParams(
205
+ { channel, configId, engagementSessionId },
206
+ {
207
+ channel: { type: 'string', required: true },
208
+ configId: { type: 'string', required: true },
209
+ engagementSessionId: { type: 'string', required: true },
210
+ },
211
+ );
212
+
213
+ return internalRequest(this.sdk, '/messageTemplates/slash-catalog', 'POST', {
214
+ body: { channel, configId, engagementSessionId },
215
+ });
216
+ }
217
+
218
+ /**
219
+ * Interpolate a catalog-visible template for a surface/session.
220
+ * @param {Object} options
221
+ * @param {'webchat'|'sms'|'email'|'whatsapp'} options.channel
222
+ * @param {string} options.configId
223
+ * @param {string} options.templateId
224
+ * @param {string} options.engagementSessionId
225
+ * @returns {Promise<{body: string}>}
226
+ */
227
+ async expand({ channel, configId, templateId, engagementSessionId }) {
228
+ this.sdk.validateParams(
229
+ { channel, configId, templateId, engagementSessionId },
230
+ {
231
+ channel: { type: 'string', required: true },
232
+ configId: { type: 'string', required: true },
233
+ templateId: { type: 'string', required: true },
234
+ engagementSessionId: { type: 'string', required: true },
235
+ },
236
+ );
237
+
238
+ return internalRequest(
239
+ this.sdk,
240
+ `/messageTemplates/templates/${templateId}/expand`,
241
+ 'POST',
242
+ { body: { channel, configId, engagementSessionId } },
243
+ );
244
+ }
245
+ }
@@ -37,7 +37,14 @@ class WebchatVisitorSessionService {
37
37
  * @param {string} [params.pageUrl]
38
38
  * @returns {Promise<{engagementSessionId:string, token:string, resumeToken:string, status:'created'}>}
39
39
  */
40
- async create({ widgetId, embedGrant, visitorData, pageUrl } = {}) {
40
+ async create({
41
+ widgetId,
42
+ embedGrant,
43
+ visitorData,
44
+ pageUrl,
45
+ trackingId,
46
+ initialMessage,
47
+ } = {}) {
41
48
  this.sdk.validateParams(
42
49
  { widgetId, embedGrant },
43
50
  {
@@ -49,7 +56,40 @@ class WebchatVisitorSessionService {
49
56
  this.sdk,
50
57
  `/webchat/${widgetId}/session`,
51
58
  'POST',
52
- { body: { embedGrant, visitorData, pageUrl } },
59
+ {
60
+ body: {
61
+ embedGrant,
62
+ visitorData,
63
+ pageUrl,
64
+ trackingId,
65
+ initialMessage,
66
+ },
67
+ },
68
+ true,
69
+ );
70
+ }
71
+
72
+ /**
73
+ * Prefill the pre-chat form from a marketing `_tid` cookie.
74
+ * @param {Object} params
75
+ * @param {string} params.widgetId
76
+ * @param {string} params.embedGrant
77
+ * @param {string} [params.trackingId]
78
+ * @returns {Promise<{values: Object}>}
79
+ */
80
+ async profile({ widgetId, embedGrant, trackingId } = {}) {
81
+ this.sdk.validateParams(
82
+ { widgetId, embedGrant },
83
+ {
84
+ widgetId: { type: 'string', required: true },
85
+ embedGrant: { type: 'string', required: true },
86
+ },
87
+ );
88
+ return internalRequest(
89
+ this.sdk,
90
+ `/webchat/${widgetId}/visitor-profile`,
91
+ 'POST',
92
+ { body: { embedGrant, trackingId } },
53
93
  true,
54
94
  );
55
95
  }