Course contentsShow
← AI Engineering
Lesson 1821 of 1,88644. Integrations and EcosystemFree lesson

Slack Event Handling and Commands

Processing slash commands, app mentions, direct messages, and real-time events using the Events API.

Slack Event Handling and Commands

What you'll learn: How to process slash commands, app mentions, direct messages, and real-time events through Slack's Events API to build responsive AI-powered bots.

Core Concepts

Once your Slack bot is authenticated (from the previous lesson), it needs to listen and respond to user interactions. Slack provides several mechanisms for this:

Slash Commands are user-invoked shortcuts like /summarize or /ask-ai. When a user types these, Slack sends an HTTP POST request to your endpoint with the command and any text that follows.

App Mentions occur when someone types @YourBot in a channel. These trigger events that your bot receives, allowing it to respond contextually to being called out.

Direct Messages are private conversations users initiate with your bot. These arrive as message events and require your bot to handle conversational context.

The Events API delivers real-time events (mentions, messages, reactions, etc.) to your webhook URL. You subscribe to specific event types during bot setup, and Slack pushes them to you as they happen.

How It Works

Think of it like a restaurant: slash commands are customers ringing a bell for service (explicit requests), while the Events API is a server constantly watching tables for raised hands or gestures (ambient monitoring). Your bot needs handlers for each interaction type.

When processing events, you typically extract the user's message, channel ID, and context, then pass the text to your LLM for processing. The response goes back through Slack's API to the appropriate channel or thread, maintaining conversation flow.

Key Takeaway: Slack bots respond to structured slash commands for explicit actions and subscribe to real-time events (mentions, DMs) through the Events API—enabling both command-driven and conversational AI interactions within Slack workspaces.