-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsendTextMessage.ts
47 lines (41 loc) · 1.32 KB
/
sendTextMessage.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { Sms } from '@sinch/sdk-core';
import {
getPhoneNumberFromConfig,
getPrintFormat,
getRecipientPhoneNumberFromConfig,
initSmsServiceWithServicePlanId,
printFullResponse,
} from '../../config';
(async () => {
console.log('*******************');
console.log('* SendTextMessage *');
console.log('*******************');
const recipientPhoneNumber = getRecipientPhoneNumberFromConfig();
const senderPhoneNumber = getPhoneNumberFromConfig();
const requestData: Sms.SendTextSMSRequestData = {
sendSMSRequestBody: {
type: 'mt_text',
to: [
recipientPhoneNumber,
],
from: senderPhoneNumber,
parameters: {
name: {
[recipientPhoneNumber]: 'John',
default: 'there',
},
},
body: 'Hi ${name}!',
delivery_report: 'full',
},
};
const smsService = initSmsServiceWithServicePlanId();
const response = await smsService.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}`);
})();