Programming chatbot in Dialogflow without responding to user - dialogflow-es

I'm aiming to program a chatbot on Dialogflow so that it runs through a series of questions without responding to user responses. This is part of an experiment where the user will think they are conversing with a human.
I'm using Fulfilment to enable functions that will edit the time in which the chatbot responds to the user (and so appear more humanlike). The most successful attempt at this interaction involved supplying training phrases in the intents. However, I won't be able to predict what the user will reply, so I need to programme the chatbot so that it ignores the responses.
When the chatbot does not recognise what the user is saying, it falls back onto the fallback intent. I have tried removing the fallback intent, but then it just says [empty response] when it doesn't understand the user.
How do I stop the chatbot from trying to analyse the user's responses?
Here is the code used for the interaction:
function greetings(agent) {
return respondSlowly( agent, 'Nice to meet you, I am Hilda. How is your week going?', 1500 );
}
function activities(agent) {
return respondSlowly( agent, 'I see! I am looking forward to the weekend. Are you ready for your first question?', 2000 );
}
Here is the code for mapping the intents:
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
intentMap.set('1. Greetings', greetings);
intentMap. set('1.2 Activities', activities) ;
intentMap. set('1.3 Start', start) ;
intentMap. set('1.4 Work', work) ;
intentMap. set('1.5 Work', work2) ;
intentMap. set('2. Social life', social) ;

Related

Amazon alexa skill game, managing program flow

I am creating a simple amazon alexa game.
I have all the intents I need for the game, but my question is how do I make sure you can only choose valid options?
Example: If alexa ask me a yes or no answer how to a promt for this?
Currently: If you answer with 10 example, it will say "You just triggered NumberIntent", I want it to say "Please choose a valid option" and then repromt until it gets a yes or no.
I am currently using the canhandle on the intents but it doesn't help for the program crashing.
Would be nice if anyone can help me!
You shouldn't try to force the user to respond to a specific question.
Vocal design is different than visual design. On a website, I can click wherever I want.
Alexa's interaction and vocal design in general is like a deck of card. Each card is an intent.
And as a user, I can choose to pick any card whenever I want.
As a user, I can say :
repeat the question
ask for help
launch another specific intent
or maybe I just want to quit the skill.
The card picked won't be the one you expect. It will go to either an intent you've defined or AMAZON.FallbackIntent
So be careful with that.
Maybe If I say something different, it's because I want to do something different.
If you still want to implement it on specific intent, you need to adapt the logic based on the user's progression.
After you ask the user a question, you save the progression in the sessionAttribute
const sessionAttributes = handlerInput.attributesManager.getSessionAttributes();
sessionAttributes.progression = "EXPECT_YES_OR_NO";
Within your intent, you add a logic to detect if the user should first response to yes or no
canHandle(handlerInput) {
return (
Alexa.getRequestType(handlerInput.requestEnvelope) === "IntentRequest" &&
Alexa.getIntentName(handlerInput.requestEnvelope) ===
"MySpecificIntent"
);
},
handle(handlerInput) {
const { responseBuilder } = handlerInput;
const sessionAttributes = handlerInput.attributesManager.getSessionAttributes();
if(sessionAttributes.progression === "EXPECT_YES_OR_NO") {
const utt = "I didn't catch that, do you like StackOverflow? You can say yes or no."
return responseBuilder.speak(utt).reprompt(utt).getResponse();
}
},
I recommend you to follow alexa skill sample tutorial zero to hero it summarise everything you need to know about developing a skill on Alexa with examples & videos.

How can I make Alexa Intent handler respond with different things each time it is called?

