Search code examples
slackslack-api

Design Slackbot service to send automated messages


It is my very first time to write a slack bot and i am wondering how to design it.

The bot supposed to be available and respond to end-users' messages immediately.

The thing is that I need that the bot will also send schedules messages to registered users with automation results.

Use case example:

A user sends a message to the bot and registered to a service that will check for changes in X. On a specific interval, my backend will call an automation that checks for those changes and will send a message to the user with the results.

What will be the best practice for this scenario?


Solution

  • Here is a basic outline.

    1. Basic setup

    • Slack app with bot user
    • Database
    • Scheduler (e.g. local CRON service, or web-cron like cron-job.org)

    2. Registration

    • Use Events API to listen to messages from users send via mention (app_mention) or direct message (message.im)
    • You app needs to store the received "registration" from each user in a database
    • Respond to user request directly if needed with chat.postMessage

    3. Scheduled response

    • Scheduler calls your app

    • Your app check if responses are due with a database query

    • If yes: App sends responses to users via chat.postMessage (but not more than one message per sec due to rate limiting)