我正在尝试使用具有nforce(用于与Salesforce集成)的Node js在Alexa中使用Alexa SDK v1来建立会话性Alexa技能,但是我遇到了一个问题。
我尝试了this.emit(:responsebody)
的response.shouldsessionattribute和response.listen
,但会话仍然超时。以前,我使用this.emit(':tell')
结束了会话,这就是为什么我将其替换为this.emit(:responsebody)
const alexaSDK = require('alexa-sdk');
const nforce = require('nforce');
const org = nforce.createConnection({
clientId: "NA",
clientSecret: "NA",
redirectUri: "NA"
});
const handlers = {
'LaunchRequest'() {
this.emit(':ask', instructions);
},
'Unhandled'() {
console.error('problem', this.event);
this.emit(':ask', 'An unhandled problem occurred!');
},
//this intent working fine
'LoginStartIntent'() {
const { accessToken } = this.event.session.user;
if(!accessToken ) {
this.emit(':tellWithLinkAccountCard', '');
}
else
{
//logic for integration
}
var speechOutput = "";
// this.emit(':tell', speechOutput); (this set the shouldsessionattribute to true)
//this.response.shouldEndSession = false;
this.response.speak(speechOutput); ( found this as a solution)
this.emit(":responseReady");
},
//this is not working error:session is not defiend
'NewLeadsIntent'(){
const { accessToken } = this.event.session.user;
if(!accessToken || !instanceUrl ) {
this.emit(':tellWithLinkAccountCard', '');
}
else
{
const query = '';
var speechOutput ;
console.log('working 1');
// auth and run query
org.query({ query:query ,oauth: getOauthObject(accessToken)}, function(err, res){
if(err)
{
console.log(err);
speechOutput = 'Darn, there was a Salesforce problem, sorry';
}
else {
// logic for sucess responsce
}
}
});
//this.emit(':tell', speechOutput); (this set the shouldsessionattribute to true)
this.response.speak(speechOutput);
//this.response.shouldEndSession = false; ( found this as a solution)
//this.response.listen(); ( found this as a solution)
this.emit(":responseReady");
}
},
'AMAZON.HelpIntent'() {
const speechOutput = '';
this.emit(':ask', speechOutput, reprompt);
},
'AMAZON.CancelIntent'() {
this.emit(':tell', 'Goodbye!');
},
'AMAZON.StopIntent'() {
this.emit(':tell', 'Goodbye!');
}
};
function getOauthObject(accessToken) {
// Construct our OAuth token based on the access token we were provided from Alexa
var oauth = {};
oauth.access_token = accessToken;
oauth.instance_url = instanceUrl;
return oauth;
}
exports.handler = function handler(event, context) {
const alexa = alexaSDK.handler(event, context);
alexa.appId = appId;
alexa.registerHandlers(handlers);
alexa.execute();
};
Cloudwatch日志