Astuces

Okay, thanks for answering my questions in comments, the EmotionalResponse function looks good. The way you have it set up currently should work well for a single response. If that is all you want Alexa to do here then just change ':ask' to ':tell' (which will respond and not expect the user to reply) so the line would become:

this.emit(':tell', EmotionalResponse(FeelingsList, 'Emotion', stateSlot.toUpperCase()).suggestion );

However, you want to be able to continue the conversation with multiple questions and response handlings. You might already have this but it’s not in your code above, and you need it to use the Alexa SDK, so make sure you have this line at the very beginning:

const Alexa = require('alexa-sdk');

You also need this, preferably at the end:

exports.handler = function(event, context, callback) {
    const alexa = Alexa.handler(event, context, callback);
    alexa.registerHandlers(handlers);
    alexa.execute();
};

Next, some things to know about continuing a conversation using Alexa SDK:

':ask'
will respond with the speechOutput sentence and expect a reply from the user, but if the user does not reply, then Alexa will « reprompt » the user with the repromptSpeech sentence.

':delegate'
will tell Alexa to determine which required slot to ask the user for, and use the prompt (set up in the Alexa developer console) to elicit the slot information from the user.

':elicitSlot'
will give Alexa the specific instructions of which slot to elicit and the exact prompt to use.


There are many ways to continue an Alexa conversation and build your logic of handling the user’s input and build an appropriate response. But to use your example of requesting more information from the user such as « Is it from your past or present? », here is one way I would suggest:

First, create another slot for this intent (anytime you want to hold user input information you’ll need another slot). Let’s call it Timeframe.

The simplest way is to « delegate » to Alexa to elicit this slot, so in the console make the slot required and add a prompt message such as, « Are you feeling this way because of something in your past or present? » You can even get fancy and use the emotion slot in that message like this: « Are you feeling {Emotion} because of something in your past or present? » Alexa will auto fill that and it will sound more intelligent and conversational.

Next you’ll want to improve the logic of this intent inside const handlers:

const handlers = {
   ...
   'EmotionalState': function () {
      var emotion = this.event.request.intent.slots.Emotion.value;
      var timeframe = this.event.request.intent.slots.Timeframe.value;
      if (!timeframe){
        this.emit(':delegate');
      } else {
        var response = responseBuilder(emotion, timeframe);
        this.emit(':tell', response);
      }
    },
    ...
} //<<--------------your code seems to be missing this to close handlers

function responseBuilder(emotion, timeframe) {
    // compare emotion with timeframe to build the appropriate response
    // just for example
    if (emotion=="sad" && timeframe=="past") { 
        return "My suggestion for feeling sadness about the past is, dry your tears and find a distraction.";
    }
}      

That’s just a rough idea, but should certainly get you progressing again. Good luck!

Références :

https://stackoverflow.com/questions/48625529/alexa-responses-and-response-builder

https://stackoverflow.com/questions/44112946/how-to-reply-with-questions-alexa

https://stackoverflow.com/questions/49471388/how-to-program-a-decision-tree-with-alexa/49492086#49492086

Publicités
Articles récents
Commentaires récents
fatima dans Bienvenue !
AdminDroid dans Bienvenue !
fatima dans Bienvenue !
Archives
Catégories
%d blogueurs aiment cette page :