Bot Framework V4 Dialog wait for user input without prompting - dialog

In Bot Framework V3 there was method Context.Wait() which provided a way how to wait for user input within dialog without necessarily prompting user for input. Typical scenario, is when you reply with HeroCard and you just wait for user's reaction, without sending pushy message like: "Please choose form the options".
In V4 I was not able to find to find context.Wait() respectively stepContext wait method, and so implementation of this behavior needed light walk around, provided in answer bellow. Maybe there is some better way ho to achieve it and will be glad if you share it.

you can return waiting result like this:
return new DialogTurnResult(DialogTurnStatus.Waiting);

To achieve wait behavior without prompting user with the text, you can use send empty prompt like this:
return await stepContext.PromptAsync("<emptyPrompt>", new PromptOptions { }, cancellationToken);

Related

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?"

Dialogflow inline editor ask for additional info

I am developing a google assistant app on Dialogflow.
And I have a intent that receives two entities: #name and #age
Using the fulfillment throught the inline editor I verify if the #age is below 18.
In that case I need to ask for additional info, I need to ask the name of the person responsible for the child.
I looked around the internet, including the fulfillment samples at https://dialogflow.com/docs/samples
I believe it would look something like this:
let conv = agent.conv();
conv.ask('As your age is under 18 I need the name of the person responsible for you:');
//Some code to retrieve user input into a variable
agent.add(conv);
But I was unable to find how to do it.
Can someone help me to achieve this?
Thanks in advance.
While you are handling an Intent, there is no way to "wait for" the user to respond to your question. Instead, you need to handle user input this way:
You send a response back from your Intent.
The user replies with something they say.
You handle this new user statement through an Intent.
Intents always represent the user taking some action - usually saying something.
So one approach would be to create a new Intent that accepts the user's response. But somehow you need to distinguish this response from the initial Intent that captured the person's name.
One way to do this would be, in the case you ask the question about who the responsible adult is, is to also set a Context. Then you can have a different Intent be triggered only when that Context is set and handle this new Intent to get the name of the adult.

Enter a user response through code

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?

BotFramework: Create Suggested Actions without text attribute

I'm creating a bot in DirectLine. I'm trying to use SuggestedActions to display a suggested action and I don't want to include the text attribute for that. When I try to run my code without the text attribute, I see a blank message being displayed. How can I avoid that?
My code
var msg = new builder.Message(session)
.suggestedActions(
builder.SuggestedActions.create(
session, [
builder.CardAction.imBack(session, "disconnect", "Disconnect"),
]
));
session.send(msg);
The Output i'm getting:
Per my understanding, you want a button which is shown absoluted at bottom and always display to remind your agent that he can disconnect conversation any time.
However, per me testing and understanding, in my opinion, there 2 points that it's maybe not a good idea to achieve this feature:
SuggestedAction is based on Messasge in Bot framework. And basically Bot application is for conversation. So every message between user and bot renderred in different channels should always be contained in a textbox, shown like in your capture. We cannot bypass this feature.
Per your requirements, I think you want this button should be always display unless the agent click it. But I didn't find any feature like this in Bot framework, and you may need to send this meesage additionally beside every message from bot, which is not graceful and will raise unpredictable risk.
My suggestion is that you can create a triggerAction to handle global disconnect requests. Refer https://learn.microsoft.com/en-us/bot-framework/nodejs/bot-builder-nodejs-dialog-actions for more info.

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