Custom BotFramework Intent Service Implementation

Developing a chatbot with language understanding capabilities is a huge leap from basic pattern recognition on the input to match to specific commands.

If you have a botframework chatbot, you’re currently limited to using LUIS as your NLP (Natural Language Processing) provider via the various Luis classes: LuisDialog, LuisModelAttribute, and LuisService.

If you’re trying to compare alternative NLP services, such as kitt.ai or wit.ai or even Alexa, then implementing support for another NLP service in Botframework for this can be a bit tricky.

In this article I’ll show you one approach to decoupling your botframework bot from a specific NLP solution.

Continue reading

Sending Proactive Botframework Messages

Having a botframework chatbot up and running and responding to user messages is one thing, but how can you send a new message to bring the user back into the conversation if they haven’t just sent a new message for you to reply to?

The botframework documentation and other tutorials will point you towards using Azure Functions and the new ActivityType.Trigger to handle this which, although being a great use case for Azure Functions, make the underlying implementation harder to understand. It also means you couldn’t easily implement this on AWS, for example.

In this article I’ll show you how to easily implement Proactive Botframework Messaging just using BotFramework fundamentals.

Continue reading

Connecting Alexa to a Botframework Chatbot

In the previous article we dissected an Alexa Skill down to the JSON request and Response, and pointed it to an HTTPS endpoint (your laptop) to get a basic end to end Skill working.

In this article I’ll show you how to link that skill into your botframework chatbot.

Creating a botframework reply

Let’s dip back into BotFramework in order to create something that can respond to the incoming request.

Calculating a Chinese Zodiac animal based on the year is really simple; just get the remainder from dividing by 12 and apply a switch:

Continue reading

Introduction to Alexa Skills: From Zero to Echo

The rise of the conversational interface shows no signs of slowing down; chatbots are the new apps, Siri is getting old already, and although it’s still awkward to say “Ok Google” at your watch or “hey cortana” to your phone, somehow we’re happy to ask “Alexa” for the news, weather, or to play something by Bruno Mars.

The Amazon Echo looks like the first generation of a socially acceptable, almost natural, voice controlled conversational interface.

It’s that first step towards the Star Trek computer; you can’t quite say “Alexa, locate Commander Data” (although you can ask her to beam you up, and for earl grey tea, hot) but you can get a decent answer to “Alexa, where is my phone?” (assuming you’ve installed the relevant app).

All of the tutorials out there for developing your own Alexa Skill require a lot of digging around on Amazon Web Services, learning some nodejs*, and getting knee deep in lambdas (Amazon’s Functions as a Service/Server less architecture solution).

In this article I’ll show you how to easily understand how to develop your own Alexa Skill with just your laptop and a json file

* Actually, AWS Lambdas now support C# too

Continue reading

Receiving files sent to your botframework chatbot

We’ve already looked at how a botframework bot receives messages, and even how to save those messages.

In this article I’ll show you how to handle files that are sent to your botframework chatbot.

When a user interacts with your bot, unless they’re responding to a prompt, they will cause the Message controller’s Post method to fire with an activity.

This will send a message through to your underlying IDialog or LuisDialog implementation.

MessageReceived

The method that receives the message will have the signature (though the parameter names and method name could be different):

Continue reading

Example for Saving Botframework Messages to Sql Server

In my previous article I showed how to override various methods within botframework such that you could run some logic to save your bot’s dialogues.

In this article I’ll give an example implementation of the IMessageRepository Interface.

IMessageRepository and IMessageActivity

In the last article I introduced an IMessageRepository concept in order to show how it would be possible to hook into botframework’s various MessageReceived methods, and create our own version of PostAsync to save outgoing messages also.

Saving both incoming and outgoing messages passed an IMessageActivity object (“context”) to a MessageRepositorys AddMessageAsync method.

Continue reading

Transcribing messages in BotFramework

Now that you’ve deployed your well structured, exception handling, language understanding chatbot, how do you know just what people are saying to it?

Sure, you could copy and paste some logging code all over the place, but there must be a cleaner way.

In this article I’ll show you a few simple tricks to be able to save each message going to and from your botframework chatbot.

IDialog

Let’s start off by saving messages going to any dialog that implements IDialog<T>.

In order to implement IDialog<T> you only need to implement the StartAsync method; however, this isn’t much use on its own, so let’s get the dialog into a conversation loop by adding in a MessageReceivedAsync method and calling that from StartAsync and from itself:

Continue reading

LDNBotFramework Meetup #2 Retrospective: From Zero to Echo via BotFramework

I had an awesome time presenting my session at the second LDNBotframework meetup!

This time I ordered the correct amount of pizza, and let people loose on it at the right time; so no fridge full of pizza for breakfast the next day!

From Zero to Echo via BotFramework

LDNBotFramework #2 - From Zero to Echo via BotFramework

Tight deadline

Having scheduled this session weeks ago, unfortunately my preferred presenters were not able to make it; as such I had just over a week to decide what to do about the already scheduled meetup: should I cancel it and lose momentum, or should I do a session myself?

Continue reading

BotFramework: Avoiding have to make everything [Serializable]

In the last article I touched on how IoC is used within botframework using Autofac.

If you’re comfortable with IoC, you probably started to enhance your dialogs using constructor injection, so that you can put your conversation logic outside of your entry point and just start coding without needing an implementation to exist yet, e.g.,

[Serializable]
public class ResolvingDialog : IDialog<object>
{
    private readonly IMessageRepository _messageRepository;

    public ResolvingDialog(IMessageRepository messageRepository)
    {
        _messageRepository = messageRepository;
    }

    public async Task StartAsync(IDialogContext context)
    {
        await context.PostAsync($"Hi!");
        context.Wait(MessageReceivedAsync);
    }

    public async Task MessageReceivedAsync(IDialogContext context, IAwaitable<IMessageActivity> argument)
    {
        var message = await argument;
        await _messageRepository.SaveMessage(message);

        await context.PostAsync($"working now");
        context.Wait(MessageReceivedAsync);
    }
}

Continue reading

BotFramework Exception Wrapping and Custom Error Message

During your time building and debugging your botframework chatbot, you’ve probably already come across the annoyance of seeing a huge error message with a ridiculous stack trace that doesn’t seem to relate to your error, or even just a plain old HTTP 500 and big red exclamation mark..

emulator red exclamation mark

Perhaps you’ve deployed to a production environment and are stuck with the stock error message:

Sorry, my bot code is having an issue

In this article I’ll show you how to 1) display useful exception information, and 2) override the default error message sent to the user

Continue reading