garypretty / botframework

Microsoft Bot Framework helpers and additional dialogs
MIT License
60 stars 51 forks source link

How to extract List BestMatch(new string[] { "Hi", "Hi There", "Hello... to a resource File (.resx) #5

Closed didaskein closed 7 years ago

didaskein commented 7 years ago

Hi Gary,

Thank you for your nice projet ! very usefull ;) Do you have an idea how to get the list of strings ( BestMatch(new string[] { "Hi", "Hi There", "Hello.. ) from multiple resources Files (.resx) (ex FR, US,...) we can imagine having a row :

BestMatchHelloKeyRow : Hi|Hi There|Hello|... in the US.resx file

BestMatchHelloKeyRow : Bonjour|Salut|... in the FR.resx file

If you have an idea ;) Thanks in advance,

garypretty commented 7 years ago

Hi. Thanks for your question, this is an interesting scenario.

To support you I have updated the project to support specifying a list of choices using a delimited string so that you can grab it from a resource file. For example,

[BestMatch("bye|bye bye|got to go|see you later|laters|adios", listDelimiter: '|')] public async Task HandleGoodbye(IDialogContext context, string messageText) { await context.PostAsync("Bye. Looking forward to our next awesome conversation already.");     context.Wait(MessageReceived); }

I have pushed the changes into this repo and I will update the NuGet package later today, but it will take a few hours until it is available.

Does that help?

Thanks

Gary

didaskein commented 7 years ago

Hi, Thanks Gary,

The issue is that at the compilation time, VS don't know which language to use. I must be dynamic with the user's language. If i add a Resource.MyKeyItem inside the Attribute, i have a compilation error that you can see below image

I think, we need to provide the list for each function in a constructor of GreetingsDialog but i don't know how to to this.

Thx,

garypretty commented 7 years ago

Ah ok. I see your issue. I think one option here would be to pass in a locale, e.g. en-GB into the constructor and then you can use this within your dialog to pick the correct resource string for each handler (using the new string param I added). Does that make sense and would that work for you?

didaskein commented 7 years ago

Hi Gary,

It is working perfectly ! :) Thank you

image

image

And a little helper to add Random in the answers ;) image

image

++

garypretty commented 7 years ago

That's fantastic news. So glad you found it useful. Good luck with your bot building. FYI I have added a new dialog to the repo and NuGet. QnAMakerDialog - check my blog post out at www.garypretty.co.uk and hopefully it might be useful.