How to ask open questions in bot framework? - botframework

I am building a chat bot using Bot Framework, C# Bot Builder and FormFlow (with FieldRelfector).
At one step I need to ask an open question to the user like "Add any other relevant information", where I just want to collect some text and store it for later usage.
I tried to define the variable as String:
[Prompt("Add any other relevant information")]
public string OpenText;
In the form chain I have:
.Field(new FieldReflector<MyForm>(nameof(OpenText))
.SetType(null)
.SetActive(state => !state.Finished()))
but that doesn't help, whatever I type the bot answers:
"blah blah" is not a open text option.
How to handle this?

Is there any reason you are using a FieldReflector for that property? I would suggest just defining a normal field for that property (you can have a form with fields defined with FieldReflector and fields defined just with Field).
Just use:
.Field(nameof(MyForm.OpenText), state => !state.Finished())
If there is a reason to use FieldReflector, please update the post with the entire form definition.

Related

How do I use capture groups in Regular Expressions in Bot Composer

I am attempting to build a Microsoft Teams bot using the Bot Framework Composer. What I would like to do is create an integration with ServiceNow. The goal would be that if anyone posts a record number (ex. REQ0123456, INC0123456, KB0123456) into the group or direct chat (with the bot), the bot would look up that record and provide a card or a short summary of the record to the chat.
To avoid creating a completely separate intent for each record type, I was hoping to use RegEx to gather the match into 2 capture groups; one for the tbl_code and one for the number.
Here is the entry for the user input:
> add some example phrases to trigger this intent:
- look up {conversation.sn_record.tbl_code=REQ}{conversation.sn_record.number=0123456}
- lookup {conversation.sn_record.tbl_code=REQ}{conversation.sn_record.number=0123456}
- {conversation.sn_record.tbl_code=REQ}{conversation.sn_record.number=0123456}
- lu {conversation.sn_record.tbl_code=REQ}{conversation.sn_record.number=0123456}
> entity definitions:
# regex sn_record tbl_code, number = /([a-z]{2,4})([0-9]{7})/mi
The Issue I'm Having
I don't know how to get the values back from the individual capture groups. I would like to have them separate so that I can determine which table needs to be queried. I could probably just use the entire match and the search API in ServiceNow for the whole record string, but I would still like to know how to use capture group values.
I'm currently using turn.recognized.text, but I don't think this is the best method for what I'm looking to do. This returns the entire regex match.
I'm very new to this framework, so please be gentle. :) Let me know if there is more information I can provide.
Thanks all.
Best Regards,
Josh
I was able to figure this one out using the examples in the ToDosSample bot.
The answer was to use named capture groups and then add them to a dialog property to use in the corresponding dialog.
For reference here are the changes I had to make:
New Regex
(?<sn_record>(?<tbl_code>[a-z]{2,4})(?<numbers>[0-9]{7}))
New Dialog Properties
dialog.sn_record = #sn_record
dialog.sn_tbl_code = #tbl_code
dialog.sn_numbers = #numbers
New response
- Okay, looking up ${dialog.sn_tbl_code}${dialog.sn_numbers}

Describe enums in Bot Framework & FormFlow with JSON Schema

I'd like to create a Bot using the FormFlow with JSON Schema approach. However, I need a bit more flexibility for displaying the answer options, since those need to be whole sentences and not only single words.
Is it possible to extend the enums specified inside the JSON file with descriptions that will be offered as options instead of the enum itself?
As I understand this is possible in code by using the Describe-Attribute.
You could use the "Define" property with custom script. The Sandwich Bot example is doing it this way (from json-schema-example):
"Define": "field.SetType(null).AddDescription(\"cookie\", DynamicSandwich.FreeCookie).AddTerms(\"cookie\", Language.GenerateTerms(DynamicSandwich.FreeCookie, 2)).AddDescription(\"drink\", DynamicSandwich.FreeDrink).AddTerms(\"drink\", Language.GenerateTerms(DynamicSandwich.FreeDrink, 2)); return true;",

MS BotBuilder : How can I set a combination of an intent and an entity to trigger a dialog?

I'm using the MS BotBuilder to create a bot language understanding bot. I have a dialog readProfile that's triggered on Read intent that is trained on LUIS.
bot.dialog('readProfile', [
function (session, args) {
var entities = args.intent.entities;
console.log("entities : ", entities)
]).triggerAction({
matches: 'Read'
}).cancelAction('cancelReadProfile', "Ok.", {
matches: /^(cancel|nevermind)/i
});
The LUIS model is trained to recognise entities like Profile and others so I do get the entity in console.
However, I wish to trigger the dialog only if the entity recognised is Profile. I can set some logic to work only when the entity in args is Profile but wondering if there's a builtin / more elegant way to do this.
Thanks for your input.
I think using a logic statement in the first step of the readProfile dialog is the best way to do this. If no Profile entity is found, end the dialog with a message like "It looks like you're trying to read a profile, but didn't I couldn't figure out what profile you're trying to read." This has the advantage of giving the user some feedback about their action and helping them figure out what they need to fix.
You could try to train the Luis model to have a strong correlation between having a Profile entity and the Read intent. Enter a few utterances that are really close to the Read intent but don't include a Profile and mark them with the None intent. That doesn't guarantee that it won't ever match a Read intent without a Profile, though, so I'd still recommend the above step.

Is it Possible to put image in Prompt using FormFlow in Microsofr Bot Framework?

I want to put an image in one prompt because my requirement is like that.So,Is there any way to put an image one prompt?I am using FormFlow concept to create guided bot.
[Prompt("Nice to meet you. Can I know name of your Organization? {||}")]
String organisation;
1.Nice to meet you.
2.Can I know name of your Organisation?
Above is sample of my Prompt for 'Organisation' Field.
I want to put an image before my first statement that is 'Nice to meet you'.
So,How can I do that?
Try sending cards with attachments.
Here are some samples for NodeJS and C#

Convert Order into custom entity 'X'

Issue is :
I have one system Entity called 'Order' and another custom entity 'X'. I am looking for some kind of same functionality as available on Quote called 'Convert into Order'. I want the same functionality on Order form that there will be some button on it and when i click on it, it will create instance of entity 'X' and not only this, it will also transfer all the mapping attributes of Order and 'X', on the 'X' form.
Can any one share his experience or step to implement this?
Many thanks.
You would have to use JavaScript and call CRM web services on click of new button.
So you don't have to map your attributes of your entities in JavaScript, you could use InitializeFromRequest to achieve same result. I have used this way to programmatically qualify/disqualify leads and convert them to contact, account and opportunities.
There is a nice sample code for this on CodePlex:
http://www.codeproject.com/KB/cs/CRM_30___EntityMoniker.aspx
Please note, this code has a bug. Check Ronalds post for quick fix:
http://ronaldlemmen.blogspot.com/2008/09/convert-lead-to-contact-account-andor.html
Yuo could do this using an on demand triggered workflow. just create a workflow targting the order entity, have the first step create a new entity X by copying the valuses from the passed in order entity.
if you want the option to do this to show under the more actions menu instead of teh workflows one then you can edit the isv.config file.

Resources