@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.
@@ -0,0 +1,304 @@
1
+ export class TollFreeCampaignsService {
2
+ constructor(sdk) {
3
+ this.sdk = sdk;
4
+ }
5
+
6
+ /**
7
+ * Create toll-free campaign
8
+ * @param {Object} params - Campaign parameters
9
+ * @param {string} params.companyName - Company name (required)
10
+ * @param {string} params.phoneNumber - Phone number (required)
11
+ * @param {string} params.description - Campaign description (required)
12
+ * @param {string} params.messageFlow - Message flow description (required)
13
+ * @param {string} [params.helpMessage] - Help message
14
+ * @param {Array<string>} [params.optInKeywords] - Opt-in keywords
15
+ * @param {Array<string>} [params.optOutKeywords] - Opt-out keywords
16
+ * @param {string} [params.website] - Business website
17
+ * @returns {Promise<Object>} Created campaign details
18
+ */
19
+ async create({
20
+ companyName,
21
+ phoneNumber,
22
+ description,
23
+ messageFlow,
24
+ helpMessage,
25
+ optInKeywords,
26
+ optOutKeywords,
27
+ website,
28
+ }) {
29
+ this.sdk.validateParams(
30
+ { companyName, phoneNumber, description, messageFlow },
31
+ {
32
+ companyName: { type: 'string', required: true },
33
+ phoneNumber: { type: 'string', required: true },
34
+ description: { type: 'string', required: true },
35
+ messageFlow: { type: 'string', required: true },
36
+ helpMessage: { type: 'string', required: false },
37
+ optInKeywords: { type: 'array', required: false },
38
+ optOutKeywords: { type: 'array', required: false },
39
+ website: { type: 'string', required: false },
40
+ },
41
+ );
42
+
43
+ const campaignData = {
44
+ companyName,
45
+ phoneNumber,
46
+ description,
47
+ messageFlow,
48
+ };
49
+
50
+ if (helpMessage) campaignData.helpMessage = helpMessage;
51
+ if (optInKeywords) campaignData.optInKeywords = optInKeywords;
52
+ if (optOutKeywords) campaignData.optOutKeywords = optOutKeywords;
53
+ if (website) campaignData.website = website;
54
+
55
+ const options = {
56
+ body: campaignData,
57
+ };
58
+
59
+ const result = await this.sdk._fetch(
60
+ '/messaging/campaigns/tollfree',
61
+ 'POST',
62
+ options,
63
+ );
64
+ return result;
65
+ }
66
+
67
+ /**
68
+ * Get toll-free campaign by ID
69
+ * @param {string} campaignId - Campaign ID
70
+ * @returns {Promise<Object>} Campaign details
71
+ */
72
+ async get(campaignId) {
73
+ this.sdk.validateParams(
74
+ { campaignId },
75
+ {
76
+ campaignId: { type: 'string', required: true },
77
+ },
78
+ );
79
+
80
+ const result = await this.sdk._fetch(
81
+ `/messaging/campaigns/tollfree/${campaignId}`,
82
+ 'GET',
83
+ );
84
+ return result;
85
+ }
86
+
87
+ /**
88
+ * Update toll-free campaign
89
+ * @param {string} campaignId - Campaign ID to update
90
+ * @param {Object} params - Update parameters
91
+ * @param {string} [params.name] - Campaign name
92
+ * @param {string} [params.campaignDescription] - Campaign description
93
+ * @param {string} [params.address1] - Business address line 1
94
+ * @param {string} [params.address2] - Business address line 2
95
+ * @param {string} [params.city] - Business city
96
+ * @param {string} [params.state] - Business state
97
+ * @param {string} [params.zip] - Business zip code
98
+ * @param {string} [params.pocFirstName] - Point of contact first name
99
+ * @param {string} [params.pocLastName] - Point of contact last name
100
+ * @param {string} [params.pocPhoneNumber] - Point of contact phone
101
+ * @param {string} [params.pocEmail] - Point of contact email
102
+ * @param {string} [params.businessName] - Business name
103
+ * @param {string} [params.website] - Business website
104
+ * @param {string} [params.messageVolume] - Expected message volume
105
+ * @param {string} [params.optInWorkflow] - Opt-in workflow description
106
+ * @param {Array<string>} [params.optInWorkflowUrls] - Opt-in workflow image URLs
107
+ * @param {Array<string>} [params.phoneNumbers] - Phone numbers for campaign
108
+ * @param {string} [params.productionMessageExample] - Production message example
109
+ * @param {string} [params.useCase] - Use case category
110
+ * @param {string} [params.useCaseDescription] - Use case description
111
+ * @param {string} [params.webhookUrl] - Webhook URL
112
+ * @returns {Promise<Object>} Updated campaign information
113
+ */
114
+ async update(
115
+ campaignId,
116
+ {
117
+ name,
118
+ campaignDescription,
119
+ address1,
120
+ address2,
121
+ city,
122
+ state,
123
+ zip,
124
+ pocFirstName,
125
+ pocLastName,
126
+ pocPhoneNumber,
127
+ pocEmail,
128
+ businessName,
129
+ website,
130
+ messageVolume,
131
+ optInWorkflow,
132
+ optInWorkflowUrls,
133
+ phoneNumbers,
134
+ productionMessageExample,
135
+ useCase,
136
+ useCaseDescription,
137
+ webhookUrl,
138
+ } = {},
139
+ ) {
140
+ this.sdk.validateParams(
141
+ {
142
+ campaignId,
143
+ name,
144
+ campaignDescription,
145
+ address1,
146
+ address2,
147
+ city,
148
+ state,
149
+ zip,
150
+ pocFirstName,
151
+ pocLastName,
152
+ pocPhoneNumber,
153
+ pocEmail,
154
+ businessName,
155
+ website,
156
+ messageVolume,
157
+ optInWorkflow,
158
+ optInWorkflowUrls,
159
+ phoneNumbers,
160
+ productionMessageExample,
161
+ useCase,
162
+ useCaseDescription,
163
+ webhookUrl,
164
+ },
165
+ {
166
+ campaignId: { type: 'string', required: true },
167
+ name: { type: 'string', required: false },
168
+ campaignDescription: { type: 'string', required: false },
169
+ address1: { type: 'string', required: false },
170
+ address2: { type: 'string', required: false },
171
+ city: { type: 'string', required: false },
172
+ state: { type: 'string', required: false },
173
+ zip: { type: 'string', required: false },
174
+ pocFirstName: { type: 'string', required: false },
175
+ pocLastName: { type: 'string', required: false },
176
+ pocPhoneNumber: { type: 'string', required: false },
177
+ pocEmail: { type: 'string', required: false },
178
+ businessName: { type: 'string', required: false },
179
+ website: { type: 'string', required: false },
180
+ messageVolume: { type: 'string', required: false },
181
+ optInWorkflow: { type: 'string', required: false },
182
+ optInWorkflowUrls: { type: 'array', required: false },
183
+ phoneNumbers: { type: 'array', required: false },
184
+ productionMessageExample: { type: 'string', required: false },
185
+ useCase: { type: 'string', required: false },
186
+ useCaseDescription: { type: 'string', required: false },
187
+ webhookUrl: { type: 'string', required: false },
188
+ },
189
+ );
190
+
191
+ const updateData = {};
192
+ if (name !== undefined) updateData.name = name;
193
+ if (campaignDescription !== undefined)
194
+ updateData.campaignDescription = campaignDescription;
195
+ if (address1 !== undefined) updateData.address1 = address1;
196
+ if (address2 !== undefined) updateData.address2 = address2;
197
+ if (city !== undefined) updateData.city = city;
198
+ if (state !== undefined) updateData.state = state;
199
+ if (zip !== undefined) updateData.zip = zip;
200
+ if (pocFirstName !== undefined) updateData.pocFirstName = pocFirstName;
201
+ if (pocLastName !== undefined) updateData.pocLastName = pocLastName;
202
+ if (pocPhoneNumber !== undefined)
203
+ updateData.pocPhoneNumber = pocPhoneNumber;
204
+ if (pocEmail !== undefined) updateData.pocEmail = pocEmail;
205
+ if (businessName !== undefined) updateData.businessName = businessName;
206
+ if (website !== undefined) updateData.website = website;
207
+ if (messageVolume !== undefined) updateData.messageVolume = messageVolume;
208
+ if (optInWorkflow !== undefined) updateData.optInWorkflow = optInWorkflow;
209
+ if (optInWorkflowUrls !== undefined)
210
+ updateData.optInWorkflowUrls = optInWorkflowUrls;
211
+ if (phoneNumbers !== undefined) updateData.phoneNumbers = phoneNumbers;
212
+ if (productionMessageExample !== undefined)
213
+ updateData.productionMessageExample = productionMessageExample;
214
+ if (useCase !== undefined) updateData.useCase = useCase;
215
+ if (useCaseDescription !== undefined)
216
+ updateData.useCaseDescription = useCaseDescription;
217
+ if (webhookUrl !== undefined) updateData.webhookUrl = webhookUrl;
218
+
219
+ const options = {
220
+ body: updateData,
221
+ };
222
+
223
+ const result = await this.sdk._fetch(
224
+ `/messaging/campaigns/tollfree/${campaignId}`,
225
+ 'PUT',
226
+ options,
227
+ );
228
+ return result;
229
+ }
230
+
231
+ async delete(campaignId) {
232
+ this.sdk.validateParams(
233
+ { campaignId },
234
+ {
235
+ campaignId: { type: 'string', required: true },
236
+ },
237
+ );
238
+
239
+ const result = await this.sdk._fetch(
240
+ `/messaging/campaigns/tollfree/${campaignId}`,
241
+ 'DELETE',
242
+ );
243
+ return result;
244
+ }
245
+
246
+ /**
247
+ * List all toll-free campaigns with optional filtering
248
+ * @param {Object} [params] - Filter parameters
249
+ * @param {number} [params.page=1] - Page number
250
+ * @param {number} [params.limit=50] - Items per page
251
+ * @param {string} [params.name] - Filter by campaign name
252
+ * @param {string} [params.status] - Filter by status
253
+ * @param {string} [params.operatorType='contains'] - Filter operator: contains, equals, startsWith, endsWith
254
+ * @returns {Promise<Array>} List of campaigns
255
+ */
256
+ async list({ page, limit, name, status, operatorType } = {}) {
257
+ const queryParams = new URLSearchParams();
258
+
259
+ if (page !== undefined) queryParams.append('page', page);
260
+ if (limit !== undefined) queryParams.append('limit', limit);
261
+ if (name) queryParams.append('name', name);
262
+ if (status) queryParams.append('status', status);
263
+ if (operatorType) queryParams.append('operatorType', operatorType);
264
+
265
+ const url = queryParams.toString()
266
+ ? `/messaging/campaigns/tollfree?${queryParams.toString()}`
267
+ : '/messaging/campaigns/tollfree';
268
+
269
+ const result = await this.sdk._fetch(url, 'GET');
270
+ return result;
271
+ }
272
+
273
+ async refreshStatus(campaignId) {
274
+ this.sdk.validateParams(
275
+ { campaignId },
276
+ {
277
+ campaignId: { type: 'string', required: true },
278
+ },
279
+ );
280
+
281
+ const result = await this.sdk._fetch(
282
+ `/messaging/campaigns/tollfree/refresh/${campaignId}`,
283
+ 'GET',
284
+ );
285
+ return result;
286
+ }
287
+
288
+ async getPhoneNumberCampaignStatus(phoneNumber) {
289
+ this.sdk.validateParams(
290
+ { phoneNumber },
291
+ {
292
+ phoneNumber: { type: 'string', required: true },
293
+ },
294
+ );
295
+
296
+ const result = await this.sdk._fetch(
297
+ `/messaging/campaigns/tollfree/phoneNumber/${encodeURIComponent(
298
+ phoneNumber,
299
+ )}/campaignStatus`,
300
+ 'GET',
301
+ );
302
+ return result;
303
+ }
304
+ }