Develop a Botkit Bot
Botkit is the leading developer tool for building chat bots, apps and custom integrations for major messaging platforms.
Botkit offers everything you need to design, build and operate an app:
In addition, Botkit works with all the NLP services (like Microsoft LUIS and IBM Watson), it can use any type of database, and runs on almost any hosting platform.

Botkit Integration Architecture

Botkit Quick Start Guide

Botkit is a Node.js module and works with Node and npm.
The fastest way to start with Botkit is using botkit-starter-rocketchat:

Get the Botkit Bot Boilerplate Code

  • Open up terminal in the directory you wish to develop your bot in and run the following commands to fetch from our repository and install all dependencies
1
git clone https://github.com/RocketChat/botkit-starter-rocketchat
2
cd botkit-starter-rocketchat/
3
npm install
Copied!
  • Next, create a .env file in the working directory if it doesn't exist and fill it with the following configurations. Rename to match your details
1
# Environment Config
2
3
# store your secrets and config variables in here
4
# only invited collaborators will be able to see your .env values
5
# reference these in your code with process.env.SECRET
6
7
# Specify a Botkit Studio token so your bot can access cloud-hosted content and features
8
# Get one here: https://studio.botkit.ai/
9
studio_token=''
10
11
# Specify your instance of RocketChat
12
ROCKETCHAT_URL='http://localhost:3000'
13
14
# Specify the bot user name in RocketChat
15
ROCKETCHAT_USER='botkit.user'
16
17
# Specify the bot user password in RocketChat
18
ROCKETCHAT_PASSWORD='botkit'
19
20
# Specify with true or false the usage of SSL
21
ROCKETCHAT_USE_SSL=false
22
23
# Specify the list of public rooms that the bot will be added.
24
# Add channels like this: 'GENERAL, channel2, ...'
25
ROCKETCHAT_ROOM='GENERAL'
26
27
# Specify the channels that the bot only can answer when mentioned.
28
# The bot will answer all messages for default, add channels like this:
29
# 'GENERAL, channel2, ...'
30
MENTION_ROOMS='GENERAL'
31
32
# Specify if the bot it's allowed to answer direct messages
33
RESPOND_TO_DM=true
34
35
# Specify if the bot it's allowed to answer live chat messages
36
RESPOND_TO_LIVECHAT=true
37
38
# Specify if the bot it's allowed to answer edited messages
39
RESPOND_TO_EDITED=true
40
41
# Enable learning mode, a set of features
42
# that allow your bot to update itself using Botkit Studio's API
43
LEARNING_MODE=true
44
Copied!
  • When the configuration is done, run the following script to start the bot
1
npm start
Copied!
  • After executing the command, botkit will try to connect to the Rocket.Chat instance and then will listen to messages in general room
1
$ npm start
2
3
> [email protected] start C:\Users\COMPUTER^CARE\Desktop\RocketChat\Bots\botkit-starter-rocketchat
4
> node bot.js
5
6
~~~~~~~~~~
7
Botkit Studio Starter Kit
8
You problably forgot to update your environment variables
9
Get a Botkit Studio token here: https://studio.botkit.ai/
10
~~~~~~~~~~
11
Initializing Botkit v0.6.16
12
info: ** No persistent storage method specified! Data may be lost when process shuts down.
13
debug: Setting up a handler for spawned
14
debug: Setting up a handler for heard_trigger
15
debug: Setting up a handler for command_triggered
16
debug: Setting up a handler for remote_command_end
17
debug: Setting up a handler for direct_message
18
debug: Setting up a handler for live_chat
19
debug: Setting up a handler for channel
20
debug: Setting up a handler for private_channel
21
[connect] Connecting {
22
username: 'botkit.user',
23
password: '12345',
24
ldap: false,
25
host: 'localhost:3000',
26
useSsl: false,
27
timeout: 20000,
28
rooms: [ 'GENERAL' ],
29
allPublic: false,
30
dm: true,
31
livechat: true,
32
edited: true,
33
integrationId: 'js.SDK',
34
roomCacheMaxSize: 10,
35
roomCacheMaxAge: 300000,
36
dmCacheMaxSize: 10,
37
dmCacheMaxAge: 100000
38
}
39
debug: Setting up a handler for message_received
40
debug: Setting up a handler for message_received
41
debug: Setting up a handler for message_received
42
debug: Setting up a handler for sticker_received
43
debug: Setting up a handler for image_received
44
debug: Setting up a handler for audio_received
45
debug: Setting up a handler for heard_trigger
46
debug: Setting up a handler for conversationStarted
47
debug: Setting up a handler for message_received
48
debug: Setting up a handler for message_received
49
debug: Setting up a handler for message_received
50
debug: Setting up a handler for message_received
51
debug: Setting up a handler for message_received
52
~~~~~~~~~~
53
NOTE: Botkit Studio functionality has not been enabled
54
To enable, pass in a studio_token parameter with a token from https://studio.botkit.ai/
55
[connect] Connected
56
[login] Logging in botkit.user
57
[getRoomIdByNameOrId] Calling (caching): GENERAL
58
[getRoomIdByNameOrId] Success: "GENERAL"
59
[joinRoom] Calling (async): ["GENERAL"]
60
[joinRoom] Success: true
61
[subscribe] Preparing subscription: stream-room-messages: __my_messages__
62
[subscribe] Stream ready: 4
63
[reactive] Listening for change events in collection stream-room-messages
Copied!
  • After running the bot, Log in to the server as a regular user (not the BOT user), go to general room, and try to talk to your bot. The bot will listen to every message in the channel.
1
[received] Message in room GENERAL
2
Message receive callback ID Nhbc6R84s24ahHwiM at Wed Nov 24 2021 10:56:07 GMT+0100 (West Africa Standard Time)
3
[Incoming] rodriq: hello
4
[getRoomNameById] Calling (caching): GENERAL
5
[getRoomNameById] Success: "general"
6
I RECEIVED {
7
_id: 'Nhbc6R84s24ahHwiM',
8
rid: 'GENERAL',
9
msg: 'hello',
10
ts: 1637747767569,
11
u: { _id: '5y8XK9YBhCHBDL4rx', username: 'rodriq', name: 'Rodriq' },
12
_updatedAt: { '$date': 1637747767627 },
13
urls: [],
14
mentions: [],
15
channels: [],
16
md: [ { type: 'PARAGRAPH', value: [Array] } ],
17
type: 'message_received',
18
raw_message: {
19
_id: 'Nhbc6R84s24ahHwiM',
20
rid: 'GENERAL',
21
msg: 'hello',
22
ts: { '$date': 1637747767569 },
23
u: { _id: '5y8XK9YBhCHBDL4rx', username: 'rodriq', name: 'Rodriq' },
24
_updatedAt: { '$date': 1637747767627 },
25
urls: [],
26
mentions: [],
27
channels: [],
28
md: [ [Object] ],
29
type: 'message_received'
30
},
31
_pipeline: { stage: 'receive' },
32
text: 'hello',
33
user: 'rodriq',
34
channel: 'GENERAL'
35
}
36
debug: RECEIVED MESSAGE
Copied!
Botkit bot is talking

Running Botkit with Docker

To fire up a docker instance of your botkit bot, run the following command.
1
docker-compose up mongo rocketchat
Copied!
Last modified 14d ago