@signalhouse-sms/sdk 1.8.0 → 1.10.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,466 @@
1
+ /** @typedef {import('../SignalHouseSDK.js').RequestOptions} RequestOptions */
2
+ /**
3
+ * @template T
4
+ * @typedef {import('../SignalHouseSDK.js').SdkResponse<T>} SdkResponse
5
+ */
6
+
7
+ /**
8
+ * @typedef {Object} RcsAgentProfile
9
+ * @property {string} [name] - Agent name shown on the handset (max 40)
10
+ * @property {string} [description] - Agent description (max 100)
11
+ * @property {string} [color] - Brand color, hex (default #6868ab)
12
+ * @property {string} [logoUrl] - HTTPS URL of a 224 × 224 px logo (use uploadAsset to host one)
13
+ * @property {string} [heroUrl] - HTTPS URL of a 1440 × 448 px hero image
14
+ * @property {string} [phone] - Contact phone, E.164 (e.g. +18005550142)
15
+ * @property {string} [website] - HTTPS website
16
+ * @property {string} [email] - Contact email
17
+ * @property {string} [phoneLabel] - Caption on the Call action (max 40; submit defaults it to "Call")
18
+ * @property {string} [websiteLabel] - Caption on the Website action (max 40; submit defaults it to "Website")
19
+ * @property {string} [emailLabel] - Caption on the Email action (max 40; submit defaults it to "Email")
20
+ * @property {string} [privacyPolicyUrl] - HTTPS privacy policy URL
21
+ * @property {string} [termsUrl] - HTTPS terms of service URL
22
+ */
23
+
24
+ /**
25
+ * The agent's launch text. Every field is required before submit, the opt-in URL and the launch video included.
26
+ * @typedef {Object} RcsAgentConsent
27
+ * @property {string} [optInDetails] - How recipients opt in (filled from the campaign's messageFlow when blank)
28
+ * @property {string} [optInUrl] - HTTPS page that shows the opt-in
29
+ * @property {string} [optInResponse] - The opt-in confirmation (filled from the campaign's optinMessage)
30
+ * @property {string} [optOutDetails] - How recipients opt out
31
+ * @property {string} [optOutResponse] - The opt-out confirmation (filled from the campaign's optoutMessage)
32
+ * @property {string} [helpResponse] - The HELP reply (filled from the campaign's helpMessage)
33
+ * @property {string} [campaignDescription] - What the agent sends (filled from the campaign's description)
34
+ * @property {string[]} [messageExamples] - 1-6 example messages (filled from the campaign's samples)
35
+ * @property {("UP_TO_10K"|"10K_100K"|"100K_500K"|"500K_1M"|"1M_PLUS")} [estimatedMonthlyVolume] - Expected monthly volume
36
+ * @property {string} [launchVideoUrl] - HTTPS video of the opt-in flow
37
+ */
38
+
39
+ /**
40
+ * The individual at the brand the carrier partner's reviewers may contact about the launch. Every field is required
41
+ * before the launch request; a shared mailbox (support@, info@) is refused.
42
+ * @typedef {Object} RcsAgentContact
43
+ * @property {string} [firstName] - First name (max 100)
44
+ * @property {string} [lastName] - Last name (max 100)
45
+ * @property {string} [role] - Role at the brand (3-75)
46
+ * @property {string} [email] - An individual's business email
47
+ * @property {string} [mobile] - Mobile number, E.164
48
+ */
49
+
50
+ /**
51
+ * One recipient of an RCS send.
52
+ * @typedef {Object} RcsRecipient
53
+ * @property {string} phoneNumber - The number, 10-15 digits, with or without the +
54
+ * @property {Object<string, string>} [variables] - Template variable values for this recipient
55
+ * @property {string} [clientMessageId] - Your reference for this message (max 128)
56
+ * @property {Object<string, string>} [metadata] - Your key-value data (up to 20 keys, values up to 500 characters)
57
+ */
58
+
59
+ /**
60
+ * What an RCS send does when RCS cannot reach a recipient.
61
+ * @typedef {Object} RcsMessageFallback
62
+ * @property {("auto"|"rcs_only"|"sms_only")} [mode] - The fallback mode
63
+ * @property {("auto"|"sms"|"mms")} [channel] - The fallback channel
64
+ * @property {string} [from] - The sender: a Ready number on the agent's linked Active campaign
65
+ * @property {{ text: string, mediaUrls?: string[] }} [content] - The fallback text; omitted, the template's fallback, else a generated one, is used
66
+ * @property {number} [validitySeconds] - How long the fallback message stays valid, in seconds
67
+ */
68
+
69
+ /**
70
+ * Build the multipart form for an agent image upload.
71
+ * @param {Object} params - Form fields
72
+ * @param {("logo"|"hero")} params.kind - Which image
73
+ * @param {Blob|File} params.file - The PNG or JPEG bytes
74
+ * @param {string} [params.fileName] - Optional file name
75
+ * @returns {FormData} - The form with kind and file fields
76
+ */
77
+ export function agentAssetForm({ kind, file, fileName }) {
78
+ const formData = new FormData();
79
+ formData.append("kind", kind);
80
+ if (fileName) formData.append("file", file, fileName);
81
+ else formData.append("file", file);
82
+ return formData;
83
+ }
84
+
85
+ /**
86
+ * RCS agents under /rcs/agent. An agent links one brand and one campaign, of any registration type: the campaign's numbers are the
87
+ * SMS fallback, and the brand and campaign supply the company identity and consent text for the carrier launch.
88
+ * One brand or campaign can serve many agents. An agent is a registration (type RCS_AGENT, id RCSA…), so the
89
+ * registrations methods read and edit the same record. 404 while the environment's RCS switch is off; 400 while the
90
+ * group's rcsEnabled flag is off.
91
+ */
92
+ export class RcsAgents {
93
+ constructor(client, multipartClient) {
94
+ this.client = client;
95
+ this.multipartClient = multipartClient;
96
+ }
97
+
98
+ /**
99
+ * Create an agent draft on a brand, optionally with its campaign. The agent's subgroup is the brand's.
100
+ * Blank consent fields fill from the linked campaign. Pass options.idempotencyKey to make a retry safe.
101
+ * @async
102
+ * @roles api, admin, developer, billing, user
103
+ * @param {Object} params - The agent
104
+ * @param {string} params.brandId - The brand: carrier brand ID, provisional UUID or _id
105
+ * @param {string|null} [params.campaignId] - A campaign of that brand: campaign ID or _id; required before submit
106
+ * @param {RcsAgentProfile} [params.agent] - The agent profile
107
+ * @param {RcsAgentConsent} [params.consent] - The launch text; required in full before the launch request
108
+ * @param {RcsAgentContact} [params.contact] - The launch contact; required in full before the launch request
109
+ * @param {("OTP"|"TRANSACTIONAL"|"PROMOTIONAL"|"MULTI_USE")} [params.useCase] - The agent's use case; required before submit
110
+ * @param {("NON_CONVERSATIONAL"|"CONVERSATIONAL")} [params.billingCategory] - Default NON_CONVERSATIONAL; submit refuses CONVERSATIONAL
111
+ * @param {{ mode?: string, channel?: string, from?: string }|null} [params.defaultFallback] - Fallback mode (auto, rcs_only, sms_only, none), channel (auto, sms, mms) and from, a number on the linked campaign
112
+ * @param {string[]} [params.excludedCarriers] - [] or ["T_MOBILE"] (the carrier partner's carrier name)
113
+ * @param {string[]} [params.testers] - Tester numbers (up to 200), invited once the agent exists at the carrier
114
+ * @param {RequestOptions} [params.options] - Additional options for the request
115
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to the agent (status DRAFT)
116
+ */
117
+ async create({ brandId, campaignId, agent, consent, contact, useCase, billingCategory, defaultFallback, excludedCarriers, testers, options = {} }) {
118
+ this.client._require({ brandId });
119
+ return this.client("/rcs/agent", {
120
+ method: "POST",
121
+ body: { brandId, campaignId, agent, consent, contact, useCase, billingCategory, defaultFallback, excludedCarriers, testers },
122
+ ...options,
123
+ });
124
+ }
125
+
126
+ /**
127
+ * List agents, newest first
128
+ * @async
129
+ * @roles api, admin, developer, billing, user
130
+ * @param {Object} [params] - Filters
131
+ * @param {string} [params.groupId] - Filter by group ID
132
+ * @param {string} [params.subgroupId] - Filter by subgroup ID
133
+ * @param {string|string[]} [params.status] - DRAFT, PENDING_REVIEW, REJECTED, AGENT_CREATING or ARCHIVED, one or a list
134
+ * @param {string} [params.brandId] - Agents linked to this brand (carrier brand ID, provisional UUID or _id)
135
+ * @param {string} [params.campaignId] - Agents linked to this campaign (campaign ID or _id)
136
+ * @param {number} [params.page] - Page number (default 1)
137
+ * @param {number} [params.limit] - Agents per page (default 25, max 100)
138
+ * @param {RequestOptions} [params.options] - Additional options for the request
139
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to { data: [agents], total, page, limit }
140
+ */
141
+ async list({ groupId, subgroupId, status, brandId, campaignId, page, limit, options = {} } = {}) {
142
+ const queryString = this.client._getQueryString({ groupId, subgroupId, status, brandId, campaignId, page, limit });
143
+ return this.client(`/rcs/agent${queryString}`, { method: "GET", ...options });
144
+ }
145
+
146
+ /**
147
+ * Get one agent with the live state of its brand and campaign links
148
+ * @async
149
+ * @roles api, admin, developer, billing, user
150
+ * @param {Object} params - The lookup
151
+ * @param {string} params.agentId - The agent ID (e.g. RCSA7K2M1QZ8RP)
152
+ * @param {RequestOptions} [params.options] - Additional options for the request
153
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to the agent
154
+ */
155
+ async get({ agentId, options = {} }) {
156
+ this.client._require({ agentId });
157
+ return this.client(`/rcs/agent/${encodeURIComponent(agentId)}`, { method: "GET", ...options });
158
+ }
159
+
160
+ /**
161
+ * Edit an agent while it may change: a draft, a Signal House rejection, a request for changes, or an agent in
162
+ * testing (the change is pushed to the carrier partner). `agent`, `consent` and `contact` merge field by field;
163
+ * every other key replaces; campaignId: null unlinks the campaign. 409 in any other status; brandId is locked once
164
+ * the agent exists at the partner and billingCategory once a launch was requested.
165
+ * @async
166
+ * @roles api, admin, developer, billing, user
167
+ * @param {Object} params - The edit
168
+ * @param {string} params.agentId - The agent ID
169
+ * @param {string} [params.brandId] - Relink to another brand of the same subgroup
170
+ * @param {string|null} [params.campaignId] - Link, relink or (null) unlink the campaign
171
+ * @param {RcsAgentProfile} [params.agent] - Profile fields to change
172
+ * @param {RcsAgentConsent} [params.consent] - Consent fields to change
173
+ * @param {RcsAgentContact} [params.contact] - Contact fields to change
174
+ * @param {string|null} [params.useCase] - The use case
175
+ * @param {string} [params.billingCategory] - The billing category
176
+ * @param {Object|null} [params.defaultFallback] - The fallback
177
+ * @param {string[]} [params.excludedCarriers] - [] or ["T_MOBILE"] (the carrier partner's carrier name)
178
+ * @param {string[]} [params.testers] - Tester numbers
179
+ * @param {RequestOptions} [params.options] - Additional options for the request
180
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to the agent
181
+ */
182
+ async update({ agentId, brandId, campaignId, agent, consent, contact, useCase, billingCategory, defaultFallback, excludedCarriers, testers, options = {} }) {
183
+ this.client._require({ agentId });
184
+ return this.client(`/rcs/agent/${encodeURIComponent(agentId)}`, {
185
+ method: "PUT",
186
+ body: { brandId, campaignId, agent, consent, contact, useCase, billingCategory, defaultFallback, excludedCarriers, testers },
187
+ ...options,
188
+ });
189
+ }
190
+
191
+ /**
192
+ * Check an agent against the next gate on its path without writing: before it exists at the carrier partner, what
193
+ * creating it needs (the full profile, useCase, NON_CONVERSATIONAL billing); after that, what the launch request needs
194
+ * (a VERIFIED brand, the campaign, the full consent with the video, the contact)
195
+ * @async
196
+ * @roles api, admin, developer, billing, user
197
+ * @param {Object} params - The lookup
198
+ * @param {string} params.agentId - The agent ID
199
+ * @param {RequestOptions} [params.options] - Additional options for the request
200
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to { valid, errors: [{ field, reason }], warnings: [{ field, reason }] }
201
+ */
202
+ async validate({ agentId, options = {} }) {
203
+ this.client._require({ agentId });
204
+ return this.client(`/rcs/agent/${encodeURIComponent(agentId)}/validate`, { method: "POST", ...options });
205
+ }
206
+
207
+ /**
208
+ * Submit a draft: create the agent at the carrier partner, with no review first. It needs the full profile, a
209
+ * useCase and NON_CONVERSATIONAL billing; otherwise a 400 whose details carry { code: "REGISTRATION_INCOMPLETE",
210
+ * errors, warnings }. The agent moves to AGENT_CREATING, then IN_TESTING once the partner reports it ready.
211
+ * @async
212
+ * @roles api, admin, developer, billing, user
213
+ * @param {Object} params - The submission
214
+ * @param {string} params.agentId - The agent ID
215
+ * @param {RequestOptions} [params.options] - Additional options for the request
216
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to the agent (status AGENT_CREATING)
217
+ */
218
+ async submit({ agentId, options = {} }) {
219
+ this.client._require({ agentId });
220
+ return this.client(`/rcs/agent/${encodeURIComponent(agentId)}/submit`, { method: "POST", ...options });
221
+ }
222
+
223
+ /**
224
+ * Request the agent's launch: the launch requirements are checked and the agent goes to Signal House review (status
225
+ * PENDING_REVIEW), whose approval files the launch with the carrier partner. Allowed from IN_TESTING, REJECTED and
226
+ * CARRIER_REJECTED (409 otherwise); a failed requirement is a 400 whose details carry { code:
227
+ * "REGISTRATION_INCOMPLETE", errors, warnings }. Sends POST /registration/:agentId/launch: the agent is a registration.
228
+ * The request charges the agent's launch fees: a wallet that cannot cover them gets a 402, and the agent stays where it is. The agent's launchFees quotes what the next request charges.
229
+ * @async
230
+ * @roles api, admin, developer, billing, user
231
+ * @param {Object} params - The launch request
232
+ * @param {string} params.agentId - The agent ID
233
+ * @param {RequestOptions} [params.options] - Additional options for the request
234
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to the agent (status PENDING_REVIEW)
235
+ */
236
+ async launch({ agentId, options = {} }) {
237
+ this.client._require({ agentId });
238
+ return this.client(`/registration/${encodeURIComponent(agentId)}/launch`, { method: "POST", ...options });
239
+ }
240
+
241
+ /**
242
+ * Archive an agent
243
+ * @async
244
+ * @roles api, admin, developer, user
245
+ * @param {Object} params - The archive request
246
+ * @param {string} params.agentId - The agent ID
247
+ * @param {RequestOptions} [params.options] - Additional options for the request
248
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to the agent (status ARCHIVED)
249
+ */
250
+ async archive({ agentId, options = {} }) {
251
+ this.client._require({ agentId });
252
+ return this.client(`/rcs/agent/${encodeURIComponent(agentId)}/archive`, { method: "POST", ...options });
253
+ }
254
+
255
+ /**
256
+ * Resend a tester's expired invitation, which starts a new 24 hours for the tester to accept it. The number must be
257
+ * a tester on the agent (404) and its invitation must be EXPIRED (409); up to 20 invitations go out a day (429).
258
+ * @async
259
+ * @roles api, admin, developer, billing, user
260
+ * @param {Object} params - The resend request
261
+ * @param {string} params.agentId - The agent ID
262
+ * @param {string} params.phoneNumber - The tester's US number, with or without the +
263
+ * @param {RequestOptions} [params.options] - Additional options for the request
264
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to the agent
265
+ */
266
+ async resendTesterInvite({ agentId, phoneNumber, options = {} }) {
267
+ this.client._require({ agentId, phoneNumber });
268
+ return this.client(`/rcs/agent/${encodeURIComponent(agentId)}/testers/${encodeURIComponent(phoneNumber)}/resend`, { method: "POST", ...options });
269
+ }
270
+
271
+ /**
272
+ * Host the agent's logo (224 × 224 px, 50 KB max) or hero image (1440 × 448 px, 200 KB max), PNG or JPEG, and set
273
+ * it on the draft. Images of any other size are refused.
274
+ * @async
275
+ * @roles api, admin, developer, billing, user
276
+ * @param {Object} params - The upload
277
+ * @param {string} params.agentId - The agent ID
278
+ * @param {("logo"|"hero")} params.kind - Which image
279
+ * @param {Blob|File} params.file - The image bytes
280
+ * @param {string} [params.fileName] - Optional file name
281
+ * @param {RequestOptions} [params.options] - Additional options for the request
282
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to the agent with the new URL
283
+ */
284
+ async uploadAsset({ agentId, kind, file, fileName, options = {} }) {
285
+ this.client._require({ agentId, kind, file });
286
+ return this.multipartClient(`/rcs/agent/${encodeURIComponent(agentId)}/asset`, {
287
+ method: "POST",
288
+ body: agentAssetForm({ kind, file, fileName }),
289
+ ...options,
290
+ });
291
+ }
292
+ }
293
+
294
+ /**
295
+ * RCS messages. Sends go through an agent to POST /message/rcs. A message is a Message record (messageType RCS), so the
296
+ * messages methods read the same record. 404 while the environment's RCS switch is off; 403 while the group's rcsEnabled
297
+ * flag is off; 409 while the agent cannot send yet.
298
+ */
299
+ export class RcsMessages {
300
+ /**
301
+ * Keep the JSON client every RCS message request goes through.
302
+ * @param {any} client - The JSON request client
303
+ */
304
+ constructor(client) {
305
+ this.client = client;
306
+ }
307
+
308
+ /**
309
+ * Send an RCS message to up to 100 recipients. A check that blocks one recipient writes a BLOCKED message for it and the
310
+ * rest still send. Pass options.idempotencyKey to make a retry safe.
311
+ * @async
312
+ * @roles api, admin, developer, billing, user
313
+ * @param {Object} params - The send
314
+ * @param {string} params.agentId - The agent that sends (RCSA…)
315
+ * @param {RcsRecipient[]} params.recipients - Up to 100 recipients
316
+ * @param {string} [params.templateId] - A template to send; exactly one of templateId or content
317
+ * @param {number} [params.templateVersion] - A published version of templateId; needs templateId
318
+ * @param {Object} [params.content] - Inline content; exactly one of templateId or content
319
+ * @param {string} [params.contentFormat] - content.v1 (default) or google.rcs
320
+ * @param {("AUTHENTICATION"|"TRANSACTION"|"SERVICEREQUEST"|"ACKNOWLEDGEMENT"|"PROMOTION")} [params.trafficType] - Required on a MULTI_USE agent when the template sets none
321
+ * @param {number} [params.ttlSeconds] - Seconds the RCS message may wait for delivery; at most one of ttlSeconds or expireTime
322
+ * @param {string} [params.expireTime] - ISO-8601 time the RCS message expires
323
+ * @param {RcsMessageFallback} [params.fallback] - The fallback for this send
324
+ * @param {string} [params.statusCallbackUrl] - URL that receives this message's status events
325
+ * @param {boolean} [params.enableShortlink] - Shorten the links in the message
326
+ * @param {boolean} [params.isTest] - Send as a test; approved testers only
327
+ * @param {("not_capable"|"ttl_expired"|"delivered"|"read")} [params.simulate] - Simulate this outcome; approved testers only
328
+ * @param {RequestOptions} [params.options] - Additional options for the request
329
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to { requested, enqueued, failed, bulkId, messages } (201). A blocked row carries blockReason, reason and issues; an archived template answers 409 TEMPLATE_ARCHIVED
330
+ */
331
+ async send({ agentId, recipients, templateId, templateVersion, content, contentFormat, trafficType, ttlSeconds, expireTime, fallback, statusCallbackUrl, enableShortlink, isTest, simulate, options = {} }) {
332
+ this.client._require({ agentId, recipients });
333
+ return this.client("/message/rcs", {
334
+ method: "POST",
335
+ body: { agentId, recipients, templateId, templateVersion, content, contentFormat, trafficType, ttlSeconds, expireTime, fallback, statusCallbackUrl, enableShortlink, isTest, simulate },
336
+ ...options,
337
+ });
338
+ }
339
+
340
+ /**
341
+ * Check a send without writing anything. Takes the same parameters as send.
342
+ * @async
343
+ * @roles api, admin, developer, billing, user
344
+ * @param {Object} params - The send to check
345
+ * @param {string} params.agentId - The agent that sends (RCSA…)
346
+ * @param {RcsRecipient[]} params.recipients - Up to 100 recipients
347
+ * @param {string} [params.templateId] - A template to send; exactly one of templateId or content
348
+ * @param {number} [params.templateVersion] - A published version of templateId; needs templateId
349
+ * @param {Object} [params.content] - Inline content; exactly one of templateId or content
350
+ * @param {string} [params.contentFormat] - content.v1 (default) or google.rcs
351
+ * @param {("AUTHENTICATION"|"TRANSACTION"|"SERVICEREQUEST"|"ACKNOWLEDGEMENT"|"PROMOTION")} [params.trafficType] - Required on a MULTI_USE agent when the template sets none
352
+ * @param {number} [params.ttlSeconds] - Seconds the RCS message may wait for delivery; at most one of ttlSeconds or expireTime
353
+ * @param {string} [params.expireTime] - ISO-8601 time the RCS message expires
354
+ * @param {RcsMessageFallback} [params.fallback] - The fallback for this send
355
+ * @param {string} [params.statusCallbackUrl] - URL that receives this message's status events
356
+ * @param {boolean} [params.enableShortlink] - Shorten the links in the message
357
+ * @param {boolean} [params.isTest] - Send as a test; approved testers only
358
+ * @param {("not_capable"|"ttl_expired"|"delivered"|"read")} [params.simulate] - Simulate this outcome; approved testers only
359
+ * @param {RequestOptions} [params.options] - Additional options for the request
360
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to { valid, errors, warnings, billingClass, segments, estimatedCostMicros, unsupportedFiles, recipients }. valid is true only with no errors; each blocked recipient adds an error and carries blockReason, reason and issues
361
+ */
362
+ async validate({ agentId, recipients, templateId, templateVersion, content, contentFormat, trafficType, ttlSeconds, expireTime, fallback, statusCallbackUrl, enableShortlink, isTest, simulate, options = {} }) {
363
+ this.client._require({ agentId, recipients });
364
+ return this.client("/message/rcs/validate", {
365
+ method: "POST",
366
+ body: { agentId, recipients, templateId, templateVersion, content, contentFormat, trafficType, ttlSeconds, expireTime, fallback, statusCallbackUrl, enableShortlink, isTest, simulate },
367
+ ...options,
368
+ });
369
+ }
370
+
371
+ /**
372
+ * Price an RCS draft; no charge or send. Sends POST /message/estimate with channel "rcs". Amounts are microdollars.
373
+ * @async
374
+ * @roles api, admin, developer, billing, user
375
+ * @param {Object} params - The draft
376
+ * @param {string} params.agentId - The agent that would send (RCSA…)
377
+ * @param {RcsRecipient[]} [params.recipients] - Named recipients; exactly one of recipients or recipientCount
378
+ * @param {number} [params.recipientCount] - A recipient count; carriers are unknown, so the default fees apply
379
+ * @param {string} [params.templateId] - A template to price; exactly one of templateId or content
380
+ * @param {number} [params.templateVersion] - A published version of templateId; needs templateId
381
+ * @param {Object} [params.content] - Inline content; exactly one of templateId or content
382
+ * @param {string} [params.contentFormat] - content.v1 (default) or google.rcs
383
+ * @param {("AUTHENTICATION"|"TRANSACTION"|"SERVICEREQUEST"|"ACKNOWLEDGEMENT"|"PROMOTION")} [params.trafficType] - Required on a MULTI_USE agent when the template sets none
384
+ * @param {number} [params.ttlSeconds] - Seconds the RCS message may wait for delivery; at most one of ttlSeconds or expireTime
385
+ * @param {string} [params.expireTime] - ISO-8601 time the RCS message expires
386
+ * @param {RcsMessageFallback} [params.fallback] - The fallback to price; its from is optional here, and with none the leg is priced on the channel of the agent's linked campaign
387
+ * @param {RequestOptions} [params.options] - Additional options for the request
388
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to { billingClass, segments, recipientCount, rcsLeg, fallbackLeg, totals, balance, issues, warnings }; rcsLeg.mediaSurcharge is the carrier's surcharge on media over 5 MB, already inside rcsLeg.cost; a message over 100 MB adds a MEDIA_TOO_LARGE issue.
389
+ */
390
+ async estimate({ agentId, recipients, recipientCount, templateId, templateVersion, content, contentFormat, trafficType, ttlSeconds, expireTime, fallback, options = {} }) {
391
+ this.client._require({ agentId });
392
+ return this.client("/message/estimate", {
393
+ method: "POST",
394
+ body: { channel: "rcs", agentId, recipients, recipientCount, templateId, templateVersion, content, contentFormat, trafficType, ttlSeconds, expireTime, fallback },
395
+ ...options,
396
+ });
397
+ }
398
+
399
+ /**
400
+ * Report which numbers can receive RCS from an agent
401
+ * @async
402
+ * @roles api, admin, developer, billing, user
403
+ * @param {Object} params - The lookup
404
+ * @param {string} params.agentId - The agent (RCSA…)
405
+ * @param {string[]} params.phoneNumbers - Up to 500 numbers, 10-15 digits, with or without the +
406
+ * @param {RequestOptions} [params.options] - Additional options for the request
407
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to { results: [{ phoneNumber, capability }] }, capability being ENABLED, UNREACHABLE or UNKNOWN
408
+ */
409
+ async capabilities({ agentId, phoneNumbers, options = {} }) {
410
+ this.client._require({ agentId, phoneNumbers });
411
+ return this.client("/rcs/capabilities", { method: "POST", body: { agentId, phoneNumbers }, ...options });
412
+ }
413
+
414
+ /**
415
+ * Get one message by its ID. The same route as messages.getMessage.
416
+ * @async
417
+ * @roles api, admin, developer, billing, user
418
+ * @param {Object} params - The lookup
419
+ * @param {string} params.messageId - The message ID
420
+ * @param {RequestOptions} [params.options] - Additional options for the request
421
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to the message; an unknown ID is a 404
422
+ */
423
+ async get({ messageId, options = {} }) {
424
+ this.client._require({ messageId });
425
+ return this.client(`/message/${encodeURIComponent(messageId)}`, { method: "GET", ...options });
426
+ }
427
+
428
+ /**
429
+ * List RCS messages. Sends GET /message with messageType RCS. A fallback leg is an SMS or MMS message: read it with
430
+ * messages.getMessage and the parent's fallbackMessageId.
431
+ * @async
432
+ * @roles api, admin, developer, billing, user
433
+ * @param {Object} params - The group, the date range and the filters
434
+ * @param {string} params.groupId - The group whose messages to list
435
+ * @param {string} params.from - ISO-8601 date or timestamp; sent as startDate
436
+ * @param {string} params.to - ISO-8601 date or timestamp; sent as endDate
437
+ * @param {string} [params.agentId] - Messages this agent sent; sent as registrationId
438
+ * @param {string} [params.status] - Filter by status (ENQUEUED, DEQUEUED, SENT, FAILED, DELIVERED, READ, EXPIRED, FALLBACK, BLOCKED)
439
+ * @param {number} [params.page] - Page number
440
+ * @param {number} [params.limit] - Messages per page
441
+ * @param {string} [params.templateId] - Messages sent from this template
442
+ * @param {number} [params.templateVersion] - Messages sent from this template version
443
+ * @param {string} [params.bulkId] - Messages of one send
444
+ * @param {string} [params.fallbackReason] - Why the fallback ran (NOT_CAPABLE, CARRIER_NOT_LAUNCHED, TTL_EXPIRED, RCS_ERROR, PROVIDER_ERROR, SMS_ONLY)
445
+ * @param {string} [params.billingClass] - Filter by billing class (RICH, RICH_MEDIA)
446
+ * @param {string} [params.deliveredChannel] - Filter by the channel that delivered the message (rcs, sms, mms)
447
+ * @param {boolean} [params.isTest] - true for test messages only, false to leave them out
448
+ * @param {RequestOptions} [params.options] - Additional options for the request
449
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to the list of messages
450
+ */
451
+ async list({ groupId, from, to, agentId, status, page, limit, templateId, templateVersion, bulkId, fallbackReason, billingClass, deliveredChannel, isTest, options = {} }) {
452
+ this.client._require({ groupId, from, to });
453
+ const queryString = this.client._getQueryString({ registrationId: agentId, startDate: from, endDate: to, groupId, status, page, limit, templateId, templateVersion, bulkId, fallbackReason, billingClass, deliveredChannel, isTest, messageType: "RCS" });
454
+ return this.client(`/message${queryString}`, { method: "GET", ...options });
455
+ }
456
+ }
457
+
458
+ /**
459
+ * RCS (Google RBM) resources. Templates for RCS live under `templates`.
460
+ */
461
+ export class Rcs {
462
+ constructor(client, multipartClient) {
463
+ this.agents = new RcsAgents(client, multipartClient);
464
+ this.messages = new RcsMessages(client);
465
+ }
466
+ }
@@ -171,6 +171,8 @@ export class Registrations {
171
171
  * @param {string|string[]} [params.status] - Filter by one registration status or a list
172
172
  * @param {string} [params.parentRegistrationId] - Filter by the parent registration ID
173
173
  * @param {string} [params.phoneNumber] - Filter to registrations holding this phone number
174
+ * @param {string} [params.brandId] - RCS agents only: filter to agents linked to this brand (carrier id, provisional UUID or _id)
175
+ * @param {string} [params.campaignId] - RCS agents only: filter to agents linked to this campaign (campaign id or _id)
174
176
  * @param {string} [params.sortBy] - Sort field: createdAt (default), subgroupId, registrationId, region or status
175
177
  * @param {string} [params.sortOrder] - Sort direction: asc or desc (default)
176
178
  * @param {number} [params.page] - Page number (default 1)
@@ -178,8 +180,8 @@ export class Registrations {
178
180
  * @param {RequestOptions} [params.options] - Additional options for the request
179
181
  * @returns {Promise<SdkResponse<any>>} A promise that resolves to { data: [registrations], totalCount, page, limit }
180
182
  */
181
- async getRegistrations({ groupId, subgroupId, region, type, kind, status, parentRegistrationId, phoneNumber, sortBy, sortOrder, page, limit, options = {} } = {}) {
182
- const queryString = this.client._getQueryString({ groupId, subgroupId, region, type, kind, status, parentRegistrationId, phoneNumber, sortBy, sortOrder, page, limit });
183
+ async getRegistrations({ groupId, subgroupId, region, type, kind, status, parentRegistrationId, phoneNumber, brandId, campaignId, sortBy, sortOrder, page, limit, options = {} } = {}) {
184
+ const queryString = this.client._getQueryString({ groupId, subgroupId, region, type, kind, status, parentRegistrationId, phoneNumber, brandId, campaignId, sortBy, sortOrder, page, limit });
183
185
  return this.client(`/registration${queryString}`, { method: "GET", ...options });
184
186
  }
185
187
 
@@ -198,9 +200,81 @@ export class Registrations {
198
200
  return this.client(`/registration/${safeId}`, { method: "GET", ...options });
199
201
  }
200
202
 
203
+ /**
204
+ * Edit a draft, or a registration Signal House rejected, before submitting it (types that keep drafts, such as
205
+ * RCS_AGENT). `data` is a partial of the type's create fields: for RCS_AGENT `agent` and `consent` merge field by
206
+ * field, every other key replaces, and `campaignId: null` unlinks the campaign. 409 once submitted.
207
+ * @async
208
+ * @roles api, admin, developer, billing, user
209
+ * @param {Object} params - The parameters for the edit
210
+ * @param {string} params.registrationId - The registration ID (e.g. RCSA7K2M1QZ8RP)
211
+ * @param {Object} params.data - The fields to change
212
+ * @param {RequestOptions} [params.options] - Additional options for the request
213
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to the updated registration
214
+ */
215
+ async updateRegistration({ registrationId, data, options = {} }) {
216
+ this.client._require({ registrationId, data });
217
+ const safeId = encodeURIComponent(registrationId);
218
+ return this.client(`/registration/${safeId}`, { method: "PUT", body: data, ...options });
219
+ }
220
+
221
+ /**
222
+ * Check a draft against every submit requirement and the live state of its links, without writing
223
+ * @async
224
+ * @roles api, admin, developer, billing, user
225
+ * @param {Object} params - The parameters for the check
226
+ * @param {string} params.registrationId - The registration ID (e.g. RCSA7K2M1QZ8RP)
227
+ * @param {RequestOptions} [params.options] - Additional options for the request
228
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to { valid, errors: [{ field, reason }], warnings: [{ field, reason }] }
229
+ */
230
+ async validateRegistration({ registrationId, options = {} }) {
231
+ this.client._require({ registrationId });
232
+ const safeId = encodeURIComponent(registrationId);
233
+ return this.client(`/registration/${safeId}/validate`, { method: "POST", ...options });
234
+ }
235
+
236
+ /**
237
+ * Submit a draft. A type Signal House reviews goes to SIGNAL_HOUSE_REVIEW; a type it does not (RCS_AGENT) goes to
238
+ * SUBMITTING and is filed with the provider at once. A draft that fails a requirement gets a 400 whose details carry
239
+ * { code: "REGISTRATION_INCOMPLETE", errors, warnings }; a second submit, or one of a registration the provider
240
+ * already holds, gets a 409.
241
+ * @async
242
+ * @roles api, admin, developer, billing, user
243
+ * @param {Object} params - The parameters for the submission
244
+ * @param {string} params.registrationId - The registration ID (e.g. RCSA7K2M1QZ8RP)
245
+ * @param {RequestOptions} [params.options] - Additional options for the request
246
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to the registration, now SIGNAL_HOUSE_REVIEW or SUBMITTING
247
+ */
248
+ async submitRegistration({ registrationId, options = {} }) {
249
+ this.client._require({ registrationId });
250
+ const safeId = encodeURIComponent(registrationId);
251
+ return this.client(`/registration/${safeId}/submit`, { method: "POST", ...options });
252
+ }
253
+
254
+ /**
255
+ * Request the launch of a registration the provider already holds (an RCS agent in testing): the launch requirements
256
+ * are checked and the registration goes to SIGNAL_HOUSE_REVIEW, whose approval files the provider's launch request.
257
+ * Allowed while the provider reports the agent ready for testing, after a Signal House rejection, or after every
258
+ * carrier refused an earlier launch (409 otherwise); a failed requirement is a 400 whose details carry
259
+ * { code: "REGISTRATION_INCOMPLETE", errors, warnings }.
260
+ * An RCS agent's launch request charges its launch fees: a wallet that cannot cover them gets a 402, and nothing changes.
261
+ * @async
262
+ * @roles api, admin, developer, billing, user
263
+ * @param {Object} params - The parameters for the launch request
264
+ * @param {string} params.registrationId - The registration ID (e.g. RCSA7K2M1QZ8RP)
265
+ * @param {RequestOptions} [params.options] - Additional options for the request
266
+ * @returns {Promise<SdkResponse<any>>} A promise that resolves to the registration, now SIGNAL_HOUSE_REVIEW
267
+ */
268
+ async launchRegistration({ registrationId, options = {} }) {
269
+ this.client._require({ registrationId });
270
+ const safeId = encodeURIComponent(registrationId);
271
+ return this.client(`/registration/${safeId}/launch`, { method: "POST", ...options });
272
+ }
273
+
201
274
  /**
202
275
  * Cancel a registration. Allowed from SIGNAL_HOUSE_REVIEW, SIGNAL_HOUSE_APPROVED, PENDING_PROVIDER, NEEDS_INFORMATION,
203
- * PAYMENT_REQUIRED and APPROVED (409 otherwise). Numbers already allocated stay on the account and stop sending.
276
+ * PAYMENT_REQUIRED and APPROVED (409 otherwise), and for types that keep drafts also from DRAFT and SIGNAL_HOUSE_REJECTED.
277
+ * Numbers already allocated stay on the account and stop sending.
204
278
  * @async
205
279
  * @roles api, admin, developer, user
206
280
  * @param {Object} params - The parameters for cancelling the registration