-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdate.ts
58 lines (48 loc) · 2.16 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
52
53
54
55
56
57
import { Conversation } from '@sinch/sdk-core';
import { getPrintFormat, getTemplateIdFromConfig, initConversationService, printFullResponse } from '../../config';
(async () => {
console.log('*******************************');
console.log('* Templates_v2_UpdateTemplate *');
console.log('*******************************');
const templateId = getTemplateIdFromConfig();
const conversationService = initConversationService();
const templateV2Response = await conversationService.templatesV2.get({
template_id: templateId,
});
const requestData: Conversation.V2UpdateTemplateRequestData = {
template_id: templateId,
updateTemplateRequestBody: {
version: templateV2Response.version,
description: 'Updated description for Template v2',
default_translation: templateV2Response.default_translation,
translations: [
// Repeat previous content to not lose it on update
...Conversation.templateV2Helper.getPreviousTranslations(templateV2Response.translations),
// New translation added in the scope of the update
{
language_code: 'fr-FR',
version: '1',
...Conversation.templateV2Helper.buildLocationMessageContent({
title: 'Phare d\'Eckmühl',
label: 'Pointe de Penmarch',
coordinates: {
latitude: 47.7981899,
longitude: -4.3727685,
},
}),
},
],
},
};
const response = await conversationService.templatesV2.update(requestData);
const printFormat = getPrintFormat(process.argv);
if (printFormat === 'pretty') {
console.log(`Template update:\nDefault translation: ${response.default_translation}\nList of translations:\n${response.translations?.map((translation) => formatPrettyMessage(translation)).join('\n')}`);
} else {
printFullResponse(response);
}
})();
const formatPrettyMessage = (translation: Conversation.V2TemplateTranslation) => {
const message = Conversation.templateV2Helper.getMessageFromTranslation(translation);
return ` - Language code: ${translation.language_code} - Version: '${translation.version}' - Message: ${JSON.stringify(message.content)}`;
};