This is part 2 in a series of blogs about Force.comSkype Bots and the Microsoft Bot Framework. In the previous blog in this series, I explained how my first successful integration between Skype and had several downsides. The most annoying one: A local server sad In this blog I will tell you about the evolution of my Skype bot to version 2; the cloud edition.

Bot Framework

Searching for better ways to have Salesforce communicate with Skype and Skype with the users, I quickly ran into the Microsoft Bot Framework. The framework was at version 1 at that time, but has evolved to version 3 in the meanwhile. Version 3 will be on the agenda next time. In this blog I will talk about the older version, which was the only one available at this time.

The Bot Framework allows developers to create a central communication hub, with 1 endpoint, to communicate across many different channels (e.g. Skype, Facebook, Webchat, Telegram, Slack etc.). The endpoint configured in the framework hosts the bot's logic, built on top of an SDK available in Node.js and C#. Since my plan was to host the bot's logic on Heroku, I decided to build my bots with Node.js, a language I had wanted to learn for some time now. To get started with version 2 of my Skype Bot through this Bot Framework, several steps were required in preparation.

  1. Registering an application in the Microsoft portal.
  2. Creation of a Skype Bot in the Skype Developer Portal, using the Application Id from 1)
  3. Creation of a Bot Framework account in the Bot Framework Portal
  4. Connecting the Skype Bot from 2) to the framework account from 3). This was done by configuring the Skype bot's tokens from 2) in the Bot framework back-end
  5. Development of a BotConnectorBot in Node.js, hosted on Heroku. The endpoint had to be configured on 3)

In theory, this would result in an architecture as displayed below (click to enlarge).

Unfortunately, I ran into several problems trying to get the above to work. Messages from Skype would not get through to my Heroku-hosted BotConnectorBot, even while tests in the Bot emulator worked just fine. This whole technology was (and still is) in preview. As a consequence, not a lot of content is yet available on the internet. This made Google searches for answers (to the abundant error messages) unsuccessful. Since the SDK's botbuilder also allowed development of a dedicated SkypeBot (and Skype was my only requirement), I decided to cut out the Bot Framework for this moment. This simplified the challenge to just communicating with Skype directly.

Even this did not solve all my trouble. Although Skype messages now got through to Heroku, where my SkypeBot was running, the body of the messages appeared to get lost in the process. It seemed like the Heroku router somehow stripped if off and passed only headers to my Node.js SkypeBot. The best answer my searches on Google had come up with, was the suggestion to host the bot on Microsoft Azure. After several days of fruitless attempts to debug the problem myself, my impatience finally got the best of me. Reluctantly I signed up on Azure and deployed the Node.js bot there. And, to my great joy ... it worked!

Since I am professionally inclined (even biased) to use Heroku, the move to Azure almost felt like high treason. But finally having a working bot, after days of frustration, was enough to soothe this feeling. In fact, I found out that Azure is a very nice cloud platform, very much similar to Heroku, but with a stronger administration UI, resulting in a lot less command-lining.

Skype Bot: Take two

Now that the proof-of-concept for the cloud version of the bot was working, it was time to dive into the SDK documentation and familiarize myself with the concept of (Skype) Dialogs. Although the dialog principle applies to other channels as well, from now on I will talk specifically about Skype dialogs.

A dialog is the control mechanism used, by the bot, in a conversation between a Skype user and the Skype bot. A conversation can be initiated by either side. The user can initiate the conversation by sending a message to the bot, the bot will respond with either a reply message, or by starting a dialog. A dialog started by the bot, can guide the user through question and answer session, also referred to as a "waterfall". A simple dialog could look like this, for example:

Skype User: Hi
Skype Bot: Hi, what's your name?
Skype user: Harm
Skype Bot: Hello Harm!

In the example, the bot starts the dialog in its first message to the user, asking for the user's name. While interacting with the user, the bot can collect data (like a name in the example), which will be available for use in the current or future conversation(s). As you will have guessed, storing the data in a database, for example in, is not that hard with Node.js. Likewise, querying Salesforce data during the conversation is also very easy. For this purpose I used JSforce. This is an easy to use Node.js library for communication with several of the Salesforce API's.

The Node.js bot framework supports several types of dialogs. For my purpose, a Travian bot, I settled for a CommandDialog. CommandDialogs allow the bot to examine the user's messages with regular expressions and respond with a distinct dialog when an expected pattern is matched. Once the user enters a dialog, the conversation can be guided by the bot. However, until this time, the approach requires the user to type commands accurately for the bot to be able to start the correct dialog. A severe usability penalty. LuisDialogs solve this problem, by implementing a model. I will discuss them in a subsequent blog.

After having transfered the logic of the old Java bot to the new Node.js edition, the resulting orchestration looked something like this (click to enlarge).

The bot was now nicely hosted in the cloud, it was 100% stable and the need for a noisy local server had vanished! Mission was accomplished. At least for the Travian bot ....

The botframework and all its practical possibilities had to be explored further. Since I got the hang of Node.js and the Botbuilder now, it was time to look beyond the hobby botting. In the next part, I will tell you about the next phase of my journey: AI and Skype integrations with the Service Cloud and Sales Cloud.


Add comment

Security code