Book Image

Building Slack Bots

Book Image

Building Slack Bots

Overview of this book

Slack promises that its users will "be less busy." Slack bots interact with users in Slack chatrooms, providing useful immediate information, and automating work. This book gives you everything you need to build powerful and useful Slack bots. You’ll see how to hook into the Slack API to create software that can read and post to chatrooms, respond to commands and hints given in natural conversational language, and build fun and useful bots for your own place of work, both as a front end to your own service and to distribute and share as apps. You can even sell your bots and build a business as a Slack bot developer. Throughout the book, you’ll build useful and fun example applications that you can modify for your own situations. These range from simple, fun applications to liven up discussions to useful, data-driven apps to help you make decisions quickly and manage work.
Table of Contents (14 chapters)

Debugging a bot


It is inevitable that eventually you will encounter a bug in your bot that is difficult to squash. The worst are bugs that don't cause your program to crash and thus don't provide a useful stack trace and line number for where the crash happened. For most issues, the console.log() method will be enough to help you track down the bug, for the more tenacious bugs however we will need a true debugging environment. This section will introduce you to iron-node (https://s-a.github.io/iron-node/), a cross-platform JavaScript debugging environment based on Chrome's dev tools.

Start by installing iron-node:

npm install -g iron-node

Note again the use of the -g flag, which installs the application globally.

Before we can start debugging, we need to add a breakpoint to our code, which tells the debugger to stop the code and allow for deeper inspection. Add the debugger statement to our previous code, within the slack.openDM() code block:

if (/uptime/g.test(msg)) {
  debugger;
      
...