How can I use PromptDialog.Choice while allowing the user to type the options without worrying about accented letters? - bots

How can I use PromptDialog.Choice while allowing the user to type the options without worrying about accented letters?
Given the following prompt to the user:
List<string> promptValues = new List<string> { "Sim", "Não" };
PromptDialog.Choice<string>(context,
AfterPrompt,
promptValues,
"Digite 'Sim' ou 'Não'",
"Opção inválida, por favor tente novamente.");
How can I allow the user to input "Nao" or "Não" without the prompt considering "Nao" as a wrong answer?
I can't use PromptDialog.Confirm because I need the dialogs to happen in Portuguese, and as far as I know I can't localize PromptDialog.Choice.
Also I want to know how can I ignore accents even with other kinds of prompt, not only Yes or No prompts.
Is there a way to do this?

I believe you might be able to localize the PromptConfirm options if you change the culture of the bot like:
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("de-DE");
because the options are being retrieved from a resource file (see this)
Now, it seems that the Portuguese resource is not implemented yet, which from my point of view it could be something great to contribute if you want to.
On the other hand, if you want to have some custom logic in the PromptChoice, you can always inherit from it and override the TryParse method to add your checks. Here is an example of a custom PromptChoice.

Related

Clear session or session variables on Bixby

Is there a way to specify that a session should be ended, or to clear out the memory of previous actions? In my testing (simulator only) I'm seeing a couple cases where Bixby is remembering a previous entry that isn't relevant anymore.
Example utterances
remove wet diaper
wet diaper
In this case there's 2 possible enums that can be said. "actionType" that is optional, in this case "remove" and "statType", in this case "wet diaper".
What is happening is on the second phrase it's caching the actionType. So, the second phrase my JavaScript still receives the "remove" even though it's not included.
I haven't tried this on an actual device (only the simulator) so it's possible this is just a simulation quirk.
This is kind of related to this question. There was a follow-up comment that the OP asked related to session management.
How does Bixby retain data from a previous NL input?
So, if you read that link. Is there a way I can signal to bixby that the conversation is over, or at least to not remember previous entries for the action?
One way would be to use the transient feature. Here is more information
For example, alter your input type so it doesn't carry over across executions.
name (ActionType) {
features {
transient
}
}
make sure all input types are NL friendly. name/enum concepts are meant for NL and you can attach vocabulary to them.
I used to have a similar issue like yours, in my case, my problem was related to the type of the 'requires' property inside the input-group declared in my action.model.bxb.
You need to handle by separate this two input cases in diferent action.model.bxb files:
In one of them you might have something like (model 1):
input-group(removeWeaper){
requires (OneOrMoreOf)
collect{
input (ActionType) {
type (Type)
min (Optional)
}
input (StatType) {
type (Type)
min (Optional)
}
}
Here, Bixby Will know that at least one of these properties will be apear in your input and will be waiting for an input with that structure.
In the other file you might have (model 2):
input-group(Weaper){
requires (OneOf)
collect{
input (StatType) {
type (Type)
min (Optional)
}
}
Here, Bixby will be waiting to catch an input that contains only one of the indicated values in you input.
(model 1) This could be ok only if you run 'wet diaper' by first time, also when you try again and run 'remove wet diaper' it might work, the problem is when you run again 'wet diaper' because Bixby Stores you previous approach including "remove". i'm not sure if there is something to clear the stored values, but, here is when (model 2) will help you to catch only the input 'wet diaper' as a different statement.
I share you this work around as my own experience, and i hope this could help you solving or getting another perspective of how you could handle or solve your problem.

Inquirer.js: ask multiple questions if one prompt is true

I'm writing an account creator using Inquirer.js, and wanted to ask for the user's e-mail and password only if the user asked for such protection. It goes like this:
inquirer.prompt([
{type:'input', name:'username', message:'Choose an username:'},
{type:'confirm', name:'protect_ask', message:'Do you want to password-protect your game list?'},
{type:'input', name:'email', message:'E-mail (for password recovering):', when:function(answers){return answers.protect_ask}},
{type:'password', name:'password', message:'Password:', when:function(answers){return answers.protect_ask}},
{type:'password', name:'confirm_password', message:'Confirm you password:', when:function(answers){return answers.protect_ask}}
]
As you can see, I'm running the exact same when statement three times, for it verifies if the password-protection was chosen or not. I want to know if there's a more intelligent, pragmatic way to do so, this is, to run this verification without repeating the when function.
Maybe nesting the three questions would do it, but how to do so without breaking the prompt flow?

Getting arguments/parameters values from api.ai

I'm now stuck on the problem of getting user input (what user says) in my index.js. For example, the user says: please tell me if {animals} can live between temperature {x} to {y}. I want to get exact value (in string) for what animals, x and y so that I can check if it is possible in my own server. I am wondering how to do that since the entities need to map to some exact key values if I annotate these three parameters to some entities category.
The methods for ApiAiApp is very limited: https://developers.google.com/actions/reference/nodejs/ApiAiApp
And from my perspective, none of the listed methods work in this case.
Please help!
Generally API.AI entities are for some set of known values, rather than listening for any value and validating in the webhook. First, I'd identify the kinds of entities you expect to validate against. For the temperatures (x and y), I'd use API.AI's system entities. Calling getArgument() for those parameters (as explained in the previous answer) should return the exact number value.
For the animals, I'd use API.AI's developer entities. You can upload them in the Entity console using JSON or CSV. You can enable API.AI's automated expansion to allow the user to speak animals which you don't support, and then getArgument() in webhook the webhook will return the new value recognized by API.AI. You can use this to validate and respond with an appropriate message. For each animal, you can also specify synonymous names and when any of these are spoken, and getArgument() will return the canonical entity value for that animal.
Extra tip, if you expect the user might speak more than one animal, make sure to check the Is List box in the parameter section of the API.AI intent.
If "animals", "x", and "y" are defined as parameters in your Intent in API.AI, then you can use the getArgument() method defined in ApiAiApp.
So the following should work:
function tempCheck( app ){
var animals = app.getArgument('animals');
var x = app.getArgument('x');
var y = app.getArgument('y');
// Check the range and then use something like app.tell() to give a response.
}

couchdb futon document editor - can I customize the document validation part?

A VERY nice to have would be if I could edit object-literals in this editor's text-field instead of JSON expressions.
If I could replace the JSON parse with a simple eval - it will make editing sooooo much easier! (and help me design document structures for my projects soooo much more easily)
I mean, gosh!! it's not a protocol school, it's an editor's tool.
The goal of the tool is not to teach me the protocol and comment me on every petty mistake, but to help me design documents for the software.
Why must it ensist on strict JSON? Can't it live with Object Literals, and do for us the
JSON.stringify( eval(editor_textarea.value))
woulnd't that be cool? LOL :D
(yea yea, catching errors and feeding back to the user)
(and for who ever missed the difference - it is mainly in the quote marks in attribute names.
the dry strict JSON protocol require quotemarks ALWAYS, no question asked, where JS object literal require quote-marks only for attribute names that are not legal JS variable names and accepts also numbers without quotation marks)
Strict dry JSON:
{ "attribute" : "value"
, "mapmap" :
{ "map" :
{ "attr" : "sdss"
, "123" : "ss32332"
, "val" : 23323
, "456" : "ss32332"
}
}
}
Object Literal
{ attribute: "value"
, mapmap :
{ map :
{ attr : "sdss"
, 123 : "ss32332"
, val : 23323
, 456 : "ss32332"
}
}
}
Well, it won't solve me missing commas or mismatching brakets, but it does make life easier, where quote marks are a big part of the scaffold.
If you can point me to where I can change this even as patch on the futon I'll be soooOOO greatful :)
Maybe later we can integrate there an editor helper such as the cool one in github source-editor or the one in jsfiddle, that helps you indent and color things nicely.
But lets start with a simple eval.
it will make life easier... :)
It can also let me generate complicated documents using JS code without any additional test software...
Happy coding :)
P.S
If you know the answer here - you might know the answer to this question:
couchdb futon document editor - can I customize the indentation rules?
I had a quick browse, and I believe this is where you will want to add your eval:
https://github.com/apache/couchdb/blob/master/share/www/script/futon.browse.js#L911
and here:
https://github.com/apache/couchdb/blob/master/share/www/script/futon.browse.js#L902
You can edit your local couchdb instance share/www/script/futon.browse.js if you want to see live changes.

playframework create dynamic subdirectory

Is there any form to create subdirectories dynamically in playframework?, I was thinking in a common interceptor like spring, but.. how can I do it in play??
Thanks for any help
example.com/event1
example.com/event2
example.com/event3
Best way, I think, is to use the routes file. Documentation here should be self-explanatory:
http://www.playframework.org/documentation/1.2.2/routes
(see e.g. http://www.playframework.org/documentation/1.2.2/routes#syntax)
You can use the routes file, but be aware that the "name" of the folder must be a key that allows you to find the object. Usually the "key" will related to an entity, and in that case Play provides a Long id as key which is a better choice. After that key you can add some string for SEO-usability purposes.
So your routes would be something like:
example.com/1/event1
example.com/2/event2
example.com/3/event3
(or alternatively)
example.com/event/1
example.com/event/2
example.com/event/3
using a routes file like:
GET /{id}/{name} MyController.getFolder
or
GET /event/{id} MyController.getFolder
There are some questions around here (SO) on how to add the extra text to the path.

Resources