Connect a Mastra agent to Novu Connect via @novu/framework. Call generate() in onMessage and return the text. Novu delivers the reply on Slack. The same handler works on other providers after you link them.
There is no @novu/framework/mastra adapter yet. Use the base Framework package and return text from onMessage (or call ctx.reply()).
Starting from scratch? See Scaffold with the CLI.
Prerequisites#
- A Novu account
- Node.js 22+
- An existing app with a Mastra agent
- A Slack workspace where you can install apps
- An
OPENAI_API_KEY(or another model key Mastra supports)
Connect an existing app#
Create the agent and connect Slack#
In the Novu dashboard:
- Go to Agents → Create agent.
- Under Custom code, pick Custom code (Mastra uses the base Framework path).
- Set Agent name and Identifier.
- Select Slack, generate a Slack App Configuration Token, paste it, and finish the install / Allow flow.
Alternatively run npx novu connect, choose Custom code and Slack, and skip creating a starter project when prompted.
Add the Mastra agent and Novu handler#
Match agent('...') to the dashboard Identifier. Export the Novu agent from your agents index.
Run locally and message Slack#
DM or @mention the bot in Slack. The reply should come from Mastra in the same thread.
Tool approval#
For sensitive tools, use ctx.toolApproval.request() from Tool approval so the turn pauses for Approve / Deny before execution.
Scaffold with the CLI#
Choose Custom code, connect Slack, accept the starter project, install @mastra/core, and replace the demo handler with the code above.
For an existing codebase, use Connect an existing app instead.
FAQ#
Which channels work with a Mastra agent?
Slack, Microsoft Teams, WhatsApp, Telegram, and email. See Channels overview.
Does Novu have a Mastra adapter?
Not yet. Use @novu/framework and return text from onMessage. AI SDK and LangChain have dedicated adapters if you prefer those stacks.
Where is the generic Framework API documented?
Other frameworks for patterns without a dedicated adapter.
Set this up with an AI assistant#
Connect a Mastra agent to Slack with Novu Connect#
Follow https://docs.novu.co/agents/get-started/mastra
Goal#
Add Novu bridge + Mastra handler to this repo and connect Slack. Prefer the existing project over scaffolding a new one.
Rules#
ALWAYS:
- Match Novu
agent('id')to the dashboard agent Identifier - Map only
type === 'message'history entries into Mastra messages - Use Mastra model strings like
openai/gpt-4o - Keep handlers channel-agnostic
NEVER:
- Hardcode API keys
- Import
@novu/framework/ai-sdkor@novu/framework/langchainfor this path