Sentiment Analyzer – Custom Middleware for Bot Framework

I have been stating these at multiple forums that Microsoft Bot Framework (MBF) is currently the richest in terms of features, supported channels and flexibility. With MBF, you can not just create one basic customer service chat bot, but you can do much more than this, from sending an email to pushing a financial transaction after a successful authentication.

With the advent of SDK 4, the number of features have been doubled. One of which is middleware capability and the ease of implementing it.

Should you wish to log any specific events, translate the requests to some other format (or language) or do some sentimental analysis on your customer’s responses, middleware is the suitable option for all these tasks.

I will not be deep diving into the technical part as you could easily check the official documentation on this. However, I am going to highlight one of the important business use-cases which can be implemented to improve your customer service.

Sentimental Analytics

Let’s say you’re an owner of a delivery / shipment business. Customer satisfaction is your KPI. You want to calculate the customer satisfaction index and analyze the responses which can help you improve your service.

Using the middleware capability, you can intercept the customer responses and generate the satisfaction index / report for your perusal. Not only this, you can also opt for short-circuit routing or fall-back processing in your bot.

For the sake of simplicity, I have developed a small sample bot on SDK 4 (ASP.NET Core 2.0) with the memory state management (although it’s just for testing purpose).

 public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton(configuration);
            services.AddBot(options =>
            {
                options.CredentialProvider = new ConfigurationCredentialProvider(configuration);
                options.Middleware.Add(new SemanticLayer());
                IStorage dataStore = new MemoryStorage();
                options.Middleware.Add(new UserState(dataStore));
            });
        }

This sample will intercept all the customer responses and will add it to the list of responses. As the main purpose of this to show you how effective and simple is to add middleware, therefore, I have not put any criteria as when it should calculate the satisfaction index but you can decide as per your business needs.

GDPR alert! If you’re capturing any information which is related to customer, you should allow him / her to delete it.

As usual, the code is up at github repository and waiting for your contribution. Happy coding!

Leave a comment