Hello Echo Bot

We live the year of the bots. Bots are being spawned everywhere to make our lives easier and to automate things. For us developers, this is not so new since we are familiar with bots that take care of our CI, deploy our code or gently notify us when things are not perfect with our production installation.

For normal people though, this is a huge revolution. With Slack, Microsoft's BotFramework, Skype and now Facebook's bots for Messenger, the masses can now interact with their AI assistant like never before.

This means that the opportunities for creating a custom AI assistant are endless.. Let's get botting.

Getting started with BotFramework

BotFramework is one of the easiest and most promising ways to start your bot. With BotConnector your can easily connect your bot to different services, like Slack, Skype or even Email and SMS. You just implement a simple API and then BotConnector will make sure your bot will understand any of the compatible chat applications. Also, BotFramework comes with client libraries for Node.js and C#, which you could use to simplify your life. Last, but definitely not least, these client libraries contain integrations with LUIS, Micrsoft's Language Understanding Intelligent Service which powers Cortana and which you can use in order to make your bot smarter, or even train it to reply to your intents!

For this tutorial, we're going to use BotConnector's Node.js client library with a restify-enabled Node.js project.

Creating your first bot from our ready-made Node.js template

In order to help you get started really fast with BotFramework in SourceLair, we've prepared a ready-made Blueprint that will bootstrap a Node.js project with everything you need to get started. You can find the Blueprint here.

This Blueprint will do the following things for you:

  1. Create a new SourceLair Node.js project
  2. Clone our template from GitHub
  3. Install the needed NPM dependencies
  4. Expose your application to your public URL, so that you can view it in your browser

In order to access your bot, you'll need your Public URL. Hit the eye-like icon in the sidebar and copy your URL as you'll need it during the next step.

Registering your bot to BotFramework's website

In order for everything to work, you'll need to register a new bot. First, sign in with your Microsoft account and authenticate BotFramework. Then, fill the required fields - in the In the Endpoint, fill in your public URL, after appending /v1/messages at the end, while in the Bot Privacy URL add just your public URL or another page where in the future you'll add your privacy policy. Make sure you paste the HTTPS version, since otherwise authentication will be problematic. After you have registered your bot, keep your Primary app secret value, we're going to need it shortly.

Setting up the web chat for testing

BotFramework also includes a handy iframe code which you could use in order to easily and quickly test your Bot. Open the Web Chat settings by clicking edit, generate a new secret and keep it for the awesome next step.

Giving life to your Bot

Now that you're done with your BotFramework setup, there's just one last step left - connect your Bot to BotFramework and enjoy it! Move back to your SourceLair project, create a new file named .env - which will be automatically loaded by your bot - and copy paste the following values - also available in the .env.example file for reference.


These are the values that you acquired during the previous steps. In order to make sure these new values are loaded into our application, we need to restart our server. To do so, open the Command palette using Ctrl + Shift + P and use the "Restart server" command.

Testing your bot

Bot testing is difficult, since your bot needs to live in the internet. That's no problem in our case though, since your SourceLair projects live online and they're always accessible using your public URL. All you have to do is open your public URL and the Web Chat will be there waiting for you. Try to send something to your bot and watch it reply. Beware though, it only knows basic stuff yet.

Add more queues to your bot

Now that you have verified that your bot is working, you only have to save your changes and your bot will automatically reload to answer all your questions. Let's - for example - teach your bot to track IP address location. For this example, we'll use the ip-api.com service.

Let's install the request package, type in your terminal:

npm install --save request

and import it in our app.js:

var request = require('request')

Now that we have request, let's add one more queue. First, open the app.js file (either using the file explorer, or quick open with Ctrl + Shift + O or Cmd on a mac) and add a new match:

.matches('^ip', builder.DialogAction.beginDialog('/ip'))

and now enter the new dialog:

helloBot.add('/ip', [
    function(session) {
        builder.Prompts.text(session, 'Which IP you\'d like to track?');
    function(session, results) {
        var ip = results.response;
        request('http://ip-api.com/json/' + ip, function(error, response, body) {
            if (error) {
                session.send('Ooops, there was an error with your request "%s"', error);
            if (response.statusCode != 200) {
                session.send('Ooops, we got a wrong status code "%s"', response.statusCode);

            try {
                body = JSON.parse(body);
            } catch(err) {
                session.send('Hmmm, the server responded with a wrong resopnse, interesting...');

            if (body.status !== 'success') {
                session.send('There\'s something wrong here, does this help? "%s"', body.message);

            session.send('Hooray, the IP is located at %s, %s', body.city, body.country);

That's it, ask your bot about your IP of choice now!

Deploy your bot

In SourceLair, we support different deployment flows, from using our Heroku or git-ftp integrations, to any deployment service using plain Git. Choose your favorite and present your bot to the word!

Wrap up

Congrats on your first bot. Let this be the start of an awesome new AI. We hope you'll enjoy playing with it as much as we do. Shoot us an email with your bot's public URL at support@sourcelair.com and we might have a little surprise for you.

You can also go back to BotFramework and integrate your bot with your favorite service - it's that easy!