packages/novu/src/commands/init/templates/app-agent/ts/README-template.md
A conversational AI agent powered by Novu and Next.js.
Start the development server:
npm run dev
Connect a chat platform in the Novu Dashboard.
Replace the demo handler in app/novu/agents/support-agent.tsx with your LLM call.
Your agent is served at /api/novu and handles incoming messages via the Novu Bridge protocol.
app/
api/novu/route.ts → Bridge endpoint serving your agent
novu/agents/
index.ts → Agent exports
support-agent.tsx → Your agent handler (edit this!)
page.tsx → Landing page
Your onMessage handler is called with (message, ctx):
message — The inbound message (text, author, timestamp)| Method / Property | Description |
|---|---|
ctx.conversation | Current conversation state and metadata |
ctx.history | Recent conversation history |
ctx.subscriber | Resolved subscriber info |
ctx.platform | Source platform (slack, teams, whatsapp) |
ctx.reply(content) | Send a reply (text, Markdown, or Card) |
ctx.metadata.set(k, v) | Set conversation metadata |
ctx.resolve(summary?) | Mark conversation as resolved |
ctx.trigger(workflowId) | Trigger a Novu workflow |
Replace the demo handler in app/novu/agents/support-agent.tsx with your LLM call:
onMessage: async (message, ctx) => {
const response = await openai.chat.completions.create({
model: 'gpt-4',
messages: [
{ role: 'system', content: 'You are a helpful support agent.' },
...ctx.history.map((h) => ({ role: h.role, content: h.content })),
{ role: 'user', content: message.text },
],
});
await ctx.reply(response.choices[0].message.content ?? '');
},