Enter a user response through code - node.js

I'm currently working on Microsoft Botframework Node.js SDK.
I was wondering if there was a way to hard code a user response for a prompt through the code?
The scenario is to add/ remove people to the meeting. The dialog contains 2 waterfall functions. The first is used to handle card actions, and display the default prompt to enter a username to search for. The second function searches for the username and displays the results in a carousel. Selecting a user from the card adds the person to the meeting (handled in first waterfall function).
Once a user is added to the meeting, the first waterfall function displays the currently added people in the meeting with the option to remove, followed by the default prompt to search users. Since it expects a prompt response, the "remove" actions causes a break and the bot's response is: "I didn't understand. Please try again.".
So is it possible to hard code a null user response through the code when the "remove" action is triggered? Or is there any other way to bypass a prompt without any input from the user's end?

Related

Is there callback available for any RichResponse in Dialogflow

I have a dialogflow requirement to present user a payment link, on the click of which I must hang on 20 seconds (show some busy image or something) and then call on the next Intent.
So far I have been able to present a link using LinkOutSuggestion/BasicCard button. But I do not have idea that how I can make my program proceed further. I know there is a approach to have user input something like "Check Payment", but can we skip this altogether and just pass on to next intent post click of that LinkOutSuggestion or BasicCard Button?
The only way you could skip the part of the user having to input something in the chat is by using a Suggestion. These suggestions cannot be added to a card or open a link, but they do continue the conversation with the text that is used, so you could add a suggestion saying Check Payment.
The linkout suggestion or buttons on card do not support a click event or the possibility to continue the conversation.

How to prompt a question from lambda function to user when dialogState is completed

I am creating an Alexa skill, but it got rejected by Amazon. The way my skill works is as follows,
User: "alexa, ask doctor is it safe to use vaccine during pregnancy"
Alexa: "gives a response, fetched from DynamoDB"
- (dialogState: Complete)
I got the following review comments from Amazon:
After the skill completes a task, the session remains open with no prompt to the user. The skill must close the session after fulfilling requests if it does not prompt the user for any input.
Can anyone help me with this?
I tried to use DelegateDialog but it doesn't seem to work.
handler_input.response_builder.add_directive(DelegateDirective())
.speak(message)
.ask(reprompt)
.set_card(SimpleCard("Custom", message))
I want Alexa to ask a question to the user, like "Do you have any other question?"
So that the conversation doesn't end and keeps going. I don't want to close the session right after Alexa sends the answer.
A couple of things:
delegate directive is when you want ASK(Alexa Skills Kit) to determine the next thing to speak. This only makes sense if you have a dialog model (requires slots, elicitation prompts, etc.) and the dialog is not yet completed. You do not seem to be using dialog model and at any case you are both delegating and providing speak() which I don't think is what you want.
For your scenario, you will likely want to produce a complete output that has both the answer and the next question. it can be as simple as string-append: message = db_response + ". Anything else?"

How to access update the next context a user should go to [DialogFlow Fulfillment]

I am using contexts within Dialogflow to call the next intent for the user. What I would like to do is have the ability for someone to change their mind on an answer they just entered. For example, as seen in the image below, if I enter a name then it would ask for an email. However, the user should be able to say "can I change my name" and go back to the context where Dialogflow is asking for a name.
I already have that intent implemented but I am trying to figure out how to go back to the question they were going to answer before deciding to change their name. I can use fulfillment to capture the raw API response and possibly get the last context however how can I force the user after changing their name to go back their previous context/intent?
You can do this easily by using the fulfillment. You have to save the previous intent contexts and prompt as well as the next intent contexts and prompt in the parameters of the intent.

How to redirect to another intent within a Google Action (Google Assistant Action)

Currently I'm creating an Action for the Google Assistant.
In this Action, I ask the user to provide its phone number. After this, another intent will repeat the phone number given, and asks if it's correct. If the user responds with 'no', I would like to redirect the user back to the first intent, so it can provide its phone number again. It should be a kind of loop.
(I'm working in a local environment, so only the intents are created within Dialogflow.)
I tried to apply contexts for this case, but in someway it won't succeed.
Thank you guys!
Remember that Intents represent what the user has said, and not what you are doing with that data. So saying that "another intent will repeat the phone number" suggests that you're making some things more complicated.
A better design is likely to have the Intent that collected the data to several things:
Repeat the phone number back
Prompt if this is correct
Set a content indicating you have prompted for confirmation
You can then have another Intent handle the "yes" or "no" statements responding to this prompt. The user may say other things, remember, including giving a correction to the phone number.
See also these articles (based on a StackOverflow question and answer) on designing a conversation and the Dialogflow Intents based on that conversation:
Thinking for Voice: Design conversations, not logic
Conversation to Code (Part 1)

Microsoft Botframework Prompts.choice not getting validation response

I am using chatconnector to connect my Bot to an frontend chat app and writing the bot's response to my own database. The problem is when I am validating a prompt the bot responds but there's no API for me to grab the validation response.
bot.dialog('/', [
function (session) {
builder.Prompts.choice(session, "Which color?", "red|green|blue");
},
function (session, results, next) {
//after the user respond, the bot validates the input, if it's not
//one of the choices, this next function in the waterfall doesn't
//even run, therefore I have no way to write the bot response
//into my own chat database and render it for the user
}])
Is there anyway I can grab the bot's response to the failed validation?
Short answer: No.
Long answer: This is not currently a feature of the SDK. If the input response to a choice prompt does not match any of the provided options, aka "intents", then the waterfall dialog does not proceed to step 2 because there is no match response. The system design is to warn the user and wait for them to input one of the provided choices either by name or number (depending on the channel). Eg. if the answer does not match any of the choice options, the framework will prompt the user with "I didn't understand. Please choose an option from the list." until a valid option is input.
Hacker answer: You would need to modify the SDK to suit your needs in this scenario, and then deploy you bot using your customized version of the SDK. The file you are looking for is Microsoft/BotBuilder/Node/core/src/dialogs/PromptChoice.ts
I have written a custom recognizer that allows Choice Prompts to be configured as optional. I.e. if a user does not click a button, but instead enters text that cannot be matched to a given choice, your waterfall dialog will proceed and you can handle the given user input individually.
Have a look at this:
https://gist.github.com/vwart/faddaee279aab5127707862ec4994574
The provided snippets are not compilable or runnable, I copied them together from my productive code. But it should be enough for you to apply the solution for your bot.
How it works:
CustomChoiceOptions:
When you start a Choice Prompt you pass a new bool flag called "optional" within the options.
OptionalPromptRecognizer:
A global recognizer registered at bot initialization. It is looking for messages in reply to a prompts that carries this optional flag. If it finds one, it will dispatch you a dummy dialog with a low score. The low score is important, so that other recognizers can beat it. E.g. LUIS Recognizer or the actual choice recognizer, which will return a score of 1.0 if the user actually hits a choice button.
If there is no recognizer that claims a reasonable score, our recognizer will be considered the best option and therefore our dummy dialog is triggered.
optional-choice-dispatcher:
The dummy dialog does nothing but creating a fake PromptChoiceResult with the index -1 and an entity that holds the actual user input. This result is then passed down your dialog stack, that means your next step can handle it.
This case can be identified due to the index of -1.
Have fun!

Resources