Я пытаюсь построить разговорные навыки Alexa, используя Alexa SDK v1 в узле js с nforce (используйте для интеграции с Salesforce), но я сталкиваюсь с проблемой сессии.
Я пробовал 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