Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions apps/api/src/app/agents/e2e/mock-agent-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if (!NOVU_SECRET_KEY) {
}

const echoBot = agent('novu-agent', {
onMessage: async ({ message, ctx }) => {
onMessage: async (message, ctx) => {
console.log('\n─────────────────────────────────────────');
console.log(`[onMessage] from ${ctx.subscriber?.firstName ?? 'unknown'} on ${ctx.platform}`);
console.log(`Message: ${message.text ?? '(none)'}`);
Expand Down Expand Up @@ -128,12 +128,12 @@ const echoBot = agent('novu-agent', {
await ctx.reply(`Echo: ${userText}`);
},

onAction: async ({ actionId, value, ctx }) => {
onAction: async (action, ctx) => {
console.log('\n─────────────────────────────────────────');
console.log(`[onAction] action: ${actionId} = ${value ?? '(no value)'}`);
console.log(`[onAction] action: ${action.actionId} = ${action.value ?? '(no value)'}`);
console.log('─────────────────────────────────────────');

if (actionId === 'ack') {
if (action.actionId === 'ack') {
await ctx.reply(
Card({
title: 'Incident Acknowledged',
Expand All @@ -145,21 +145,21 @@ const echoBot = agent('novu-agent', {
],
})
);
} else if (actionId === 'resolve') {
} else if (action.actionId === 'resolve') {
ctx.resolve('Incident resolved via action');
await ctx.reply(`Incident resolved by *${ctx.subscriber?.firstName ?? 'unknown'}*.`);
} else if (actionId === 'assign') {
await ctx.reply(`On-call assignment updated to *${value}*.`);
} else if (actionId === 'escalate') {
} else if (action.actionId === 'assign') {
await ctx.reply(`On-call assignment updated to *${action.value}*.`);
} else if (action.actionId === 'escalate') {
await ctx.reply(
`**Escalated** — paging the secondary on-call team.\n\n_Triggered by ${ctx.subscriber?.firstName ?? 'unknown'}_`
);
} else {
await ctx.reply(`Got action: *${actionId}*${value ? ` = ${value}` : ''}`);
await ctx.reply(`Got action: *${action.actionId}*${action.value ? ` = ${action.value}` : ''}`);
}
},

onResolve: async ({ ctx }) => {
onResolve: async (ctx) => {
console.log(`\n[onResolve] Conversation ${ctx.conversation.identifier} closed.`);
ctx.metadata.set('resolvedAt', new Date().toISOString());
},
Expand Down
22 changes: 4 additions & 18 deletions packages/framework/src/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,40 +324,26 @@ export class NovuRequestHandler<Input extends any[] = any[], Output = any> {
switch (event) {
case AgentEventEnum.ON_MESSAGE:
await replyIfPresent(
await registeredAgent.handlers.onMessage({
message: ctx.message!,
ctx: ctx as unknown as AgentMessageContext,
})
await registeredAgent.handlers.onMessage(ctx.message!, ctx as unknown as AgentMessageContext)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
);
break;
case AgentEventEnum.ON_ACTION:
if (registeredAgent.handlers.onAction) {
await replyIfPresent(
await registeredAgent.handlers.onAction({
actionId: ctx.action!.actionId,
value: ctx.action!.value,
ctx: ctx as unknown as AgentActionContext,
})
await registeredAgent.handlers.onAction(ctx.action!, ctx as unknown as AgentActionContext)
);
}
break;
case AgentEventEnum.ON_REACTION:
if (registeredAgent.handlers.onReaction) {
await replyIfPresent(
await registeredAgent.handlers.onReaction({
reaction: ctx.reaction!,
ctx: ctx as unknown as AgentReactionContext,
})
await registeredAgent.handlers.onReaction(ctx.reaction!, ctx as unknown as AgentReactionContext)
);
}
break;
case AgentEventEnum.ON_RESOLVE:
if (registeredAgent.handlers.onResolve) {
await replyIfPresent(
await registeredAgent.handlers.onResolve({
ctx: ctx as unknown as AgentResolveContext,
})
);
await replyIfPresent(await registeredAgent.handlers.onResolve(ctx as unknown as AgentResolveContext));
}
break;
default:
Expand Down
Loading
Loading