diff --git a/alexa-api/server.js b/alexa-api/server.js index 636b147..d458e58 100644 --- a/alexa-api/server.js +++ b/alexa-api/server.js @@ -37,6 +37,7 @@ function httpsRequest(path, options, extraCookies) { extraCookies = extraCookies || ''; return new Promise(function(resolve, reject) { var allCookies = ALEXA_COOKIE + (extraCookies ? '; ' + extraCookies : ''); + var bodyBuf = options.body ? Buffer.from(options.body, 'utf8') : null; var reqOpts = { hostname: ALEXA_HOST, path: path, @@ -46,7 +47,7 @@ function httpsRequest(path, options, extraCookies) { 'Accept': 'application/json, text/plain, */*', 'Accept-Language': 'ja-JP,ja;q=0.9', 'Cookie': allCookies, - }, options.headers || {}), + }, bodyBuf ? { 'Content-Length': bodyBuf.length } : {}, options.headers || {}), }; var req = https.request(reqOpts, function(res) { var body = ''; @@ -54,7 +55,7 @@ function httpsRequest(path, options, extraCookies) { res.on('end', function() { resolve({ status: res.statusCode, headers: res.headers, body: body }); }); }); req.on('error', reject); - if (options.body) req.write(options.body); + if (bodyBuf) req.write(bodyBuf); req.end(); }); } @@ -136,8 +137,9 @@ app.post('/speak', async function(req, res) { deviceType: target.deviceType, deviceSerialNumber: target.serialNumber, customerId: customerId, - locale: '', + locale: 'ja-JP', textToSpeak: text, + speakType: 'ssml' }, }, };