-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DEVEXP-557: Add snippets for SMS API
- Loading branch information
1 parent
960c736
commit 104f676
Showing
34 changed files
with
5,051 additions
and
836 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.idea | ||
node_modules | ||
**/tsconfig.tsbuildinfo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// eslint-disable-next-line no-unused-vars | ||
import { Sms, SmsService } from '@sinch/sdk-core'; | ||
|
||
/** @param {SmsService} smsService */ | ||
export const execute = async (smsService) => { | ||
|
||
const batchId = 'the_batch_id_to_cancel'; | ||
|
||
/** @type {Sms.CancelBatchMessageRequestData} */ | ||
const requestData= { | ||
batch_id: batchId, | ||
}; | ||
|
||
const response = await smsService.batches.cancel(requestData); | ||
|
||
console.log(`Response:\n${JSON.stringify(response, null, 2)}`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// eslint-disable-next-line no-unused-vars | ||
import { Sms, SmsService } from '@sinch/sdk-core'; | ||
|
||
/** @param {SmsService} smsService */ | ||
export const execute = async (smsService) => { | ||
|
||
const batchId = 'the_batch_id'; | ||
const recipientPhoneNumber = 'YOUR_recipient_phone_number'; | ||
|
||
/** @type {Sms.DeliveryFeedbackRequestData} */ | ||
const requestData= { | ||
batch_id: batchId, | ||
deliveryFeedbackRequestBody: { | ||
recipients: [ | ||
recipientPhoneNumber, | ||
], | ||
}, | ||
}; | ||
|
||
await smsService.batches.sendDeliveryFeedback(requestData); | ||
|
||
console.log('The delivery feedback has been sent'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// eslint-disable-next-line no-unused-vars | ||
import { Sms, SmsService } from '@sinch/sdk-core'; | ||
|
||
/** @param {SmsService} smsService */ | ||
export const execute = async (smsService) => { | ||
|
||
const from = 'YOUR_sinch_phone_number'; | ||
const recipient = 'YOUR_recipient_phone_number'; | ||
const body = 'This is a test SMS message using the Sinch Node.js SDK.'; | ||
|
||
/** @type {Sms.DryRunRequestData} */ | ||
const requestData= { | ||
dryRunRequestBody: { | ||
type: 'mt_text', | ||
from, | ||
to: [ | ||
recipient, | ||
], | ||
body, | ||
}, | ||
}; | ||
|
||
const response = await smsService.batches.dryRun(requestData); | ||
|
||
console.log(`Response:\n${JSON.stringify(response, null, 2)}`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// eslint-disable-next-line no-unused-vars | ||
import { Sms, SmsService } from '@sinch/sdk-core'; | ||
|
||
/** @param {SmsService} smsService */ | ||
export const execute = async (smsService) => { | ||
|
||
const batchId = 'the_batch_id'; | ||
|
||
/** @type {Sms.GetBatchMessageRequestData} */ | ||
const requestData= { | ||
batch_id: batchId, | ||
}; | ||
|
||
const response = await smsService.batches.get(requestData); | ||
|
||
console.log(`Batch details:\n${JSON.stringify(response, null, 2)}`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// eslint-disable-next-line no-unused-vars | ||
import { Sms, SmsService } from '@sinch/sdk-core'; | ||
|
||
/** @param {SmsService} smsService */ | ||
export const execute = async (smsService) => { | ||
|
||
const oneWeekAgo = new Date(); | ||
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7); | ||
oneWeekAgo.setHours(0, 0, 0, 0); | ||
|
||
/** @type {Sms.ListBatchesRequestData} */ | ||
const requestData= { | ||
start_date: oneWeekAgo, | ||
page_size: 2, | ||
}; | ||
|
||
console.log('List of batches printed one by one:'); | ||
// Use the iterator and fetch data from all the pages automatically | ||
for await (const batch of smsService.batches.list(requestData)) { | ||
console.log(JSON.stringify(batch, null, 2)); | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// eslint-disable-next-line no-unused-vars | ||
import { Sms, SmsService } from '@sinch/sdk-core'; | ||
|
||
/** @param {SmsService} smsService */ | ||
export const execute = async (smsService) => { | ||
|
||
const oneWeekAgo = new Date(); | ||
oneWeekAgo.setDate(oneWeekAgo.getDate() - 7); | ||
oneWeekAgo.setHours(0, 0, 0, 0); | ||
|
||
/** @type {Sms.ListBatchesRequestData} */ | ||
const requestData= { | ||
start_date: oneWeekAgo, | ||
page_size: 2, | ||
}; | ||
|
||
/** @type {Sms.SendSMSResponse[]} */ | ||
const batchesList = []; | ||
// Fetch a page of Batches | ||
let response = await smsService.batches.list(requestData); | ||
// Fetch the data page by page manually | ||
while (response.hasNextPage) { | ||
batchesList.push(...response.data); | ||
response = await response.nextPage(); | ||
} | ||
batchesList.push(...response.data); | ||
|
||
console.log(`Full list of batches printed at once (length = ${batchesList.length}):\n${JSON.stringify(batchesList, null, 2)}`); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// eslint-disable-next-line no-unused-vars | ||
import { Sms, SmsService, textToHex } from '@sinch/sdk-core'; | ||
|
||
/** @param {SmsService} smsService */ | ||
export const execute = async (smsService) => { | ||
|
||
const from = 'YOUR_sinch_phone_number'; | ||
const recipient = 'YOUR_recipient_phone_number'; | ||
const batchId = 'the_batch_id_scheduled_in_the_future'; | ||
|
||
/** @type {Sms.ReplaceBatchMessageRequestData} */ | ||
const requestData= { | ||
batch_id: batchId, | ||
replaceBatchMessageRequestBody: { | ||
type: 'mt_binary', | ||
from, | ||
to: [ | ||
recipient, | ||
], | ||
udh: textToHex('UserDataHeader'), | ||
body: btoa('This is a replaced message'), | ||
client_reference: 'Sinch Node.js SDK snippet', | ||
}, | ||
}; | ||
|
||
const response = await smsService.batches.replace(requestData); | ||
|
||
console.log(`Replaced batch:\n${JSON.stringify(response, null, 2)}`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// eslint-disable-next-line no-unused-vars | ||
import { Sms, SmsService, textToHex } from '@sinch/sdk-core'; | ||
|
||
/** @param {SmsService} smsService */ | ||
export const execute = async (smsService) => { | ||
|
||
const from = 'YOUR_sinch_phone_number'; | ||
const recipient = 'YOUR_recipient_phone_number'; | ||
|
||
/** @type {Sms.SendBinarySMSRequestData} */ | ||
const requestData= { | ||
sendSMSRequestBody: { | ||
type: 'mt_binary', | ||
from, | ||
to: [ | ||
recipient, | ||
], | ||
body: 'SGVsbG8sIHRoaXMgaXMgYSBTTVMgZnJvbSBTaW5jaA==', | ||
udh: textToHex('UserDataHeader'), | ||
delivery_report: 'full', | ||
}, | ||
}; | ||
|
||
const response = await smsService.batches.sendBinaryMessage(requestData); | ||
|
||
console.log(`Response for binary batch:\n${JSON.stringify(response, null, 2)}`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// eslint-disable-next-line no-unused-vars | ||
import { Sms, SmsService } from '@sinch/sdk-core'; | ||
|
||
/** @param {SmsService} smsService */ | ||
export const execute = async (smsService) => { | ||
|
||
const from = 'YOUR_sinch_phone_number'; | ||
const recipient = 'YOUR_recipient_phone_number'; | ||
|
||
/** @type {Sms.SendMediaSMSRequestData} */ | ||
const requestData= { | ||
sendSMSRequestBody: { | ||
type: 'mt_media', | ||
from, | ||
to: [ | ||
recipient, | ||
], | ||
body: { | ||
url: 'https://media.body.url', | ||
message: 'Text message coming along with the media file', | ||
}, | ||
delivery_report: 'full', | ||
strict_validation: true, | ||
}, | ||
}; | ||
|
||
const response = await smsService.batches.sendMediaMessage(requestData); | ||
|
||
console.log(`Response for MMS batch:\n${JSON.stringify(response, null, 2)}`); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// eslint-disable-next-line no-unused-vars | ||
import { Sms, SmsService } from '@sinch/sdk-core'; | ||
|
||
/** @param {SmsService} smsService */ | ||
export const execute = async (smsService) => { | ||
|
||
const from = 'YOUR_sinch_phone_number'; | ||
const recipient = 'YOUR_recipient_phone_number'; | ||
|
||
/** @type {Sms.SendTextSMSRequestData} */ | ||
const requestData= { | ||
sendSMSRequestBody: { | ||
type: 'mt_text', | ||
from, | ||
to: [ | ||
recipient, | ||
], | ||
body: 'Hi ${name}!', | ||
parameters: { | ||
name: { | ||
[recipient]: 'John', | ||
default: 'there', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
const response = await smsService.batches.sendTextMessage(requestData); | ||
|
||
console.log(`Response for SMS batch:\n${JSON.stringify(response, null, 2)}`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// eslint-disable-next-line no-unused-vars | ||
import { Sms, SmsService } from '@sinch/sdk-core'; | ||
|
||
/** @param {SmsService} smsService */ | ||
export const execute = async (smsService) => { | ||
|
||
const batchId = 'the_batch_id_scheduled_in_the_future'; | ||
const from = 'YOUR_sinch_phone_number'; | ||
|
||
/** @type {Sms.UpdateBatchMessageRequestData} */ | ||
const requestData= { | ||
batch_id: batchId, | ||
updateBatchMessageRequestBody: { | ||
type: 'mt_text', | ||
from, | ||
body: 'Hi ${name}! This is an updated message', | ||
delivery_report: 'per_recipient', | ||
}, | ||
}; | ||
|
||
const response = await smsService.batches.update(requestData); | ||
|
||
console.log(`Response:\n${JSON.stringify(response, null, 2)}`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// eslint-disable-next-line no-unused-vars | ||
import { Sms, SmsService } from '@sinch/sdk-core'; | ||
|
||
/** @param {SmsService} smsService */ | ||
export const execute = async (smsService) => { | ||
|
||
const batchId = 'the_batch_id'; | ||
|
||
/** @type {Sms.GetDeliveryReportByBatchIdRequestData} */ | ||
const requestData= { | ||
batch_id: batchId, | ||
}; | ||
|
||
const response = await smsService.deliveryReports.get(requestData); | ||
|
||
console.log(`Delivery report:\n${JSON.stringify(response, null, 2)}`); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// eslint-disable-next-line no-unused-vars | ||
import { Sms, SmsService } from '@sinch/sdk-core'; | ||
|
||
/** @param {SmsService} smsService */ | ||
export const execute = async (smsService) => { | ||
|
||
const batchId = 'the_batch_id'; | ||
const recipient = 'YOUR_recipient_phone_number'; | ||
|
||
/** @type {Sms.GetDeliveryReportByPhoneNumberRequestData} */ | ||
const requestData= { | ||
batch_id: batchId, | ||
recipient_msisdn: recipient, | ||
}; | ||
|
||
const response = await smsService.deliveryReports.getForNumber(requestData); | ||
|
||
console.log(`Recipient delivery report:\n${JSON.stringify(response, null, 2)}`); | ||
}; |
Oops, something went wrong.