Skip to main content
Build a Mastra agent with Novu Connect. You call Mastra from a Novu 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?

How do I get a working agent?

1

Run the CLI

In an empty folder:
When prompted:
  1. Sign in to Novu (or paste your secret key).
  2. Choose Custom code as the runtime (Mastra uses the base Framework path).
  3. Name your agent. Note the identifier the CLI prints. Your code must use the same value.
  4. You can skip LLM auth in the CLI. You will wire Mastra in the next steps after the scaffold.
  5. Choose Slack (or another channel).
2

Connect Slack

When the CLI asks for a Slack App Configuration Token:
  1. Open Slack API apps.
  2. Under App Configuration Tokens, click Generate Token.
  3. Select your workspace, generate the token, and copy it (it starts with xoxe.xoxp-).
  4. Paste it into the CLI and finish the install / Allow flow in Slack.
The token is used once to create the Slack app. Novu does not store it.For screenshots of this flow, see Create a Slack app in the custom code quickstart.
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:
  1. Install Mastra:
  1. Add your model key to .env.local (keep the NOVU_SECRET_KEY the CLI wrote):
  1. Replace the demo handler with Mastra. Create app/novu/agents/mastra-support.ts:
  1. Update your Novu agent file (use your real identifier) so it calls Mastra:
  1. Export that agent from app/novu/agents/index.ts.
If you already have an app and skipped the scaffold, jump to Wire an existing app.
4

Run the agent locally

This starts your app and tunnels it to Novu so channel messages reach your bridge. Keep the process running.If the script is missing:
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:novu is still running.
  • Confirm the agent identifier in code matches the dashboard.
  • Confirm OPENAI_API_KEY is 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.
Add to .env.local:
Copy NOVU_SECRET_KEY from API Keys in the dashboard if needed.
Same code as Accept the scaffold, then wire Mastra: a Mastra Agent, a small toMastraMessages helper, and a Novu agent() that returns result.text.
Create app/api/novu/route.ts:
Then run npx novu dev (or npm run dev:novu) and message the bot. For Express, Hono, and other servers, see Connecting your app.
For human-in-the-loop approval before a sensitive tool runs, use Novu’s tool approval APIs (ctx.toolApproval.request()).

Frequently asked questions

Slack, Microsoft Teams, WhatsApp, Telegram, and email. One handler works for all of them. See Agents and providers.
Not yet. Use @novu/framework and return text from onMessage. AI SDK and LangChain already have dedicated adapters if you prefer those stacks.
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().
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.
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

Open in Cursor

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.