Reputation: 15
I want to make knock knock jokes using dialogflow, but I found that I can trigger one knock knock joke from the context of another. For example I have the following intents:
If the bot responds with annie, I can respond with orange who and get the orange punchline to the joke. How can I prevent this from happening? I only want the orange punchline to be able to be called when the response from the whosethere intent was orange.
Upvotes: 0
Views: 63
Reputation: 15
Thank you @andreas030241 for the information. I figured out how to get the logic to work by learning how to use fulfillment. I set the response of the knockknock-whosethere intent inside the inline editor, and created an associated context name, that I then used as the input context for whichever punchline intent I wanted to be valid. The example code is below. Much appreciation!
function punchline(agent) {
var names = [`Annie`,`Orange`,`Lena`,`Quiche`,`Wa`,`A little old lady`];
var context_names = ['annie-punchline','orange-punchline','lena-punchline','quiche-punchline','wa-punchline','alittleoldlady-punchline'];
var number = Math.floor(Math.random() * names.length);
agent.add(names[number]);
agent.setContext({
name: context_names[number],
lifespan: 1,
});
}
let intentMap = new Map();
intentMap.set('knockknock-whosethere', punchline);
agent.handleRequest(intentMap);
Upvotes: 0
Reputation: 100
I think you need to look into how to send a responsive via fulfilment/webhook and how contexts work. In your whosthere intent, you could send a response via fulfilment and set the context appropriately. E.g.: if you answer with "annie", set an annie specific context (e.g. punchline-annie-context) and set punchline-annie-context as an input context for the punchline-annie intent. This way you ensure that punchline-annie can only be activated, if the whosthere response was "annie".
Upvotes: 1