Channels
Added in: @mastra/core@1.22.0
Channels connect agents to messaging platforms. Configure them via the channels property on the Agent constructor. See the Channels guide for concepts and platform setup instructions.
Usage exampleDirect link to Usage example
import { Agent } from '@mastra/core/agent'
import { createSlackAdapter } from '@chat-adapter/slack'
import { createDiscordAdapter } from '@chat-adapter/discord'
export const supportAgent = new Agent({
id: 'support-agent',
name: 'Support Agent',
instructions: 'You are a helpful support assistant.',
model: 'openai/gpt-5.4',
channels: {
adapters: {
slack: createSlackAdapter(),
discord: createDiscordAdapter(),
},
},
})
ParametersDirect link to Parameters
adapters:
handlers?:
inlineMedia?:
inlineLinks?:
tools?:
state?:
userName?:
threadContext?:
chatOptions?:
Per-adapter optionsDirect link to Per-adapter options
Wrap an adapter in a ChannelAdapterConfig object to set per-adapter options:
import { Agent } from '@mastra/core/agent'
import { createDiscordAdapter } from '@chat-adapter/discord'
import { createSlackAdapter } from '@chat-adapter/slack'
const agent = new Agent({
name: 'Example',
instructions: '...',
model: 'openai/gpt-5.4',
channels: {
adapters: {
discord: {
adapter: createDiscordAdapter(),
cards: false,
gateway: false,
},
slack: createSlackAdapter(), // Plain adapter uses defaults
},
},
})
adapter:
gateway?:
cards?:
formatToolCall?:
formatError?:
HandlersDirect link to Handlers
Override built-in event handlers. Each handler can be:
- Omitted: uses the default Mastra handler (routes to
agent.streamand posts the response) false: disables the handler entirely- A function
(thread, message, defaultHandler) => Promise<void>: wraps or replaces the default
import { Agent } from '@mastra/core/agent'
import { createSlackAdapter } from '@chat-adapter/slack'
const agent = new Agent({
name: 'Custom Handler Agent',
instructions: '...',
model: 'openai/gpt-5.4',
channels: {
adapters: {
slack: createSlackAdapter(),
},
handlers: {
onMention: async (thread, message, defaultHandler) => {
console.log('Received mention:', message.text)
await defaultHandler(thread, message)
},
onDirectMessage: false,
},
},
})
onDirectMessage?:
onMention?:
onSubscribedMessage?:
The ChannelHandler function signature:
type ChannelHandler = (
thread: Thread,
message: Message,
defaultHandler: (thread: Thread, message: Message) => Promise<void>,
) => Promise<void>
Inline mediaDirect link to Inline media
Controls which attachment types (images, video, PDFs, etc.) are sent as file parts to the model. Types that do not match are described as text summaries so the agent knows about the file without crashing models that reject unsupported types.
Supported glob patterns:
| Pattern | Matches |
|---|---|
image/* | All image types (image/png, image/jpeg, etc.) |
video/* | All video types |
* or */* | All types |
application/pdf | Exact type match |
For platforms with private CDNs (e.g. Slack), attachments are fetched with authenticated credentials from the Chat SDK. For platforms with public CDNs (e.g. Discord), the URL is passed directly to the model.
Inline linksDirect link to Inline links
Promotes URLs found in message text to file parts so the model can process linked content instead of seeing raw URL text. Each entry can be a string (domain pattern) or an object with a forced mime type.
String entries match a domain and perform a HEAD request to detect the Content-Type. The resolved type is checked against inlineMedia and only matching types become file parts.
Object entries match a domain and force a specific mime type, skipping the HEAD request and bypassing the inlineMedia check. This is useful for sites like YouTube where a HEAD request returns text/html, but the model treats the URL as video content.
type InlineLinkEntry =
| string // Domain pattern (HEAD determines mime type)
| { match: string; mimeType: string } // Domain + forced mime type (skips HEAD)
RelatedDirect link to Related
- Channels guide — concepts, quickstart, and platform setup
- Agent class — constructor parameters and methods
- Chat SDK adapters — adapter configuration and platform setup