onMessage handler and return the text. Novu delivers replies on Slack, Microsoft Teams, WhatsApp, Telegram, or email.
This walkthrough uses Slack for the first connection. The same handler works on other channels once you link them.
Novu does not ship a dedicated
@novu/framework/mastra adapter yet. Use @novu/framework, call Mastra in onMessage, and return the text (or call ctx.reply()).What do I need before I start?
- A Novu account
- Node.js 22+
- A Slack workspace where you can install apps (or another supported channel)
- An
OPENAI_API_KEY(or another model key Mastra supports)
How do I get a working agent?
1
Run the CLI
In an empty folder:- Sign in to Novu (or paste your secret key).
- Choose Custom code as the runtime (Mastra uses the base Framework path).
- Name your agent. Note the identifier the CLI prints. Your code must use the same value.
- You can skip LLM auth in the CLI. You will wire Mastra in the next steps after the scaffold.
- Choose Slack (or another channel).
2
Connect Slack
When the CLI asks for a Slack App Configuration Token:- Open Slack API apps.
- Under App Configuration Tokens, click Generate Token.
- Select your workspace, generate the token, and copy it (it starts with
xoxe.xoxp-). - Paste it into the CLI and finish the install / Allow flow in Slack.
3
Accept the scaffold, then wire Mastra
Confirm creating a starter project when the CLI asks. It creates a Next.js app with a bridge route and a demo handler.Then:- Install Mastra:
- Add your model key to
.env.local(keep theNOVU_SECRET_KEYthe CLI wrote):
- Replace the demo handler with Mastra. Create
app/novu/agents/mastra-support.ts:
- Update your Novu agent file (use your real identifier) so it calls Mastra:
- Export that agent from
app/novu/agents/index.ts.
4
Run the agent locally
5
Send a message
Message your bot in Slack (DM or @mention). You should get a reply from Mastra in the same thread.Success looks like: the tunnel is connected, and the reply is from your Mastra agent (not the demo scaffold text).If nothing comes back:- Confirm
npm run dev:novuis still running. - Confirm the agent identifier in code matches the dashboard.
- Confirm
OPENAI_API_KEYis set. - Confirm Slack install completed and you are messaging the correct bot.
Wire an existing app
Use this only if you skipped the CLI scaffold. Otherwise you can skip this section.Install packages and env
Install packages and env
.env.local:NOVU_SECRET_KEY from API Keys in the dashboard if needed.Create the Mastra agent and Novu handler
Create the Mastra agent and Novu handler
Same code as Accept the scaffold, then wire Mastra: a Mastra
Agent, a small toMastraMessages helper, and a Novu agent() that returns result.text.Add the bridge route
Add the bridge route
Create Then run
app/api/novu/route.ts:npx novu dev (or npm run dev:novu) and message the bot. For Express, Hono, and other servers, see Connecting your app.Add Mastra tools (optional)
Add Mastra tools (optional)
ctx.toolApproval.request()).Frequently asked questions
Which channels can I use with a Mastra agent?
Which channels can I use with a Mastra agent?
Slack, Microsoft Teams, WhatsApp, Telegram, and email. One handler works for all of them. See Agents and providers.
Does Novu have a Mastra adapter?
Does Novu have a Mastra adapter?
Not yet. Use
@novu/framework and return text from onMessage. AI SDK and LangChain already have dedicated adapters if you prefer those stacks.Why map ctx.history myself?
Why map ctx.history myself?
Adapters like
@novu/framework/ai-sdk convert history for you. On the base Framework path, you map history into whatever format Mastra expects, then call generate().Can I stream tokens into the channel?
Can I stream tokens into the channel?
Yes, with care. Post an initial reply with
ctx.reply(''), then update it as chunks arrive using ReplyHandle.edit(). The provider must support message edits.Which CLI runtime should I pick?
Which CLI runtime should I pick?
Choose Custom code. That wires the base
@novu/framework path Mastra uses.Set this up with an AI assistant
Build a Mastra agent with Novu Connect
Next steps
Other frameworks
Patterns for any LLM stack without a Novu adapter.
Agents and providers
Slack, Teams, WhatsApp, Telegram, and email capabilities.
Going to production
Deploy the bridge and switch off local tunneling.
AI SDK quickstart
Same flow with a first-class Novu adapter.