I am trying to develop an Alexa Skill with ASK node.js SDK. I am trying to build a game where the Alexa and the user take turns counting (not a great game, but useful educationally for me). Alexa starts with one, then the user two, then Alexa says three, and so on until the user says an incorrect number. In this case, I hope to implement logic to end the game.I am struggling to figure out how to get Alexa to respond differently after each time the user says a number. Is this a situation where I need multiple intent handlers? It seems like that would be silly, as the general logic does not change. I'm struggling to find up to date example code of game logic generally, so any resources that I can learn from would be greatly appreciated. The code I have as of yet is as follows--
const MyGameIntentHandler = {
canHandle(handlerInput) {
return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'MyGameIntent';
},
handle(handlerInput) {
const speechText = 'One';
return handlerInput.responseBuilder
.speak(speechText).listen()
.getResponse();
}
};
Obviously, I have not gotten very far. I have successfully created an intent and tested that Alexa will respond with 'One' when I ask to start a game. Where I am stuck is how to get Alexa to say 'One', then wait for a user to say 'Two', and depending on if they said the correct number, Alexa would say 'Three' or 'Game over' and end the game. The Codecademy course for ASK uses a different and outdated syntax, but it is the closest I have come yet to an answer. It suggests to chain a .listen() after speak, but does not provide information about whether this .listen() will re-prompt the same intent handler
To make it work as you wish, you need to keep the state of the game in Session Attributes between utterances. Please read it to better understand how it works.
If about your game, I would suggest to follow those steps:
You speak "start the game", the skill responses with "One" (you have already implemented this part) AND stores the game state (ie. by saving next expected answer)
When it's your turn, the skill should check if received answer is equal to expected and react - continue and store next expected answer or finish the game. For this step you'll need another handler for intent which expects just a number.
There is an example from Alexa team that shows how to create a game and store the state between utterances - Trivia Game.

Dialogflow: Is it possible to bypass the default reprompts if needed?

I am developing an app with dialogflow and actions-on-google, using webhook and node.js to program intents.
My problem is that dialogflow gives default reprompts on intents as seen in the code below.
app.intent('Reprompt', (conv) => {
const repromptCount = parseInt(conv.arguments.get('REPROMPT_COUNT'));
if (repromptCount === 0) {
conv.ask(`What was that?`);
} else if (repromptCount === 1) {
conv.ask(`Sorry I didn't catch that. Could you repeat yourself?`);
} else if (conv.arguments.get('IS_FINAL_REPROMPT')) {
conv.close(`Okay let's try this again later.`);
}
});
The context is that I am programming a conversational agent that asks users questions such as "What made you smile today?" and I expect the users to talk about this question with their partner. The best case scenario is that the app asks the question and then only listens for "Next question" or "End conversation", but does not interrupt the users.
As for now, the default reprompt interrupts the users, saying "What was that?" after a bit of time.
Is it possible to fiddle with the reprompt so that it stops doing that?
I know that the reprompts is part of the 'Best practice' for developing conversational agents, but I this case it seems counter intuitive.
I had a similar situation where I ask users a few questions (survey), and whatever the answer is, I go to the next question. From my understanding, you are looking for something similar. Let's suppose you want to ask the user 'What's your name?' and after they answer you want to ask them 'Where are you from?'.Here's how you do it (maybe not the optimal way but it works):
1. Create an intent 'name' and add a required parameter with prompt 'What is your name?'
2. Add a custom event 'userName'
3. Enable webhook call for the fulfillment
4. (Optional) You can add training phrases to invoke this intent
Follow the same steps as above to create another intent for the country
1. Name intent 'country' and add a required parameter with prompt 'Where are you from?'
2. Add a custom event 'userCountry'
3. same as above
Now we will write a fulfillment function for 'name' intent that will trigger country question
function Name(agent){
agent.add('This will invoke as respond to name question');
agent.setFollowupEvent('userCountry');
}
So, what is happening is that when the user invokes intent name he has to tell his name and your bot doesn't respond but instead trigger country intent, where answering 'Where are you from?' is also required. So the final conversation will look as follow:
Bot: What is your name?
User: Blah Blah
Bot: Where you from?
User: Blah Blah

List option in dialog flow for google assistant not giving correct results

