-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdate.ts
51 lines (45 loc) · 1.41 KB
/
update.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
48
49
50
51
import {
getBatchIdFromConfig,
getPhoneNumberFromConfig,
getPrintFormat, getRecipientPhoneNumberFromConfig,
initSmsServiceWithServicePlanId,
printFullResponse,
} from '../../config';
import { Sms } from '@sinch/sdk-core';
(async () => {
console.log('**********************');
console.log('* UpdateBatchMessage *');
console.log('**********************');
const batchId = getBatchIdFromConfig();
const recipientPhoneNumber = getRecipientPhoneNumberFromConfig();
const senderPhoneNumber = getPhoneNumberFromConfig();
const requestData: Sms.UpdateBatchMessageRequestData= {
batch_id: batchId,
updateBatchMessageRequestBody: {
from: senderPhoneNumber,
parameters: {
name: {
[recipientPhoneNumber]: 'John',
default: 'there',
},
},
body: 'Hi ${name}! This is an updated message',
delivery_report: 'none',
type: 'mt_text',
} as Sms.ApiUpdateTextMtMessage,
};
const smsService = initSmsServiceWithServicePlanId();
let response;
try {
response = await smsService.batches.update(requestData);
} catch (error) {
console.error(`ERROR: The batch could not be updated`);
throw error;
}
const printFormat = getPrintFormat(process.argv);
if (printFormat === 'pretty') {
console.log(`The batch has been updated successfully. Here is the batch id: ${response.id}`);
} else {
printFullResponse(response);
}
})();