Search code examples
c#azurebotframeworkcortana

Bot Framework: Enable PromptDialog.Text to be spoken by cortana


I need to get Cortana to read all my prompts, so far I managed to get it to speak simple phrases like in this example:

[LuisIntent("Thanks")]
public async Task Thanks(IDialogContext context, IAwaitable<IMessageActivity> activity, LuisResult result)
{

    await context.SayAsync(text: Phrases.YOURE_WELCOME, speak: Phrases.YOURE_WELCOME);
    context.Wait(this.MessageReceived);

}

But I can't do this on PromptDialogs.Text I have this code:

private async Task OnCustomerSet(IDialogContext context, IAwaitable<string> result)
{

    string name = await result;
    PromptDialog.Text(context, OnNIFSet, Phrases.ASK_CUSTOMER_NIF);

}

How can I get Cortana to also speak this prompt?

Thanks.


Solution

  • Update: I have submitted a pull request to have this added to the C# SDK and upon the next release it will be part of the bot.builder package. The current release is 3.15.2.2 (at the time of writing this) so anything higher than that should have it. it will be in the SDK so you will not have to use the method in this answer.

    After looking deeper into this, I was able to come up with a solution that will work without changes to the SDK and I have confirmed this is already working in node out of the box. I will add the changes in a pull request still, but this should help you for now.

    You can make a class that will inherit from PromptDialog and make a constructor for a PromptDialog.text like this:

    public class PromptDialogTextSpeak:PromptDialog
    {
        public static void Text(IDialogContext context, ResumeAfter<string> resume, IPromptOptions<string> promptOptions)
        {
            var child = new PromptString(promptOptions);
            context.Call<string>(child, resume);
        }
    }
    

    I was able to get this working with a simple prompt such as:

     var text = "this is a prompt";
    PromptOptions<string> qwerty = new PromptOptions<string>(text, speak: text);
    PromptDialogTextSpeak.Text(context, AfterPrompt, qwerty);