This is a repo for experimenting with Slackbots using the Botkit Node.js framework. Botkit is to Slack as Express is to the web.
Each bot is defined by a botname-bot.js
file in the top-level directory. Like you would define a set of web routes for an app in an Express or Sinatra main file, in each bot file you define a set of "bot routes" -- the things the bot is listening for and how it should respond. For each "route", you can tell the bot to listen only to direct messages, any mention, or all ambient messages in the channels it belongs to. That's the basic approach. Eventually you can get fancier, such as by having your bot initiate sending a message or starting a conversation.
git clone [email protected]:ewiener/consequential-bots.git
-
Install the consequential-bots repo.
-
Install botkit and other node dependencies defined in package.json. From within consequential-bots, run:
npm install
- Make a new bot integration inside of the consequential Slack team. Go here:
https://consequential.slack.com/services/new/bot
Enter a name for your bot, let's say Steve. As the Botkit documentation says, avoid a single task specific name.
-
After you click "Add Bot Integration", copy the API token that Slack gives you.
-
Create a .env file inside your consequential-bots repo and add a line like this:
SLACK_TOKEN_STEVE=<your-new-api-token>
- Copy example-bot.js to your own bot file, named after your own bot, and customize:
cp example-bot.js steve-bot.js
Edit steve-bot.js and set var BOTNAME = 'steve'
.
- Fire up your new bot:
node steve-bot.js
- Your bot should be online! Within Slack, send it a quick direct message to say hello. It should say hello back!
Try:
- who are you?
- call me Bob
- shutdown
-
Note: Your bot uses ./storage/steve to remember things.
-
See the Botkit documentation for much more.
I know about:
- Your location
i am in Berkeley
where am i
- Symbolic locations
home is in Berkeley
work is in Oakland
where is work
i am at work
work is at home
- Weather
weather
(I'll use your current location)weather in San Francisco
weather at work
weather here
(I'll ask where you are)
- XboxLive
xbox friends [gamertag]
xbox status [gamertag]
xbox msg gamertag message...
xbox messages