Microsoft bot framework tip: mind the mentions

Hi,

As you know, the Microsoft bot framework is mutli-channel, therefore, when users start talking to a bot from Teams, they may mention it in order to interact with your bot.

So far so good but you should mind the mention as it it sent to your bot on the form:

<at>bot name</at>

meaning that if you leave it “as is” and if you’re using LUIS behind the scenes, your bot will suddenly misunderstand a lot of things. Therefore, make sure to remove the mentions as your first coding action:

activity.Text = Regex.Replace(activity.Text, "<at>.*</at>", "", RegexOptions.IgnoreCase).Trim();

Happy coding!

Posted in Azure | Tagged | Leave a comment

Dialogue tip with the Microsoft botframework

Hi,

Admittedly, dealing with dialogues within the bot framework isn’t an easy task. We often have to struggle to make that damn thing do what we want it to do. I recently had to include a potentially rich answer during one of my dialogues.  In short, the answer to a given question could contain a video but could as well be a basic text.

Moreover, this is only one step of the whole dialogue.  As I had to fight a little bit to get it work, I thought it might be worthwhile to make a short blog post about it.  So here is the code:

[Serializable]
public class VideoAnswer : IDialog<IMessageActivity>
{
    string _link = string.Empty;
    string _text = string.Empty;
    public VideoAnswer(string text,string link)
    {
        _link = link;
        _text = text;
    }
    public async Task StartAsync(IDialogContext context)
    {

        var reply = context.MakeMessage();
        reply.Text = _text;
        if (!string.IsNullOrEmpty(_link))
        {
            VideoCard card = new VideoCard();
            card.Text = "We found a video that should help you";
            List<MediaUrl> medias = new List<MediaUrl>();
            medias.Add(new MediaUrl
            {
                Url = _link
            });
            card.Media = medias;
            reply.Attachments.Add(card.ToAttachment());
        }
        await context.PostAsync(reply);
        context.Done(reply);
    }
}

[Serializable]
public class KbDialog : IDialog<object>
{
    string _path = null;
    Guid _source = Guid.Empty;
    public KbDialog(string path,Guid source)
    { 
        _path = path;
        _source = source;
    }
    public async Task StartAsync(IDialogContext context)
    {
        context.Call(Chain.From(() =>
            Chain.Return(SPUtils.GetSharePointAnswerToQuestion(_path, _source)))
            .ContinueWith<SharePointKB, IMessageActivity>(async (ctx, answ) =>
            {
                var a = await answ;
                return new VideoAnswer(
                    a.Answer,
                    a.VideoLink);
            })
            .ContinueWith<IMessageActivity, bool>(async (ctx, act) =>
            {
                return new PromptDialog.PromptConfirm(
                    Config.Cfg.DidItHelpPrompt, Config.Cfg.DidItHelpPromptInvalidAnswer, 100);
            }
            ), OnQAComplete);
    }

    private async Task OnQAComplete(IDialogContext context, IAwaitable<bool> result)
    {
        //do your stuff
        context.Done(this);
    }
}

The idea of the above code is to get some answer from SharePoint when a user asks a question. My KB may contain a video or not. So here in the KbDialog, which is itself part of a root dialog, I start getting the answer from SharePoint and I pass it to the next step on the form of a SharePointKb object. The next step’s output is an IMessageActivity which is implemented inside of the VideoAnswer class, itself implementing the IDialog interface. Within that separate dialogue, I reply either with text-only, either with text & video but always on the form of a IMessageActivity.

Happy Bot Coding!

Posted in Azure | Tagged | Leave a comment

How to properly train Microsoft LUIS?

Hi,

I’m now working with LUIS since late December 2016 and I have detected some patterns that I think can be very useful when training your models. My observations are based on models that served different purposes. I’m not going to show you screenshots of the UI since it recently changed dramatically so I’ll focus more on the features and I guess you’ll find your way in the UI yourself.

Entities and phrase list features

IMHO, entities are the corner stone of a LUIS model. They can help LUIS pairing intents & entities together while allowing the resulting action to benefit from the captured value(s). To take a concrete example, if a user asks this question:

Where to find documentation on SharePoint

Continue reading

Posted in Azure Cognitive Services, NLP | Tagged , , | Leave a comment

SharePoint-hosted QnA versus QnA Maker, how do they compare to eachother

Hi,

I’ve a little bit tackled this topic in my previous post but I’m now going to elaborate more and come with concrete results. Before making the comparison between a SharePoint-Hosted QnA and QnA Maker, let me describe shortly what QnA Maker is all about.

QnA Maker in a nutshell

Microsoft QnA maker is free (for the time being) and allows an easy integration of existing online FAQs and/or custom set of questions/answers. The QnA is supposed to resolve similar questions to the one stored in its KB and return a relevant answer with a confidence score. QnA Maker offers an API that is very straightforward to consume. The below SWOT recaps my perception of this component for the time being: Continue reading

Posted in Azure, Azure Cognitive Services, NLP, SharePoint Online | Tagged , , , | Leave a comment

LUIS and POS-Tagging, better together to build great bots

Hi,

I recently wrote a blog post on SharePoint’s nextgen searchbox that showed how to use a bot to query SharePoint instead of using the regular searchbox. As many of you know, SharePoint’s search engine is very powerful but end users will not leverage 10% of the keyword query syntax. The idea of having a bot building such queries automatically by interpreting end users questions and “translating” them into SP queries is a great way of letting end users express their needs in natural language and let the system figure out what they want.

Continue reading

Posted in Azure, NLP | Tagged , , , | 3 Comments

Writing a #cognitive #bot that leverages #luis #azureml and #qna maker

Hi,

In this blog post, I’m going to show you how to create the boilerplate code & actions to leverage a magic set of tools, namely: the bot framework, LUIS, Azure Machine Learning and the easy-to-use QnA maker.

Before diving into the “how to”, let’s describe the fictional scenario I had in mind for this blog post. We want to write a bot that advises people about the fitness for use of products against usages. So, the bot should be able to answer questions such as: “Is SharePoint suitable for document management?”, “Should I use Yammer for social computing or should I use IBM Connections?”. Here is a demo:

Continue reading

Posted in Azure, NLP | Tagged , , , | Leave a comment

#botframework custom #webchat control secret tip

Hi,

Following an issue I reported to the GitHub repository, pay attention to use the right secret when working with the custom webchat control. Indeed, if you rebuild this control yourself, you’ll have to enable the DirectLine Channel and use this channel’s secret instead of the webchat one.

At the time of writing, using the webchat channel’s secret works (with a websocket issue depicted in my previous post and in the page targeted by the above pointer), but it seems it’s gonna stop working soon, so it’s better to know it…

Happy Coding!

Posted in Azure | Tagged , , | Leave a comment