I have a problem with input password in webchat.I used Sample - Customize Web Chat with Password Input Activity for password input card when I enter wrong password it show a message like wrong password please try again but when i enter password out of form i need to show another message.
I used this code.
if (card.activity.type === 'message') {
if (
card.activity.from.role === 'bot' &&
(card.activity.text === getLoginMessage(this.props.language) ||
card.activity.text === getLoginRetryMessage(this.props.language))
) {
let message = card.activity.text;
if (!this.hasSubmittedPassword && (card.activity.text === getLoginRetryMessage(this.props.language))) {
message = "Please fill the form and click enter in order to complete your request.";
}
return children => (
<ConnectedPasswordInputActivity
promptMessage={message}
passwordPlaceholder={this.props.literals.password}
language={this.props.language}
handlePasswordSubmit={this.handlePasswordSubmit}
>
{next(card)(children)}
</ConnectedPasswordInputActivity>
);
}
Refer to the image please
This is hard to know for certain as there is a lot of hidden code you are referencing, however I suspect the issue is tied to your hasSubmittedPassword function and your check against it.
You are matching on
A message
From a bot
Where the text equals either the getLoginMessage or getLoginRetryMessage return value
These are passing your check (based on the attached image).
You then check against hasSubmittedPassword which (apparently) is passing and then check a second time on getLoginRetryMessage (???). This second check is unnecessary as you wouldn't be in this if statement if the first check (card.activity.text = this.getLoginRetryMessage(this.props.language) hadn't succeeded.
This can be simplified to:
if (!this.hasSubmittedPassword) {
message = "Please fill the form and click enter in order to complete your request.";
}
That being said, your use of if(!this.hasSubmittedPassword) {...} is only checking if there is a returned value or not. This function may or may not be returning the correct value, but your check doesn't care. It only wants to know IF there is a value. If your logic is setup to always return something (i.e. true, false, yes, no, try again), then it will always pass.
From what I can see, if your first three checks pass, then you will always get the secondary message.
Hope of help!
Related
I have added retrySpeak property to builder.prompt.text incase if the user not responds for a while. But only the text in speak property will be spoken and not retrySpeak text. the below is the dialog which I am triggering from default dialog. I am testing this from cortana mobile app. Is there any property I missed here?
bot.dialog("mainServices", [
function(session){
builder.Prompts.text(session, 'How can I help you?', {
speak: 'How can I help you?',
retrySpeak: 'How can I help you,please say something',
inputHint: builder.InputHint.expectingInput
});
}
])
.triggerAction({
// The user can request this at any time.
// Once triggered, it clears the stack and prompts the main services again.
matches: /^start over$|^go back to main services$|^begin again$|start over services/i,
confirmPrompt: "This will cancel your request. Are you sure?"
});
IPrompt Options retrySpeak
This property is actually a re-prompt for if the response from the user was invalid, as opposed to a lack of response. For example, if speak prompted for a time (in my example a number), and the bot receives a string it cannot parse instead, retrySpeak is prompted asking for a valid message. This is where you can tell the user what input type you are expecting, or to enter a value within a set range, etc.
bot.dialog("/", [
function(session){
builder.Prompts.number(session, 'Please enter a time for your reservation', {
speak: 'Please enter a time, 1-4, for your reservation.',
retryPrompt: 'That is not a number!', //what bot types
retrySpeak: 'I\'m sorry. That is not a valid time. Please enter a time between 1:00 and 4:00', //what Cortana says
inputHint: builder.InputHint.expectingInput
});
},
function(session, results){
console.log(results)
session.endConversation();
}
])
If you are particularly looking for a timeout check, take a look at this botbuilder-timeout package, which reprompts after a certain amount of time. Please keep in mind that it's a third party app and I haven't tested it myself. :)
I have a Intent where I have a parameter called age and its value I want it to be the user input.
And in the response I would like to responde with the same input as user given ex:
User Input: Hello, haw are you.
Bot: You said: Hello, haw are you.
So I would need the user input first to store in a parameter and from the Text Response section I can call the parameter but I just don't know how to catch the user input at this moment!
So Text response would be like: You said: $input.
Assuming that you are using Javascript, you can find many useful details here.
Depending on the way you get the input, the solution is totally different.
For instance, in this link you get the input via a click (this.button.addEventListener("click", this.handleClick.bind(this))) or in the following code you get the input as a query.
import {ApiAiClient} from "api-ai-javascript";
import {IRequestOptions, IServerResponse, ApiAiConstants} from "api-ai-javascript/ApiAiClient"
const client = new ApiAiClient({accessToken: 'YOUR_ACCESS_TOKEN'})
queryInput.addEventListener("keydown", queryInputKeyDown);
.textRequest('Hello!')
.then((response) => {console.log(queryInput.value);})
Thus, in the above example, you can use:
value = queryInput.value
you can try it in Inline Editor Fulfillment
function userInput(agent) {
let user_input = agent.query;
//test it
agent.add(user_input);
}
The PromptDialog.Choice in the Bot Framework display the choice list which is working well. However, I would like to have an option to cancel/escape/exit the dialog with giving cancel/escape/exit optioin in the list. Is there anything in PromptDialog.Choice which can be overridden since i have not found any cancel option.
here is my code in c#..
PromptDialog.Choice(
context: context,
resume: ChoiceSelectAsync,
options: getSoftwareList(softwareItem),
prompt: "We have the following software items matching " + softwareItem + ". (1), (2), (3). Which one do you want?:",
retry: "I didn't understand. Please try again.",
promptStyle: PromptStyle.PerLine);
Example:
Bot: We have the following software items matching Photoshop. (1), (2), (3). Which one do you want
Version 1
Version 2
Version 3
What I want if user enter none of above or a command or number, cancel, exit, that bypasses the options above, without triggering the retry error message.
How do we do that?
There are two ways of achieving this:
Add cancel as an option as suggested. While this would definitely work, long term you will find repeating yourself a lot, plus that you will see the cancel option in the list of choices, what may not be desired.
A better approach would be to extend the current PromptChoice to add your exit/cancelation logic. The good news is that there is something already implemented that you could use as is or as the base to achieve your needs. Take a look to the CancelablePromptChoice included in the BotBuilder-Samples repository. Here is how to use it.
Just add the option "cancel" on the list and use a switch-case on the method that gets the user input, then call your main manu, or whatever you want to do on cancel
Current Prompt Choice does not work in that way to allows user select by number. I have override the ScoreMatch function in CancleablePromptChoice as below
public override Tuple<bool, int> ScoreMatch(T option, string input)
{
var trimmed = input.Trim();
var text = option.ToString();
// custom logic to allow users to select by number
int isInt;
if(int.TryParse(input,out isInt) && isInt <= promptOptions.Options.Count())
{
text = promptOptions.Options.ElementAt(isInt - 1).ToString();
trimmed = option.ToString().Equals(text) ? text :trimmed;
}
bool occurs = text.IndexOf(trimmed, StringComparison.CurrentCultureIgnoreCase) >= 0;
bool equals = text == trimmed;
return occurs ? Tuple.Create(equals, trimmed.Length) : null;
}
#Ezequiel Once again thank you!.
I have a Grails command object that I'm using for updating passwords. It looks like this:
class UpdatePasswordCommand {
String password
static constraints = {
password blank: false,
nullable: false,
size: 8..64,
matches: someLongRegex
validator: { String password, command ->
if (someService.isPasswordSameAsUsername(password)) {
return 'password.invalid.sameasuser'
}
}
I left out everything that doesn't pertain to the question I'm asking.
The problem I'm running into is that, whenever this validation triggers, it will trigger ALL the validations, and the command.errors collection will have an error message for each validation failure. This means that, for example, if the user tried to use test for the password, they will get the following error messages:
* Password length must be between 8 and 64 characters.
* Password must not be the same as the user name.
* Password must contain at least one special character, uppercase letter, and digit.
In this case, if the password length is wrong, I want the validation to stop at that point. Likewise, if it's the same as the username, I don't want it to check against the regex. Is there any way I can get the Grails validation to only return the first validation failure for a particular property? Note that it's important that I only want it to stop per property, because if the user doesn't type in his confirm password, for example, I still want to display two error messages:
* Password length must be between 8 and 64 characters.
* You must enter a confirm password.
Shouldn't that be a practice to provide all the validation messages preemptively to the user so that User can rectify or take care of them in one go, instead of rectifying it one by one?
But anyways you can programmatically force to return back only one message at a time something like below:
static constraints = {
password validator: { String password, command ->
def errorMsgs = []
if (!password){
errorMsgs << 'password.invalid.blank' //'password.invalid.null'
return errorMsgs
} else if (!(password.size() in (8..64))){
if (someService.isPasswordSameAsUsername(password)){
errorMsgs << 'password.invalid.sameasuser'
}
errorMsgs << 'password.invalid.length'
return errorMsgs
} else if (/*password not matching YourRegex*/){
errorMsgs << 'password.invalid.specialCharacters'
return errorMsgs
} else if (someService.isPasswordSameAsUsername(password)){
errorMsgs << 'password.invalid.sameasuser'
return errorMsgs
}
}
}
I think we have to take care of the special cases where more than one message is sent back by adding control logic as done above for password length and its match with user name.
Take a look at grails validate, the interesting thing is that you can pass property names to validate(). The second thing is errors property that implements spring Errors interface. You can use it to clean up messages to show only one for property. Write a custom validator as dmahapatro suggested is a good approach.
How can I show a validation error for a form field outside of a field constructor in Play framework 2? Here is what I tried:
#eventForm.("name").error.message
And I get this error:
value message is not a member of Option[play.api.data.FormError]
I'm confused because in the api docs it says message is a member of FormError. Also this works fine for global errors:
#eventForm.globalError.message
You can get a better grasp of it checking Form's sourcecode here
Form defines an apply method:
def apply(key: String): Field = Field(
this,
key,
constraints.get(key).getOrElse(Nil),
formats.get(key),
errors.collect { case e if e.key == key => e },
data.get(key))
That, as said in the doc, returns any field, even if it doesn't exist. And a Field has an errors member which returns a Seq[FormError]:
So, you could do something like that (for the Seq[FormError]):
eventForm("name").errors.foreach { error =>
<div>#error.message</div>
}
Or (for the Option[FormError])
eventForm("name").error.map { error =>
<div>#error.message</div>
}
Or, you could use Form errors:
def errors(key: String): Seq[FormError] = errors.filter(_.key == key)
And get all errors of a given key. Like this (for the Seq[FormError]):
eventForm.errors("name").foreach { error =>
<div>#error.message</div>
}
Or (for the Option[FormError])
eventForm.error("name").map { error =>
<div>#error.message</div>
}
If you want more details, check the source code. It's well written and well commented.
Cheers!
EDIT:
As biesior commented: to show human readable pretty messages with different languages you have to check how play works I18N out here
To be thorough you're probably going to have to deal with I18N. It's not hard at all to get it all working.
After reading the documentation you may still find yourself a bit consufed. I'll give you a little push. Add a messages file to your conf folder and you can copy its content from here. That way you'll have more control over the default messages. Now, in your view, you should be able to do something like that:
eventForm.errors("name").foreach { error =>
<div>#Messages(error.message, error.args: _*)</div>
}
For instance, if error.message were error.invalid it would show the message previously defined in the conf/messages file Invalid value. args define some arguments that your error message may handle. For instance, if you were handling an error.min, an arg could be the minimum value required. In your message you just have to follow the {n} pattern, where n is the order of your argument.
Of course, you're able to define your own messages like that:
error.futureBirthday=Are you sure you're born in the future? Oowww hay, we got ourselves a time traveler!
And in your controller you could check your form like that (just one line of code to show you the feeling of it)
"year" -> number.verifying("error.furtureBirthday", number <= 2012) // 2012 being the current year
If you want to play around with languages, just follow the documentation.
Cheers, again!
As you said yourself, message is a member of FormError, but you have an Option[FormError]. You could use
eventForm("name").error.map(_.message).getOrElse("")
That gives you the message, if there is an error, and "" if there isn't.