-
Notifications
You must be signed in to change notification settings - Fork 1
/
textapi.js
31 lines (27 loc) · 821 Bytes
/
textapi.js
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
const request = require('request');
const uuidv4 = require('uuid/v4');
const subscriptionKey = "720a6bbe3e914dc4a465dca0bd5f0e3e"
function generateRequestOptions(message) {
return {
method: 'POST',
baseUrl: 'https://api.cognitive.microsofttranslator.com/',
url: 'translate',
qs: {
'api-version': '3.0',
'to': 'it',
'to': 'en'
},
headers: {
'Ocp-Apim-Subscription-Key': subscriptionKey,
'Content-type': 'application/json',
'X-ClientTraceId': uuidv4().toString()
},
body: [{
'text': message
}],
json: true,
};
}
request(generateRequestOptions("Buenos dias mi amigo, que pasa?"), function(err, res, body){
console.log(JSON.stringify(body, null, 4));
});