mastra-channels
Skill2 starsChanged 29 days agoApache-2.0View on GitHub
Put a Mastra agent into Slack, Microsoft Teams, Discord, Telegram, WhatsApp, iMessage, and any other Chat SDK platform with the agent channels option, webhook routes, thread context, tool approval cards, streaming replies, custom handlers, and serverless delivery; or let Mastra provision bots with SlackProvider, TeamsProvider, or TelegramProvider. Use this skill whenever the user wants an agent in a messaging app, a Slack bot, a webhook URL for a bot, approve and deny buttons in chat, multi-user threads, or a bot that keeps working on Vercel. Triggers on channels, @mastra/core/channels, @chat-adapter/slack, createSlackAdapter, createDiscordAdapter, createTeamsAdapter, createTelegramAdapter, createWhatsAppAdapter, createiMessageAdapter, createLinqAdapter, Chat SDK, SlackProvider, @mastra/slack, TeamsProvider, TelegramProvider, ChannelProvider, toolDisplay, toolApprovers, threadContext, onMention, waitUntil, channel webhook. Also covers GitHub and Ring listings.
- Reads credentials
- Installs packages
In this repository46 other files it gives its agents.
- mastra-a2a-acpSkill
- mastra-agent-approval-hitlSkill
- mastra-agentic-uiSkill
- mastra-agent-skillsSkill
- mastra-agentsSkill
- mastra-authSkill
- mastra-browserSkill
- mastra-build-playbookSkill
- mastra-classifierSkill
- mastra-cli-apiSkill
- mastra-client-sdkSkill
- mastra-datasets-experimentsSkill
- mastra-deploymentSkill
- mastra-evalsSkill
- mastra-file-based-agentsSkill
- mastra-framework-integrationSkill
- mastra-guideSkill
- mastra-harnessSkill
- mastra-knowledgeSkill
- mastra-mcpSkill
- mastra-memorySkill
- mastra-migrationsSkill
- mastra-modelsSkill
- mastra-multi-agentSkill
- mastra-observabilitySkill
- mastra-observational-memorySkill
- mastra-platformSkill
- mastra-processors-guardrailsSkill
- mastra-project-setupSkill
- mastra-ragSkill
- mastra-schedulesSkill
- mastra-semantic-recallSkill
- mastra-serverSkill
- mastra-signalsSkill
- mastra-storageSkill
- mastra-streamingSkill
- mastra-structured-outputSkill
- mastra-studio-editorSkill
- mastra-tool-integrationsSkill
- mastra-toolsSkill
- mastra-troubleshootingSkill
- mastra-vector-storesSkill
- mastra-voiceSkill
- mastra-workflowsSkill
- mastra-workflow-suspend-resumeSkill
- mastra-workspace-sandboxSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 107
Verify the API: If node_modules/@mastra/ exists, read node_modules/@mastra/core/dist/docs/ for channels and the installed ChannelConfig …
- Very specific: line 111
Expose the server: Run npx mastra dev, then npx cloudflared tunnel --url http://localhost:4111, and paste …
- Very specific: line 122
Sender identity: Every run has requestContext.get('channel') (type ChannelContext from @mastra/core/channels) with platform, userId, …
- Very specific: line 136
Memory ownership: Default resourceId is ${platform}:${userId}.
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Mastra Channels
Connect an agent to messaging platforms so users talk to it in DMs, mentions, and threads, with webhooks, memory, approvals, and serverless delivery set up correctly.
When to use
- Adding an agent to Slack, Teams, Discord, Telegram, WhatsApp, iMessage, or another Chat SDK adapter
- Building the webhook URL and testing it locally through a tunnel
- Rendering tool calls and Approve/Deny cards in chat, or hiding them
- Handling DMs, mentions, subscribed threads, and unmentioned messages with custom handlers
- Mapping platform users to your own user IDs for memory (
resolveResourceId) - Images, video, PDFs, and links in chat messages (
inlineMedia,inlineLinks) - Running channel agents on Vercel, Lambda, or other serverless platforms
- Letting Mastra create and install bots (
SlackProvider,TeamsProvider,TelegramProvider)
When NOT to use
- GitHub pull request follow-up and Ring doorbell events: these are signal providers (use
mastra-signals) - Managed channel credentials through Mastra Connect (use
mastra-tool-integrations) - Building the agent itself (use
mastra-agents) - Memory, threads, and
lastMessagestuning (usemastra-memory) - Tool approval semantics outside chat (use
mastra-agent-approval-hitl) - Pub/sub, server middleware, and auth on other routes (use
mastra-serverandmastra-auth) - Deploying the server (use
mastra-deployment)
Required inputs
- Target platforms and whether you create the bot yourself (adapter) or let Mastra provision it (provider)
- Platform credentials (bot token, signing secret, app ID and password, webhook verify token)
- A public HTTPS base URL (production URL, or a tunnel in development)
- Storage for the Mastra instance (thread subscriptions, approvals, dedup)
- Which tools need approval, and who may approve them in shared channels
- Deployment target (long-running server vs serverless)
The framework: adapter on the agent, webhook route from Mastra
Channels use Chat SDK adapters. Add an adapter under channels.adapters; Mastra registers a webhook route for it and runs the normal agent pipeline for each message, streaming the reply back.
import { Agent } from '@mastra/core/agent'
import { createSlackAdapter } from '@chat-adapter/slack'
export const yourAgent = new Agent({
id: 'your-agent',
name: 'Your Agent',
instructions: 'You are a helpful assistant.',
model: 'openai/gpt-6.1-sol',
channels: {
adapters: {
slack: createSlackAdapter(),
},
},
})import { Mastra } from '@mastra/core'
import { LibSQLStore } from '@mastra/libsql'
import { yourAgent } from './agents/your-agent'
export const mastra = new Mastra({
agents: { yourAgent },
storage: new LibSQLStore({ id: 'mastra-storage', url: process.env.DATABASE_URL }),
})Webhook route: /api/agents/<AGENT_ID>/channels/<ADAPTER_KEY>/webhook, for example /api/agents/your-agent/channels/slack/webhook. Point the platform's event, interactions, or webhook URL there. The adapter key (slack above) also becomes the platform value.
| Path | Use when |
Adapter on channels.adapters | You create the bot or app yourself and set env vars |
ChannelProvider on new Mastra({ channels }) | Mastra provisions apps, runs OAuth installs, stores encrypted tokens |
Message routing
| Handler | Fires on | Default |
onDirectMessage | DMs | Runs the agent and posts the reply |
onMention | @mentions | Runs the agent, then subscribes to the thread |
onSubscribedMessage | Later messages in subscribed threads | Runs the agent |
onMessage | Anything else the bot can read | Off unless you supply a function |
onAction | Button and select clicks | Handles built-in Approve/Deny |
Each handler is omitted (default), false (disabled), or (thread, message, defaultHandler, ctx) => Promise<void>.
Workflow
- Verify the API. If
node_modules/@mastra/exists, readnode_modules/@mastra/core/dist/docs/for channels and the installedChannelConfigtypes. Otherwise fetchhttps://mastra.ai/docs/channels.md,https://mastra.ai/reference/agents/channels.md, and the platform page such ashttps://mastra.ai/integrations/channels/slack.md. Trust these over memory. - Install the adapter (
npm install @chat-adapter/slack) and add it tochannels.adapters. - Configure storage on
Mastra. Channels need it for subscriptions, approvals, and dedup. Addmemoryto the agent so thread history persists. - Set credentials the adapter reads (for Slack:
SLACK_SIGNING_SECRET,SLACK_BOT_TOKEN). Seereferences/providers.md. - Expose the server. Run
npx mastra dev, thennpx cloudflared tunnel --url http://localhost:4111, and pastehttps://<tunnel>/api/agents/<id>/channels/<key>/webhookinto the platform settings (Slack: Event Subscriptions and Interactivity). - Tune presentation.
toolDisplay,streaming,textFormat,textDisplay,typingStatusper adapter. - Gate tools. Mark risky tools
requireApproval: true. DecidetoolApprovers: 'requester'(default) or'anyone'. On platforms without cards, avoid approval-gated tools. - Customize routing and identity with
handlers,ctx.requestContext,resolveResourceId, andthreadContext. - Prepare for production. On Vercel pass
waitUntil. On multi-instance or serverless, configure a shared pub/sub (RedisStreamsPubSub) and a sharedstateadapter. Update webhook URLs to the production host.
Deep dive: identity, access, and context
- Who can reach the agent. Slack has no allowlist. Anyone in a DM or a channel the bot belongs to, including Slack Connect guests, can use the agent and its tools. Gate on the sender in a handler or tool.
- Sender identity. Every run has
requestContext.get('channel')(typeChannelContextfrom@mastra/core/channels) withplatform,userId,userName,isDM,channelId,threadId,botUserId,botUserName,botMention.
channels: {
adapters: { slack: createSlackAdapter() },
handlers: {
onDirectMessage: async (thread, message, defaultHandler, ctx) => {
ctx.requestContext.set('locale', 'en-GB')
await defaultHandler(thread, message)
},
},
},- Memory ownership. Default
resourceIdis${platform}:${userId}. UseresolveResourceIdto map platform users to your SSO user. It runs only when a thread is created. - Thread context. On the first mention in a thread, Mastra saves the first message plus up to
maxMessages - 1recent ones (default 10) into memory. Set memorylastMessagesto at leastmaxMessages + 1. Disable withthreadContext: { maxMessages: 0 }for adapters that cannot fetch history. - Webhook auth. Channel webhooks are public routes exempt from Mastra server auth. The adapter verifies signatures, so keep signing secrets set.
Failure patterns
- No storage on
Mastra. Subscriptions, approvals, and dedup are lost on restart. Configure storage. - Webhook pointed at
localhost. Platforms cannot reach it. Use a tunnel, then switch to the production URL after deploy. - Wrong path segment. The route uses the agent
idand the adapter key, not the variable name. - Agent stops mid-reply on Vercel or Lambda. The function froze after the
200. PasswaitUntilfrom@vercel/functions(orresolveWaitUntil). - Threads processed twice on serverless. The default pub/sub is in memory. Configure
RedisStreamsPubSubonMastra. - Duplicate side effects after retries. Dedup is best effort. Use a shared
stateadapter (createRedisState()) and make handler side effects idempotent. - Custom handler throws silently. Errors in custom handlers are only logged. Catch them and post a message to the thread.
- Approval buttons do nothing.
onAction: false, a customonActionthat never callsdefaultHandler(), or custom card ids not exactlytool_approve:<toolCallId>/tool_deny:<toolCallId>. - Approval-gated tool on iMessage or with
toolDisplay: 'text'. Text cannot submit approvals; the tool stays suspended. Avoid it or approve from another surface. timelineorgroupedwithout streaming. Falls back tocardswith a warning. Keepstreaming: true(Slack default).- First message trimmed from thread context. Memory
lastMessagesis lower thanmaxMessages + 1. - Expecting channel tools automatically.
add_reactionandremove_reactionare never added; pass them explicitly from the channelsgetTools(). - Prompting for Slack mrkdwn. Replies post as standard markdown by default. Remove the dialect instructions or set
textFormat: 'plain'.
Output format
A finished channel delivery contains:
- The agent with
channels.adapters(or aChannelProvideronnew Mastra({ channels })) - Storage on
Mastraand memory on the agent - Adapter credentials in
.env.exampleand the webhook URL documented per platform - Approval and display settings matching the platform's card support
- Serverless settings (
waitUntil, shared pub/sub, shared state) when deployed serverless - Evidence: a DM and a mention answered in the real platform through a tunnel or staging URL
Reference files
references/api.md-ChannelConfig, per-adapter options, handlers, context types,ChannelProviderinterface, Slack, Teams, and Telegram providers.references/examples.md- Slack agent end to end, multi-platform support agent with handlers, serverless Vercel setup, provider-managed Telegram bot.references/providers.md- Every platform page: package, factory, env vars, webhook notes, card support; plus GitHub and Ring signal providers.references/checklist.md- Launch checklist.
Live docs
- https://mastra.ai/docs/channels
- https://mastra.ai/reference/agents/channels
- https://mastra.ai/reference/channels/channel-provider
- https://mastra.ai/reference/channels/slack-provider
- https://mastra.ai/reference/channels/teams-provider
- https://mastra.ai/reference/channels/telegram-provider
- https://mastra.ai/integrations/channels/slack
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

