-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtranscode.ts
50 lines (44 loc) · 1.5 KB
/
transcode.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
import { Conversation } from '@sinch/sdk-core';
import { getAppIdFromConfig, getPrintFormat, initConversationService, printFullResponse } from '../../config';
(async () => {
console.log('********************************');
console.log('* Transcoding_TranscodeMessage *');
console.log('********************************');
const appId = getAppIdFromConfig();
const requestData: Conversation.TranscodeMessageRequestData = {
transcodeMessageRequestBody: {
app_id: appId,
app_message: {
location_message: {
title: 'Phare d\'Eckmühl',
label: 'Pointe de Penmarch',
coordinates: {
latitude: 47.7981899,
longitude: -4.3727685,
},
},
},
channels: [
'MESSENGER',
],
from: 'from',
to: 'to',
},
};
const conversationService = initConversationService();
const response = await conversationService.transcoding.transcodeMessage(requestData);
const printFormat = getPrintFormat(process.argv);
if (printFormat === 'pretty') {
if (response.transcoded_message) {
console.log(`Transcoded messages:\n`);
Object.entries(response.transcoded_message).forEach(([channel, transcodedValue]) => {
const transcodedMessage = JSON.parse(transcodedValue);
console.log(channel + ': ' + JSON.stringify(transcodedMessage.message));
});
} else {
console.log('No transcoded messages returned.');
}
} else {
printFullResponse(response);
}
})();