Event handlers
Event handlers are functions that respond to events in a conversation. Your agent can respond to four event types:
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
- Provider information
- Platform-specific details, such as thread or channel identifiers
- Methods for replying, updating metadata, triggering workflows, or resolving the conversation
Event handling flow
When a user messages your agent:1
User sends a message
A user sends a message from a connected provider (for example, Slack).
2
Novu receives the event
The provider delivers the inbound message to your agent endpoint.
3
Novu maps the thread
Novu maps the provider thread to a conversation and resolves the platform user to a subscriber, when possible.
4
Novu calls onMessage
Novu calls the agent’s
onMessage handler with the context object.5
Handler passes context to agent logic
6
Agent logic decides next action
Your agent logic decides what should happen next.
7
Handler sends reply or signals
8
Novu delivers the reply
The agent response is posted back to the original provider thread.
9
Novu records conversation state
Novu records messages, participants, metadata, signals, and conversation status.
onMessage
onMessage fires every time a user sends a message in a conversation with your agent.
Handling attachments
Inbound messages can include file attachments when the platform supports them. Novu normalizes files intomessage.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.
onAction
onAction fires when a user clicks a button or selects a value in an interactive card. See Interactive cards.
onReaction
onReaction fires when a user adds or removes an emoji reaction on a message.
onResolve
onResolve fires when the conversation is marked as resolved via ctx.resolve() or the resolve signal.
Related
Reply
Send plain text, markdown, attachments, and interactive cards.
Edit sent messages
Update a message in place after sending it with
ReplyHandle.Connect your first agent
Walk through a full support-bot handler file.