I have been exploring Dialogflow from last 6-7 days and have created a bot which has menu in the form of List.
After going through lot of articles got to know that we need to have event actions_intent_OPTION in one of the intents for List to work properly. Also got to know that on top of it we need to have handler/intent for actions_intent_OPTION. This intent would be triggered once user taps one of the option of List.
Now i am struggling in defining handler for event actions_intent_OPTION. I had defined intent with name "actions_intent_OPTION-handler" but I am not able to find the code which i can code in for fulfillment section of Dialogflow, which will identify the option selected by user and will call the intent associated to that option.
I am a not from coding background, and I tried one code (index.js), but when deployed doesn't given any error however when executed on simulator it throws error "Failed to parse Dialogflow response into AppResponse because of empty speech response."
Reiterating my requirement, I am looking for a sample code which can capture the option selected by user (from list) and trigger the already defined intent.
Details about bot,list and intents is attached herewith.
This is the list defined by me and currently iam trying to code to capture the Payment Due Date option (which has text Payment Due Date Electricity defined in list
Code in fulfillment section
Intents defined
Note - Intent which needs to be called is "1.1 - ElectricityDetails - DueDate"
Here is the code -> Please don't ask me why i have used certain peice of code, as iam newbie :).
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {dialogflow} = require('actions-on-google');
const app = dialogflow({debug: true});
//const agent = new WebhookClient({ request, response });
let intentMap = new Map();
app.intent('actions_intent_OPTION-handler', (conv, params, option) => {
if (!option) {
conv.ask('You did not select any item from the list or carousel');
} else if (option === 'Payment Due Date Electricity') {
//conv.ask('You are great');
//intentMap.set('Default Welcome Intent', welcome);
intentMap.set('1.1 - ElectricityDetails - DueDate',option);
} else {
conv.ask('You selected ' + option);
}
});
//agent.handleRequest(intentMap);
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
You have a few issues here, so it is difficult to tell exactly which one is the real problem, but they all boil down to this statement in your question:
Please don't ask me why i have used certain peice of code
We understand that you're new - we've all been there! But copying code without understanding what it is supposed to do is a risky path.
That said, there are a few things about your design and code that jump out at me as issues:
Mixing libraries
You seem to be loading both the actions-on-google library and the dialogflow-fulfillment library. While most of what you're doing is with the actions-on-google library, the intentMap is what is used by the d-f library.
You can't mix the two. Pick one and understand how to register handlers and how those handlers are chosen.
Register handlers with actions-on-google
If you're using the a-o-g library, you'll typically create the app object with something like
const app = dialogflow();
and then register each handler with something like
app.intent( 'intent name', conv => {
// handler code here
});
You'll register the app to handle the request and response with something like
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);
Register handler with dialogflow-fulfillment
The dialogflow-fulfillment approach is similar, but it suggests creating a Map that maps from Intent Name to handler function. Something like this:
let intentMap = new Map();
intentMap.set( 'intent name', handlerFunction );
Where handlerFunction is also the name of a function you want to use as the handler. It might look something like
function handlerFunction( agent ){
// Handler stuff here
}
You can then create an agent, set the request and response objects it should use, and tell it to use the map to figure out which Intent Handler to call with something like
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
agent.handleRequest( intentMap );
Intents represent what the user does, not what you do with it
Remember that Intents represent a user's action.
What you do based on that action depends on a lot of things. In your case, once they have selected an option, you want to reply the same way as if they had triggered it with a particular Intent. Right?
You don't do that by trying to trigger that Intent.
What you do is you have both Handlers call a function that does what you want. There is nothing fancy about this - both are just calling the same function, just like lots of other code that can call common functions.
Don't try to dynamically register handlers
Related to the previous issue, trying to register a new Handler inside an existing Handler won't do what you want. By that time, it is too late, and the handlers are already called.
There may be situations where this makes sense - but they are very few, far between, and a very very advanced concept. In general, register all your handlers in a central place as I outlined above.

Slotfilling entities does not come through to fullfilment

I got a weird problem with dialogflow / node.js backend.
Within Dialogflow I have two entities "color" and "order_amount". I set the entities to required within the intent. But only one of the required entities is send back to my backend and the other is undefined. Though both are received within dialogflow.
app.intent('Default Welcome Intent - yes', (conv, {product_color}, {order_amount}) => {
console.log({product_color});
console.log({order_amount});
conv.ask(`Top. In welke maat?`);
});
So for example, when this intent runs the slotfilling is being done in dialogflow. But I only the first entity is defined e.g {color} and {order_amount} is undefined. When I switch {product_color} and {order_amount} as the below example. Then product_color is undefined.
app.intent('Default Welcome Intent - yes', (conv, {order_amount}, {product_color})
Anyone knows whats going on?
Got the answer myself. You can use "params": https://actions-on-google.github.io/actions-on-google-nodejs/classes/dialogflow.dialogflowconversation.html#parameters
The issue is that you're mangling your JavaScript. The second function parameter contains an object with all the Intent parameters. The {name1} syntax in JavaScript maps object attribute names to a variable. So you could rewrite the line as
app.intent('Default Welcome Intent - yes', (conv, {product_color,order_amount})

Resources