Novu gives your handler the same building blocks whether the message came from Slack, email, or another provider, and whether you call an LLM or plain TypeScript.
Channel support#
Handlers are provider-agnostic. The same onMessage, onMessageUpdated, onMessageDeleted, onAction, onReaction, onResolve, onToolApproval, and onError APIs run on Slack, Microsoft Teams, WhatsApp, Telegram, and email. What the user sees (buttons vs action links, typing vs eyes reaction) depends on the channel. See Channels overview.
| Event surface | Slack | Teams | Telegram | ||
|---|---|---|---|---|---|
onMessage | Yes | Yes | Yes | Yes | Yes |
onAction (buttons / links) | Yes | Yes | Yes | Yes | Yes |
onReaction | Yes | Yes | Yes | Yes | Gmail only |
onResolve | Yes | Yes | Yes | Yes | Yes |
onToolApproval | Yes | Yes | Yes | Yes | Yes |
Event handlers#
Event handlers are functions that respond to events in a conversation. Your agent can respond to these event types:
| Handler | When it runs | Common use case |
|---|---|---|
onMessage | A user sends a message in the conversation | Process the message and reply |
onMessageUpdated | A user edits a message they already sent | Re-evaluate the request; ctx.previousMessage holds the prior text |
onMessageDeleted | A user deletes a message | Clean up state tied to that message |
onAction | A user clicks a button or selects a value in an interactive card | Handle form submissions, button clicks, dropdown selections |
onReaction | A user adds or removes a reaction | Capture feedback or trigger a follow-up |
onResolve | The conversation is marked as resolved | Clean up state, log analytics, or send a summary |
onToolApproval | A user approves or denies a gated tool call | Run or skip the tool, audit the decision. See Tool approval |
onError | A turn fails (handler throw, promise rejection, delivery error) | Log, suppress, send custom copy, or rely on Novu’s generic reply |
Handlers are where the communication layer connects to your application logic. For example, an onMessage handler receives the user’s message, passes conversation context to an LLM or custom function, and sends the response back through Novu.
Context object#
Each event handler receives a context object with the information needed to understand the current event and respond. Depending on the event type, it can include:
- The incoming message
- The current conversation state and metadata
- The resolved subscriber (when available)
- Recent conversation history
- The originating workflow notification (
ctx.notification), when the conversation started from a workflow-assigned agent send - Provider information
- Platform-specific details, such as thread or channel identifiers
- Methods for replying, emitting custom events, updating metadata, triggering workflows, or resolving the conversation
The context object is how your code talks to Novu. You do not call Slack, Teams, or email APIs directly in the handler.
Event handling flow#
When a user messages your agent:
User sends a message
A user sends a message from a connected provider (for example, Slack).
Novu receives the event
The provider delivers the inbound message to your agent endpoint.
Novu maps the thread
Novu maps the provider thread to a conversation and resolves the platform user to a subscriber, when possible.
Novu calls onMessage
Novu calls the agent’s onMessage handler with the context object.
Handler passes context to agent logic
Your handler forwards the message and ctx.history to your LLM or custom logic.
Agent logic decides next action
Your agent logic decides what should happen next.
Handler sends reply or signals
Your handler returns a reply, calls ctx.reply(), or emits signals.
Novu delivers the reply
The agent response is posted back to the original provider thread.
Novu records conversation state
Novu records messages, participants, metadata, signals, and conversation status.
The same agent logic works across all connected providers because Novu handles the provider-specific communication layer. Connecting a new provider does not require changing your agent code.
onMessage#
onMessage fires every time a user sends a message in a conversation with your agent.
Return generateText() or streamText() from the handler - Novu delivers the model output to the thread. See AI SDK.
Return a LangChainAgentConfig from the handler - Novu runs the agent and delivers the final text. See LangChain.
Call your LLM or business logic yourself, then reply with ctx.reply() or by returning a string.
Handling attachments#
Inbound messages can include file attachments when the platform supports them. Novu normalizes files into message.attachments with short-lived signed URLs. Keep in mind:
- Download attachment URLs promptly inside your handler.
- Signed links are valid for 15 minutes.
- Inbound attachments are limited to 25 MB per file.
Quote-reply context#
When a user quote-replies to a prior message, Novu sets message.replyTo with that message’s platform id. Supported on WhatsApp, Telegram, and Microsoft Teams.
Formatted content#
message.text is plain text, so formatting such as bold, links, code, and pasted Slack tables is lost. When the message has formatting, Novu also sets message.markdown with the same content as GitHub-flavored Markdown. Slack tables become GFM tables. For plain prose, message.markdown is not set because text already has the full content.
Author details#
message.author describes who sent the message, even when the sender is not linked to a subscriber:
author.email: the sender’s email, when the platform provides it (Slack, Microsoft Teams, and email).author.isSystem:truewhen the platform itself generated the message, such as a Slackbot notice. Use it to skip messages that did not come from a person.
onMessageUpdated#
onMessageUpdated fires when a user edits a message they already sent. It does not re-run onMessage. The handler receives the edited message (same platformMessageId), and ctx.previousMessage holds the body before the edit when the channel sends it, or null when it does not.
onMessageDeleted#
onMessageDeleted fires when a user deletes a message. It does not re-run onMessage. The handler receives the removed message; message.text is the last known body and may be empty when the channel does not include a snapshot.
Both handlers are optional and depend on the channel reporting message edits and deletions. Slack reports both. Novu records each edit and delete as an append-only revision, so dashboard history keeps the full log while the model transcript reflects the latest text.
onAction#
onAction fires when a user clicks a button or selects a value in an interactive card. The action payload carries action.id (the element’s id prop), action.value (its value prop, if set), and action.sourceMessageId. See Interactive cards.
onReaction#
onReaction fires when a user adds or removes an emoji reaction on a message. The reaction payload carries reaction.emoji.name, reaction.added (true when added, false when removed), and reaction.messageId.
onResolve#
onResolve fires when the conversation is marked as resolved via ctx.resolve() or the resolve signal. It receives only the context object.
onToolApproval#
onToolApproval fires when a user approves or denies a gated tool call. It receives a decision with the tool call, the verdict, and a handle to the approval card.
On the AI SDK path, tools gated with needsApproval: true in onMessage trigger this handler when the user clicks Approve or Deny. Register it when you need a hook after the click - for example to audit the decision or change how the card is handled.
Gate the tool with ctx.toolApproval.request() and handle the click in onToolApproval:
See Tool approval for card customization, auditing, and renderApproval.
onError#
When a turn fails - your handler throws, a returned promise rejects, or message delivery fails inside the handler - Novu runs an error pipeline on the bridge before the turn ends:
- Log the failure locally on your bridge
- Call
onErrorif you registered one - If
onErrordoes not handle the failure, auto-report{ error: true }to Novu - Novu delivers safe generic copy to the user in the thread
- Clear the typing indicator for the turn (even when no reply is sent)
By default, users see:
Something went wrong while processing your message. Please try again in a moment.
Return from onError | Behavior |
|---|---|
nothing / undefined | Auto-report - Novu sends the generic message |
{ suppress: true } | No user-visible reply (failure is logged only) |
string / JSX Card | Custom reply delivered through ctx.reply() |
The first argument is an AgentError (use toAgentError() from @novu/framework if you normalize errors in your own code). Reply delivery failures surface as AgentDeliveryError, a subclass of AgentError, with statusCode and responseBody for debugging.
When onError returns message content, Novu posts it like a normal reply. When it returns nothing, the framework auto-reports the turn failure and Novu sends the generic message.
When to suppress#
Use { suppress: true } when a failure should be logged on your bridge but should not post another message in the thread. A common case is side-effect handlers such as onReaction or onAction: if analytics or feedback logging fails, a generic “Something went wrong…” reply is usually more confusing than helpful.
For onMessage failures, prefer a custom reply or the default generic message so the user knows their message was not handled.
Runtime adapters forward onError from the same agent config. For adapter-specific failure behavior, see AI SDK, LangChain, or Other frameworks.
Reporting turn failures is best-effort. If the bridge cannot reach Novu, the failure is logged locally and is not re-thrown. Failures inside onError itself are logged and do not recurse.
Related#
Send plain text, markdown, attachments, and interactive cards.
Show a Thinking… or custom status while your handler runs.
Gate tool calls with an in-thread Approve / Deny card.
Build end to end with @novu/framework/ai-sdk.
Build end to end with @novu/framework/langchain.