I'm developing an Alexa Skill which has to do POST request to a REST api. When testing my POST-Function locally it's working like a charm, but when I deploy my package as Lambda-Function I have to invoke the skill twice (or more times) before the request is send. Is my POST-Function implementation wrong or do I miss something in the skill itself?
'use strict';
var Alexa = require('alexa-sdk');
var http = require( 'http' );
exports.handler = function(event, context, callback) {
var alexa = Alexa.handler(event, context);
alexa.APP_ID = APP_ID;
alexa.registerHandlers(handlers);
alexa.execute();
};
var handlers = {
'LaunchRequest': function () {
this.emit('GetFact');
},
'GetNewFactIntent': function () {
this.emit('GetFact');
},
'SendSMSIntent': function () {
this.emit('SendSMS');
},'SendSMS': function () {
console.log('===== SMS =====');
// Create speech output
var speechOutput = "SEND SMS";
postRequest('Message','Recipient','4657114258','SMS');
this.emit(':tellWithCard', speechOutput, SKILL_NAME)
},
'AMAZON.HelpIntent': function () {
var speechOutput = "";
var reprompt = "What can I help you with?";
this.emit(':ask', speechOutput, reprompt);
},
'AMAZON.CancelIntent': function () {
this.emit(':tell', 'Bye!');
},
'AMAZON.StopIntent': function () {
this.emit(':tell', 'Bye!');
}
};
function postRequest(m,r,u,t){
console.log('===== POST REQUEST =====');
var request = require('request');
request.post(
'Server.com',
{ json: { 'Message' : m,'Recipient' : r ,'UserID': u, 'Type': t } },
function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body)
}
}
);
}
via user3042626
No comments:
Post a Comment