-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0cad94c
commit fe8b2aa
Showing
6 changed files
with
177 additions
and
22 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
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
42 changes: 42 additions & 0 deletions
42
examples/simple-examples/src/sms/batches/sendBinaryMessage.ts
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,42 @@ | ||
import { SendBinaryMessageRequestData, textToHex } from '@sinch/sdk-core'; | ||
import { | ||
getPhoneNumberFromConfig, | ||
getPrintFormat, | ||
getRecipientPhoneNumberFromConfig, | ||
initSmsClient, | ||
printFullResponse, | ||
} from '../../config'; | ||
|
||
(async () => { | ||
console.log('**************'); | ||
console.log('* SendBinary *'); | ||
console.log('**************'); | ||
|
||
const recipientPhoneNumber = getRecipientPhoneNumberFromConfig(); | ||
const senderPhoneNumber = getPhoneNumberFromConfig(); | ||
|
||
const requestData: SendBinaryMessageRequestData = { | ||
sendSMSRequestBody: { | ||
type: 'mt_binary', | ||
to: [ | ||
recipientPhoneNumber, | ||
], | ||
from: senderPhoneNumber, | ||
body: 'SGVsbG8sIHRoaXMgaXMgYSBTTVMgZnJvbSBTaW5jaA==', | ||
udh: textToHex('UserDataHeader'), | ||
delivery_report: 'full', | ||
}, | ||
}; | ||
|
||
const sinchClient = initSmsClient(); | ||
const response = await sinchClient.sms.batches.sendBinaryMessage(requestData); | ||
|
||
const printFormat = getPrintFormat(process.argv); | ||
|
||
if (printFormat === 'pretty') { | ||
console.log(`The SMS has been sent successfully. Here is the batch id: ${response.id}\nThe message (decoded) was: '${atob(response.body!)}'`); | ||
} else { | ||
printFullResponse(response); | ||
} | ||
console.log(`You may want to update your .env file with the following value: BATCH_ID=${response.id}`); | ||
})(); |
51 changes: 51 additions & 0 deletions
51
examples/simple-examples/src/sms/batches/sendMediaMessage.ts
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,51 @@ | ||
import { SendMediaMessageRequestData } from '@sinch/sdk-core'; | ||
import { | ||
getPhoneNumberFromConfig, | ||
getPrintFormat, | ||
getRecipientPhoneNumberFromConfig, | ||
initSmsClient, | ||
printFullResponse, | ||
} from '../../config'; | ||
|
||
(async () => { | ||
console.log('********************'); | ||
console.log('* SendMediaMessage *'); | ||
console.log('********************'); | ||
|
||
const recipientPhoneNumber = getRecipientPhoneNumberFromConfig(); | ||
const senderPhoneNumber = getPhoneNumberFromConfig(); | ||
|
||
const requestData: SendMediaMessageRequestData = { | ||
sendSMSRequestBody: { | ||
type: 'mt_media', | ||
to: [ | ||
recipientPhoneNumber, | ||
], | ||
from: senderPhoneNumber, | ||
parameters: { | ||
name: { | ||
[recipientPhoneNumber]: 'John', | ||
default: 'there', | ||
}, | ||
}, | ||
body: { | ||
url: 'https://media.body.url', | ||
message: 'Text message coming along with the media file', | ||
}, | ||
delivery_report: 'full', | ||
strict_validation: true, | ||
}, | ||
}; | ||
|
||
const sinchClient = initSmsClient(); | ||
const response = await sinchClient.sms.batches.sendMediaMessage(requestData); | ||
|
||
const printFormat = getPrintFormat(process.argv); | ||
|
||
if (printFormat === 'pretty') { | ||
console.log(`The MMS has been sent successfully. Here is the batch id: ${response.id}\nThe message was: '${response.body?.message}'`); | ||
} else { | ||
printFullResponse(response); | ||
} | ||
console.log(`You may want to update your .env file with the following value: BATCH_ID=${response.id}`); | ||
})(); |
47 changes: 47 additions & 0 deletions
47
examples/simple-examples/src/sms/batches/sendTextMessage.ts
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,47 @@ | ||
import { SendTextMessageRequestData } from '@sinch/sdk-core'; | ||
import { | ||
getPhoneNumberFromConfig, | ||
getPrintFormat, | ||
getRecipientPhoneNumberFromConfig, | ||
initSmsClient, | ||
printFullResponse, | ||
} from '../../config'; | ||
|
||
(async () => { | ||
console.log('*******************'); | ||
console.log('* SendTextMessage *'); | ||
console.log('*******************'); | ||
|
||
const recipientPhoneNumber = getRecipientPhoneNumberFromConfig(); | ||
const senderPhoneNumber = getPhoneNumberFromConfig(); | ||
|
||
const requestData: SendTextMessageRequestData = { | ||
sendSMSRequestBody: { | ||
type: 'mt_text', | ||
to: [ | ||
recipientPhoneNumber, | ||
], | ||
from: senderPhoneNumber, | ||
parameters: { | ||
name: { | ||
[recipientPhoneNumber]: 'John', | ||
default: 'there', | ||
}, | ||
}, | ||
body: 'Hi ${name}!', | ||
delivery_report: 'full', | ||
}, | ||
}; | ||
|
||
const sinchClient = initSmsClient(); | ||
const response = await sinchClient.sms.batches.sendTextMessage(requestData); | ||
|
||
const printFormat = getPrintFormat(process.argv); | ||
|
||
if (printFormat === 'pretty') { | ||
console.log(`The SMS has been sent successfully. Here is the batch id: ${response.id}\nThe message was: '${response.body}'`); | ||
} else { | ||
printFullResponse(response); | ||
} | ||
console.log(`You may want to update your .env file with the following value: BATCH_ID=${response.id}`); | ||
})(); |