Microsoft offers great bot development framework (http://dev.botframework.com) for bot developers. The key features are:
- Write once, publish to multiple chat platform (skype, facebook, skype for business, slack, sms, email, etc.)
- Provide dialog support so that developers easily implement conversation flow without managing the conversation.
- C#/Node.js SDK
- IDE and simulator support
- Native integration with Microsoft Cognitive services.
The best part, for me at least, is the dialog support. If the bot only does single Q and A, then it is not much different from search experience. But with dialog support, bot remembers previous conversations and use multiple input to execute business logic to achieve something greater.
The issue? Microsoft Bot Framework do not support LINE platform atm.
Yes, there is a solution. Microsoft Bot Framework have channel called “Direct Line”, which let developer connect whatever they want. So only we need is a connector which uses it. We implement the connector by using C# and it is super easy to set up.
Who want to use this?
There are two types of audience for this solution.
- You are bot developer using Microsoft Bot Framework who want to connect to LINE.
- You are LINE bot developer who wants to utilize Microsoft Bot Framework
- Microsoft Bot Framework bot application. I assume you already have one anyway. If you don’t have it at the moment, you can grab samples from GitHub.
- Visual Studio 2017
- Azure Subscription
- LINE developer account and one bot setup
For LINE developer account and bot setup, please refer to Setup LINE section of my previous article
Let’s start from Bot Framework side. I am using sample Pizza bot application for my test here.
1. Go to http://dev.botframework.com and select your registered bot and select “Channels”.
2. Click “Direct Line” in “Add a channel”.
3. Copy one of Secret Keys and click “Done”.
To track several items, we use Azure Storage.
1. Go to Azure Portal. http://portal.azure.com
2. Create a storage account. I created one in the same resource as my bot application lives.
3. Move to the storage account you created, and click “Access keys”.
4. Copy one of the CONNECTION STRING.
1. Go to LINE Developer portal (http://developers.line.me) and select your LINE bot.
2. Copy Channel Secret.
3. Issue and copy channel access token.
4. Keep the window open as we will update webhook URL later.
Next, setup connector.
1. Open Visual Studio 2017, go to tools | Extensions and Updates.
2. Search “LINE Bot C# Template from Online and install it. Restart the VS if necessary.
3. From project, select “LineWithBotFrameworkApplication” template and create the project.
4. Open web.config and fill parameters.
5 For NuGet packages, update as you need.
6. Right click the project and click “Publish”.
7. Publish to Azure Web Apps, and copy the URL.
8. Go back to LINE developer portal and update Webhook URL. Do not forget to add “/api/linebot” at the end.
Test the bot
Everything up and running, so let’s test.
1. From your LINE client, add the bot by scanning QR code in LINE developer portal page.
2. send “hi” and then follow it. Oh I just realized that I am not using pizza bot sample but using sandwich sample. Anyway it doesn’t matter much here.
How this works
It’s very simple. The connector receives the message from LINE Platform, and redirect it to Bot Framework via direct line. Then it receives the results back from Bot Framework, then redirect to LINE Platform. It just changes the format in between.
Anyway hope you enjoy hooking your Bot Framework application to LINE