Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Building Slack Bots

You're reading from  Building Slack Bots

Product type Book
Published in Jun 2016
Publisher Packt
ISBN-13 9781786460806
Pages 182 pages
Edition 1st Edition
Languages
Concepts

Simple to-do example


With the basics of Redis covered, we shall now move on to create a simple to-do Slack bot. The aim of this bot is to allow users to create a to-do list, allowing them to add, complete, and delete a task from this list as they go about their day.

This time, we will start with a skeleton of what we want and build each feature step by step. Start by adding this new command to your bot:

bot.respondTo('todo', (message, channel, user) => {
  let args = getArgs(message.text);

  switch(args[0]) {
    case 'add':
      
      break;

    case 'complete':
      
      break;

    case 'delete':
      
      break;

    case 'help':
      channel.send('Create tasks with \`todo add [TASK]\`, complete them with \`todo complete [TASK_NUMBER]\` and remove them with \`todo delete [TASK_NUMBER]\` or \`todo delete all\`');
      break;

    default:
      showTodos(user.name, channel);
      break;
  }
}, true);

function showTodos(name, channel) {
  client.smembers(name, (err, set...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}