Building a Chatbot Using Botkit

Cindy Kei
3 min readNov 28, 2020
Src: Hubtype

Nowadays, when you log on to any website, chances are that you’ll come across a chatbot. Chatbots are widely used across web applications in order to perform tasks — such as greeting customers and providing answers to frequently asked questions — that were once relegated to human beings.

Today’s chatbots are surprisingly complex, intelligent, and efficient, making them a no-brainer for most websites. While the AI and machine learning that goes in to chatbots are increasingly complicated, the task of building and customizing your own chatbot has become easier than ever. Today, there exists many tools for people to implement their own chatbots and tweak them to accomplish tasks that fit their own needs.

One such tool for building a chatbot is Botkit, an “open source developer tool for building chat bots, apps, and custom integrations for major messaging platforms”. Botkit is one of many such tools and resources that make up the Microsoft Bot Framework. The cool thing about Botkit is that it takes care of most of the complicated, mind-boggling technical details, freeing up time for developers to build fun, useful features for their bot.

Getting Started

To get started with Botkit, you should first install the Botkit command line tool by running npm install -g yo generator-botkit . This installs the Botkit starter kit globally. Alternately, you can also just add Botkit into an existing project by running npm install — save botkit.

From here, you then have to add Botkit to your application. Within your bot.js file, which serves as your main file, require Botkit and initialize a new instance of Botkit:

const { Botkit } = require('botkit');const controller = new Botkit(MY_CONFIGURATION);

Botkit Functions

Next comes the fun part — customizing the chatbot to make it your own. Botkit comes with many useful functions that are easy to implement, such as hears(), ask(), and reply(). To start customizing your chatbot, you can tell Botkit what words to look out for and how to respond.

If, for example, you wanted to tell your chatbot to listen for the word “hello” and then reply with a specific message once it does hear the key word, you would include the below code:

You can also direct chatbot to respond to events, such as when the page loads, when a button is clicked, or when someone joins a channel. This is done using the on() function, like so:

To learn more about Botkit and how you can use it to begin building your own chatbot, I’d encourage you to look through Botkit’s documentation, which does a good job of running through the core features and how you can use them in your own bot.

--

--

Cindy Kei

Fullstack Software Engineer based in NYC. Passionate about creating social change and making a difference through innovative, powerful technologies.