The Palos Publishing Company

Follow Us On The X Platform @PalosPublishing
Categories We Write About

Create a Slack bot to automate reminders

Creating a Slack bot to automate reminders involves building a bot that can integrate with Slack’s API, respond to commands, and send scheduled messages. Below is a concise implementation guide using Python, Flask, and Slack Bolt SDK.


Prerequisites

  • Python 3.8+

  • Slack workspace

  • Slack App created from https://api.slack.com/apps

  • Install dependencies:

    bash
    pip install slack_bolt flask apscheduler

Step 1: Create a Slack App

  1. Go to https://api.slack.com/apps and create a new app.

  2. Enable Socket Mode and Bot Token.

  3. Under “OAuth & Permissions”, add:

    • chat:write

    • commands

    • reminders:write

  4. Install the app to your workspace and save the Bot Token and App Token.


Step 2: Basic Bot Structure

python
from slack_bolt import App from slack_bolt.adapter.flask import SlackRequestHandler from flask import Flask, request from apscheduler.schedulers.background import BackgroundScheduler from datetime import datetime, timedelta SLACK_BOT_TOKEN = "xoxb-your-bot-token" SLACK_APP_TOKEN = "xapp-your-app-level-token" app = App(token=SLACK_BOT_TOKEN) flask_app = Flask(__name__) handler = SlackRequestHandler(app) scheduler = BackgroundScheduler() scheduler.start() reminders = [] @app.command("/remindme") def handle_remindme_command(ack, respond, command): ack() text = command['text'] # Expected format: "Take a break in 10" try: message, minutes = text.rsplit(" in ", 1) delay_minutes = int(minutes.strip()) reminder_time = datetime.now() + timedelta(minutes=delay_minutes) reminders.append({ "channel": command['channel_id'], "message": message.strip(), "time": reminder_time }) respond(f"✅ Got it! I'll remind you to *{message.strip()}* in {delay_minutes} minutes.") except Exception as e: respond("⚠️ Please use the format: `/remindme [message] in [minutes]`") def check_reminders(): now = datetime.now() for reminder in reminders[:]: if now >= reminder["time"]: app.client.chat_postMessage(channel=reminder["channel"], text=f"⏰ Reminder: {reminder['message']}") reminders.remove(reminder) scheduler.add_job(check_reminders, 'interval', seconds=30) @flask_app.route("/slack/events", methods=["POST"]) def slack_events(): return handler.handle(request) if __name__ == "__main__": flask_app.run(port=3000)

Step 3: Configure the /remindme Slash Command

In the Slack App settings:

  • Navigate to Slash Commands.

  • Add /remindme with the request URL: https://yourdomain.com/slack/events (use ngrok or public URL during testing).

  • Set the usage hint like: Take a break in 10


Notes

  • Use ngrok for local testing: ngrok http 3000

  • You can enhance the bot to support recurring reminders, message editing, or use natural language parsing with dateparser.


This script sets up a simple Slack bot that accepts reminder commands and sends automated messages after the specified delay.

Share this Page your favorite way: Click any app below to share.

Enter your email below to join The Palos Publishing Company Email List

We respect your email privacy

Categories We Write About