@unboundcx/sdk 2.7.7 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/base.js +76 -43
- package/index.js +4 -1
- package/package.json +1 -1
- package/services/ai.js +16 -3
- package/services/engagementMetrics.js +153 -0
- package/services/messaging/CampaignsService.js +10 -0
- package/services/messaging/EmailAddressesService.js +89 -0
- package/services/messaging/EmailAnalyticsService.js +109 -0
- package/services/messaging/EmailDomainsService.js +252 -0
- package/services/messaging/EmailMailboxesService.js +458 -0
- package/services/messaging/EmailQueueService.js +96 -0
- package/services/messaging/EmailService.js +690 -0
- package/services/messaging/EmailSuppressionService.js +189 -0
- package/services/messaging/EmailTemplatesService.js +145 -0
- package/services/messaging/MessagingService.js +12 -0
- package/services/messaging/SmsService.js +75 -0
- package/services/messaging/SmsTemplatesService.js +124 -0
- package/services/messaging/TenDlcBrandsService.js +446 -0
- package/services/messaging/TenDlcCampaignManagementService.js +390 -0
- package/services/messaging/TenDlcCampaignsService.js +32 -0
- package/services/messaging/TollFreeCampaignsService.js +304 -0
- package/services/messaging.js +37 -2100
- package/services/objects.js +28 -38
- package/services/recordTypes.js +227 -4
- package/services/sipEndpoints.js +12 -12
- package/services/storage.js +226 -1
- package/services/video.js +59 -1
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
export class EmailSuppressionService {
|
|
2
|
+
constructor(sdk) {
|
|
3
|
+
this.sdk = sdk;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* List email suppression entries for the current account
|
|
8
|
+
* @param {Object} [params] - Query parameters
|
|
9
|
+
* @param {string} [params.type] - Filter by suppression type (bounce, complaint, etc.)
|
|
10
|
+
* @param {string} [params.emailAddress] - Filter by email address (partial match)
|
|
11
|
+
* @param {string} [params.fromAddress] - Filter by sender address
|
|
12
|
+
* @param {string} [params.carrierName] - Filter by carrier name
|
|
13
|
+
* @param {number} [params.page=1] - Page number (1-based)
|
|
14
|
+
* @param {number} [params.limit=50] - Number of items per page (max 100)
|
|
15
|
+
* @returns {Promise<Object>} Paginated suppression list
|
|
16
|
+
* @example
|
|
17
|
+
* // Get all bounce suppressions
|
|
18
|
+
* const bounces = await sdk.messaging.email.suppression.list({ type: 'bounce', page: 1, limit: 50 });
|
|
19
|
+
* // Returns: {
|
|
20
|
+
* // items: [{ id, emailAddress, type, subType, fromAddress, carrierName, createdAt, requestRemovalReason, requestRemovalBy, requestRemovalAt }],
|
|
21
|
+
* // pagination: { page, limit },
|
|
22
|
+
* // filters: { type }
|
|
23
|
+
* // }
|
|
24
|
+
*/
|
|
25
|
+
async list({
|
|
26
|
+
type,
|
|
27
|
+
emailAddress,
|
|
28
|
+
fromAddress,
|
|
29
|
+
carrierName,
|
|
30
|
+
page,
|
|
31
|
+
limit,
|
|
32
|
+
} = {}) {
|
|
33
|
+
const options = { query: {} };
|
|
34
|
+
if (type) options.query.type = type;
|
|
35
|
+
if (emailAddress) options.query.emailAddress = emailAddress;
|
|
36
|
+
if (fromAddress) options.query.fromAddress = fromAddress;
|
|
37
|
+
if (carrierName) options.query.carrierName = carrierName;
|
|
38
|
+
if (page !== undefined) options.query.page = page;
|
|
39
|
+
if (limit !== undefined) options.query.limit = limit;
|
|
40
|
+
|
|
41
|
+
const result = await this.sdk._fetch(
|
|
42
|
+
'/messaging/email/suppression',
|
|
43
|
+
'GET',
|
|
44
|
+
options,
|
|
45
|
+
);
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Delete a suppression entry with required reason (soft delete)
|
|
51
|
+
* @param {string} id - Suppression item ID (required)
|
|
52
|
+
* @param {string} reason - Reason for deletion (required, max 128 characters)
|
|
53
|
+
* @returns {Promise<Object>} Deletion confirmation with details
|
|
54
|
+
* @example
|
|
55
|
+
* // Delete a suppression entry
|
|
56
|
+
* const result = await sdk.messaging.email.suppression.delete('supp-123', 'Customer request to remove');
|
|
57
|
+
* // Returns: {
|
|
58
|
+
* // success: true,
|
|
59
|
+
* // message: 'Suppression item deleted successfully',
|
|
60
|
+
* // deletedItem: { id, emailAddress, deletedBy, deletedReason, deletedAt }
|
|
61
|
+
* // }
|
|
62
|
+
*/
|
|
63
|
+
async delete(id, reason) {
|
|
64
|
+
this.sdk.validateParams(
|
|
65
|
+
{ id, reason },
|
|
66
|
+
{
|
|
67
|
+
id: { type: 'string', required: true },
|
|
68
|
+
reason: { type: 'string', required: true },
|
|
69
|
+
},
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
if (reason.length > 128) {
|
|
73
|
+
throw new Error('Deletion reason must be 128 characters or less');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const options = {
|
|
77
|
+
body: { reason },
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const result = await this.sdk._fetch(
|
|
81
|
+
`/messaging/email/suppression/${id}`,
|
|
82
|
+
'DELETE',
|
|
83
|
+
options,
|
|
84
|
+
);
|
|
85
|
+
return result;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Check if an email address is globally suppressed (not limited by account)
|
|
90
|
+
* @param {string} emailAddress - Email address to check (required)
|
|
91
|
+
* @returns {Promise<Object>} Suppression status and removal request availability
|
|
92
|
+
* @example
|
|
93
|
+
* // Check if email is suppressed globally
|
|
94
|
+
* const status = await sdk.messaging.email.suppression.checkGlobal('user@example.com');
|
|
95
|
+
* // Returns: {
|
|
96
|
+
* // suppressed: true/false,
|
|
97
|
+
* // message: 'Status message',
|
|
98
|
+
* // canRequestRemoval: true/false (only if suppressed)
|
|
99
|
+
* // }
|
|
100
|
+
*/
|
|
101
|
+
async checkGlobal(emailAddress) {
|
|
102
|
+
this.sdk.validateParams(
|
|
103
|
+
{ emailAddress },
|
|
104
|
+
{
|
|
105
|
+
emailAddress: { type: 'string', required: true },
|
|
106
|
+
},
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
const result = await this.sdk._fetch(
|
|
110
|
+
`/messaging/email/suppression/global/${encodeURIComponent(emailAddress)}`,
|
|
111
|
+
'GET',
|
|
112
|
+
);
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Request removal of an email address from global suppression list
|
|
118
|
+
* @param {string} emailAddress - Email address to request removal for (required)
|
|
119
|
+
* @param {string} reason - Reason for removal request (required, max 128 characters)
|
|
120
|
+
* @returns {Promise<Object>} Removal request confirmation or existing request details
|
|
121
|
+
* @example
|
|
122
|
+
* // Request removal from suppression list
|
|
123
|
+
* const result = await sdk.messaging.email.suppression.requestRemoval('user@example.com', 'Customer opt-in consent obtained');
|
|
124
|
+
* // Success: {
|
|
125
|
+
* // success: true,
|
|
126
|
+
* // message: 'Removal request submitted successfully',
|
|
127
|
+
* // emailAddress, requestedBy, reason, requestedAt, recordsUpdated, records
|
|
128
|
+
* // }
|
|
129
|
+
* // Already requested: {
|
|
130
|
+
* // success: false,
|
|
131
|
+
* // message: 'A removal request has already been submitted...',
|
|
132
|
+
* // existingRequest: { requestedAt, requestedBy, reason }
|
|
133
|
+
* // }
|
|
134
|
+
*/
|
|
135
|
+
async requestRemoval(emailAddress, reason) {
|
|
136
|
+
this.sdk.validateParams(
|
|
137
|
+
{ emailAddress, reason },
|
|
138
|
+
{
|
|
139
|
+
emailAddress: { type: 'string', required: true },
|
|
140
|
+
reason: { type: 'string', required: true },
|
|
141
|
+
},
|
|
142
|
+
);
|
|
143
|
+
|
|
144
|
+
if (reason.length > 128) {
|
|
145
|
+
throw new Error('Removal reason must be 128 characters or less');
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const options = {
|
|
149
|
+
body: { reason },
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const result = await this.sdk._fetch(
|
|
153
|
+
`/messaging/email/suppression/global/${encodeURIComponent(
|
|
154
|
+
emailAddress,
|
|
155
|
+
)}/request-removal`,
|
|
156
|
+
'POST',
|
|
157
|
+
options,
|
|
158
|
+
);
|
|
159
|
+
return result;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Get bounce suppressions only (convenience method)
|
|
164
|
+
* @param {Object} [params] - Query parameters
|
|
165
|
+
* @param {number} [params.page=1] - Page number (1-based)
|
|
166
|
+
* @param {number} [params.limit=50] - Number of items per page (max 100)
|
|
167
|
+
* @returns {Promise<Object>} Paginated bounce suppressions
|
|
168
|
+
* @example
|
|
169
|
+
* // Get all bounce suppressions
|
|
170
|
+
* const bounces = await sdk.messaging.email.suppression.getBounces({ page: 1, limit: 50 });
|
|
171
|
+
*/
|
|
172
|
+
async getBounces({ page, limit } = {}) {
|
|
173
|
+
return this.list({ type: 'bounce', page, limit });
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Get complaint suppressions only (convenience method)
|
|
178
|
+
* @param {Object} [params] - Query parameters
|
|
179
|
+
* @param {number} [params.page=1] - Page number (1-based)
|
|
180
|
+
* @param {number} [params.limit=50] - Number of items per page (max 100)
|
|
181
|
+
* @returns {Promise<Object>} Paginated complaint suppressions
|
|
182
|
+
* @example
|
|
183
|
+
* // Get all complaint suppressions
|
|
184
|
+
* const complaints = await sdk.messaging.email.suppression.getComplaints({ page: 1, limit: 50 });
|
|
185
|
+
*/
|
|
186
|
+
async getComplaints({ page, limit } = {}) {
|
|
187
|
+
return this.list({ type: 'complaint', page, limit });
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
export class EmailTemplatesService {
|
|
2
|
+
constructor(sdk) {
|
|
3
|
+
this.sdk = sdk;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Create email template
|
|
8
|
+
* @param {Object} params - Template parameters
|
|
9
|
+
* @param {string} params.name - Template name (required)
|
|
10
|
+
* @param {string} params.subject - Template subject (required)
|
|
11
|
+
* @param {string} [params.html] - HTML template body
|
|
12
|
+
* @param {string} [params.text] - Plain text template body
|
|
13
|
+
* @returns {Promise<Object>} Created template details with auto-extracted variables
|
|
14
|
+
* @example
|
|
15
|
+
* // Create template with variables in the content
|
|
16
|
+
* const template = await sdk.messaging.email.templates.create({
|
|
17
|
+
* name: 'Welcome Email',
|
|
18
|
+
* subject: 'Welcome {{firstName}}!',
|
|
19
|
+
* html: '<h1>Hello {{firstName}} {{lastName}}</h1>',
|
|
20
|
+
* text: 'Hello {{firstName}} {{lastName}}'
|
|
21
|
+
* });
|
|
22
|
+
* // Returns: { id, name, variables: ['firstName', 'lastName'] }
|
|
23
|
+
*/
|
|
24
|
+
async create({ name, subject, html, text }) {
|
|
25
|
+
this.sdk.validateParams(
|
|
26
|
+
{ name, subject },
|
|
27
|
+
{
|
|
28
|
+
name: { type: 'string', required: true },
|
|
29
|
+
subject: { type: 'string', required: true },
|
|
30
|
+
html: { type: 'string', required: false },
|
|
31
|
+
text: { type: 'string', required: false },
|
|
32
|
+
},
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const templateData = { name, subject };
|
|
36
|
+
if (html) templateData.html = html;
|
|
37
|
+
if (text) templateData.text = text;
|
|
38
|
+
|
|
39
|
+
const options = {
|
|
40
|
+
body: templateData,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const result = await this.sdk._fetch(
|
|
44
|
+
'/messaging/email/template',
|
|
45
|
+
'POST',
|
|
46
|
+
options,
|
|
47
|
+
);
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Update email template
|
|
53
|
+
* @param {string} id - Template ID (required)
|
|
54
|
+
* @param {Object} params - Update parameters
|
|
55
|
+
* @param {string} [params.name] - Template name
|
|
56
|
+
* @param {string} [params.subject] - Template subject
|
|
57
|
+
* @param {string} [params.html] - HTML template body
|
|
58
|
+
* @param {string} [params.text] - Plain text template body
|
|
59
|
+
* @returns {Promise<Object>} Updated template details with auto-extracted variables
|
|
60
|
+
* @example
|
|
61
|
+
* // Update template - variables are auto-extracted from content
|
|
62
|
+
* const updated = await sdk.messaging.email.templates.update('tpl_123', {
|
|
63
|
+
* subject: 'Hi {{firstName}}, welcome to {{companyName}}!'
|
|
64
|
+
* });
|
|
65
|
+
* // Returns updated template with variables: ['firstName', 'companyName']
|
|
66
|
+
*/
|
|
67
|
+
async update(id, { name, subject, html, text }) {
|
|
68
|
+
this.sdk.validateParams(
|
|
69
|
+
{ id },
|
|
70
|
+
{
|
|
71
|
+
id: { type: 'string', required: true },
|
|
72
|
+
name: { type: 'string', required: false },
|
|
73
|
+
subject: { type: 'string', required: false },
|
|
74
|
+
html: { type: 'string', required: false },
|
|
75
|
+
text: { type: 'string', required: false },
|
|
76
|
+
},
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const updateData = {};
|
|
80
|
+
if (name) updateData.name = name;
|
|
81
|
+
if (subject) updateData.subject = subject;
|
|
82
|
+
if (html) updateData.html = html;
|
|
83
|
+
if (text) updateData.text = text;
|
|
84
|
+
|
|
85
|
+
const options = {
|
|
86
|
+
body: updateData,
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const result = await this.sdk._fetch(
|
|
90
|
+
`/messaging/email/template/${id}`,
|
|
91
|
+
'PUT',
|
|
92
|
+
options,
|
|
93
|
+
);
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Delete email template
|
|
99
|
+
* @param {string} id - Template ID (required)
|
|
100
|
+
* @returns {Promise<Object>} Deletion confirmation
|
|
101
|
+
*/
|
|
102
|
+
async delete(id) {
|
|
103
|
+
this.sdk.validateParams(
|
|
104
|
+
{ id },
|
|
105
|
+
{
|
|
106
|
+
id: { type: 'string', required: true },
|
|
107
|
+
},
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
const result = await this.sdk._fetch(
|
|
111
|
+
`/messaging/email/template/${id}`,
|
|
112
|
+
'DELETE',
|
|
113
|
+
);
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Get email template by ID
|
|
119
|
+
* @param {string} id - Template ID (required)
|
|
120
|
+
* @returns {Promise<Object>} Template details
|
|
121
|
+
*/
|
|
122
|
+
async get(id) {
|
|
123
|
+
this.sdk.validateParams(
|
|
124
|
+
{ id },
|
|
125
|
+
{
|
|
126
|
+
id: { type: 'string', required: true },
|
|
127
|
+
},
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
const result = await this.sdk._fetch(
|
|
131
|
+
`/messaging/email/template/${id}`,
|
|
132
|
+
'GET',
|
|
133
|
+
);
|
|
134
|
+
return result;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* List all email templates
|
|
139
|
+
* @returns {Promise<Array>} List of email templates
|
|
140
|
+
*/
|
|
141
|
+
async list() {
|
|
142
|
+
const result = await this.sdk._fetch('/messaging/email/template', 'GET');
|
|
143
|
+
return result;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { SmsService } from './SmsService.js';
|
|
2
|
+
import { EmailService } from './EmailService.js';
|
|
3
|
+
import { CampaignsService } from './CampaignsService.js';
|
|
4
|
+
|
|
5
|
+
export class MessagingService {
|
|
6
|
+
constructor(sdk) {
|
|
7
|
+
this.sdk = sdk;
|
|
8
|
+
this.sms = new SmsService(sdk);
|
|
9
|
+
this.email = new EmailService(sdk);
|
|
10
|
+
this.campaigns = new CampaignsService(sdk);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { SmsTemplatesService } from './SmsTemplatesService.js';
|
|
2
|
+
|
|
3
|
+
export class SmsService {
|
|
4
|
+
constructor(sdk) {
|
|
5
|
+
this.sdk = sdk;
|
|
6
|
+
this.templates = new SmsTemplatesService(sdk);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Send an SMS/MMS message
|
|
11
|
+
* @param {Object} params - Message parameters
|
|
12
|
+
* @param {string} params.to - Recipient phone number (required)
|
|
13
|
+
* @param {string} [params.from] - Sender phone number
|
|
14
|
+
* @param {string} [params.message] - Message text
|
|
15
|
+
* @param {string} [params.templateId] - Template ID to use
|
|
16
|
+
* @param {Object} [params.variables] - Template variables
|
|
17
|
+
* @param {Array<string>} [params.mediaUrls] - Media URLs for MMS
|
|
18
|
+
* @param {string} [params.webhookUrl] - Webhook URL for delivery status
|
|
19
|
+
* @returns {Promise<Object>} Message details
|
|
20
|
+
*/
|
|
21
|
+
async send({
|
|
22
|
+
from,
|
|
23
|
+
to,
|
|
24
|
+
message,
|
|
25
|
+
templateId,
|
|
26
|
+
variables,
|
|
27
|
+
mediaUrls,
|
|
28
|
+
webhookUrl,
|
|
29
|
+
}) {
|
|
30
|
+
const messageData = {};
|
|
31
|
+
if (from) messageData.from = from;
|
|
32
|
+
if (message) messageData.message = message;
|
|
33
|
+
if (templateId) messageData.templateId = templateId;
|
|
34
|
+
if (variables) messageData.variables = variables;
|
|
35
|
+
if (mediaUrls) messageData.mediaUrls = mediaUrls;
|
|
36
|
+
if (webhookUrl) messageData.webhookUrl = webhookUrl;
|
|
37
|
+
|
|
38
|
+
this.sdk.validateParams(
|
|
39
|
+
{ to, ...messageData },
|
|
40
|
+
{
|
|
41
|
+
to: { type: 'string', required: true },
|
|
42
|
+
from: { type: 'string', required: false },
|
|
43
|
+
message: { type: 'string', required: false },
|
|
44
|
+
templateId: { type: 'string', required: false },
|
|
45
|
+
variables: { type: 'object', required: false },
|
|
46
|
+
mediaUrls: { type: 'array', required: false },
|
|
47
|
+
webhookUrl: { type: 'string', required: false },
|
|
48
|
+
},
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const options = {
|
|
52
|
+
body: { to, ...messageData },
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const result = await this.sdk._fetch('/messaging/sms', 'POST', options);
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Get SMS/MMS message by ID
|
|
61
|
+
* @param {string} id - Message ID
|
|
62
|
+
* @returns {Promise<Object>} Message details
|
|
63
|
+
*/
|
|
64
|
+
async get(id) {
|
|
65
|
+
this.sdk.validateParams(
|
|
66
|
+
{ id },
|
|
67
|
+
{
|
|
68
|
+
id: { type: 'string', required: true },
|
|
69
|
+
},
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
const result = await this.sdk._fetch(`/messaging/sms/${id}`, 'GET');
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
export class SmsTemplatesService {
|
|
2
|
+
constructor(sdk) {
|
|
3
|
+
this.sdk = sdk;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Create SMS template
|
|
8
|
+
* @param {Object} params - Template parameters
|
|
9
|
+
* @param {string} params.name - Template name (required)
|
|
10
|
+
* @param {string} params.message - Template message (required)
|
|
11
|
+
* @param {Object} [params.variables] - Template variables
|
|
12
|
+
* @returns {Promise<Object>} Created template details
|
|
13
|
+
*/
|
|
14
|
+
async create({ name, message, variables }) {
|
|
15
|
+
this.sdk.validateParams(
|
|
16
|
+
{ name, message },
|
|
17
|
+
{
|
|
18
|
+
name: { type: 'string', required: true },
|
|
19
|
+
message: { type: 'string', required: true },
|
|
20
|
+
variables: { type: 'object', required: false },
|
|
21
|
+
},
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
const templateData = { name, message };
|
|
25
|
+
if (variables) templateData.variables = variables;
|
|
26
|
+
|
|
27
|
+
const options = {
|
|
28
|
+
body: templateData,
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const result = await this.sdk._fetch(
|
|
32
|
+
'/messaging/sms/templates',
|
|
33
|
+
'POST',
|
|
34
|
+
options,
|
|
35
|
+
);
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Update SMS template
|
|
41
|
+
* @param {string} id - Template ID
|
|
42
|
+
* @param {Object} params - Update parameters
|
|
43
|
+
* @param {string} [params.name] - Template name
|
|
44
|
+
* @param {string} [params.message] - Template message
|
|
45
|
+
* @param {Object} [params.variables] - Template variables
|
|
46
|
+
* @returns {Promise<Object>} Updated template details
|
|
47
|
+
*/
|
|
48
|
+
async update(id, { name, message, variables }) {
|
|
49
|
+
this.sdk.validateParams(
|
|
50
|
+
{ id },
|
|
51
|
+
{
|
|
52
|
+
id: { type: 'string', required: true },
|
|
53
|
+
name: { type: 'string', required: false },
|
|
54
|
+
message: { type: 'string', required: false },
|
|
55
|
+
variables: { type: 'object', required: false },
|
|
56
|
+
},
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
const updateData = {};
|
|
60
|
+
if (name) updateData.name = name;
|
|
61
|
+
if (message) updateData.message = message;
|
|
62
|
+
if (variables) updateData.variables = variables;
|
|
63
|
+
|
|
64
|
+
const options = {
|
|
65
|
+
body: updateData,
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const result = await this.sdk._fetch(
|
|
69
|
+
`/messaging/sms/templates/${id}`,
|
|
70
|
+
'PUT',
|
|
71
|
+
options,
|
|
72
|
+
);
|
|
73
|
+
return result;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Delete SMS template
|
|
78
|
+
* @param {string} id - Template ID
|
|
79
|
+
* @returns {Promise<Object>} Deletion result
|
|
80
|
+
*/
|
|
81
|
+
async delete(id) {
|
|
82
|
+
this.sdk.validateParams(
|
|
83
|
+
{ id },
|
|
84
|
+
{
|
|
85
|
+
id: { type: 'string', required: true },
|
|
86
|
+
},
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
const result = await this.sdk._fetch(
|
|
90
|
+
`/messaging/sms/templates/${id}`,
|
|
91
|
+
'DELETE',
|
|
92
|
+
);
|
|
93
|
+
return result;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Get SMS template by ID
|
|
98
|
+
* @param {string} id - Template ID
|
|
99
|
+
* @returns {Promise<Object>} Template details
|
|
100
|
+
*/
|
|
101
|
+
async get(id) {
|
|
102
|
+
this.sdk.validateParams(
|
|
103
|
+
{ id },
|
|
104
|
+
{
|
|
105
|
+
id: { type: 'string', required: true },
|
|
106
|
+
},
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
const result = await this.sdk._fetch(
|
|
110
|
+
`/messaging/sms/templates/${id}`,
|
|
111
|
+
'GET',
|
|
112
|
+
);
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* List all SMS templates
|
|
118
|
+
* @returns {Promise<Array>} List of templates
|
|
119
|
+
*/
|
|
120
|
+
async list() {
|
|
121
|
+
const result = await this.sdk._fetch('/messaging/sms/templates', 'GET');
|
|
122
|
+
return result;
|
|
123
|
+
}
|
|
124
|
+
}
|