Skip to content

Commit 86c7647

Browse files
authored
Enhance bot response details (#1632)
* Enable agent sync start * Enhance bot response details * Refactor message body creation
1 parent 19523ba commit 86c7647

File tree

4 files changed

+26
-11
lines changed

4 files changed

+26
-11
lines changed

agents/bots/gm/index.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getMessageBody } from "@agents/helper";
12
import { Agent, getTestUrl, logDetails } from "@agents/versions";
23
import { APP_VERSION } from "@helpers/client";
34
import { getSDKVersionInfo } from "@helpers/versions";
@@ -15,13 +16,12 @@ const agent = await Agent.createFromEnv({
1516
});
1617

1718
agent.on("text", async (ctx) => {
19+
const messageBody1 = await getMessageBody(ctx);
1820
if (ctx.isDm()) {
19-
const messageContent = ctx.message.content;
20-
const senderAddress = await ctx.getSenderAddress();
21-
console.log(`Received message: ${messageContent} by ${senderAddress}`);
22-
await ctx.sendText("gm local " + ctx.conversation.id);
23-
} else if (ctx.isGroup() && ctx.message.content.includes("@gm"))
24-
await ctx.sendText("gm local " + ctx.conversation.id);
21+
await ctx.sendText(messageBody1);
22+
} else if (ctx.isGroup() && ctx.message.content.includes("@gm")) {
23+
await ctx.sendText(messageBody1);
24+
}
2525
});
2626

2727
agent.on("start", () => {

agents/bots/key-check/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getMessageBody } from "@agents/helper";
12
import {
23
ActionBuilder,
34
initializeAppFromConfig,
@@ -332,17 +333,15 @@ appConfig.menus["load-test-menu"].actions.forEach((action: MenuAction) => {
332333
initializeAppFromConfig(appConfig);
333334

334335
agent.on("text", async (ctx) => {
335-
console.log(
336-
`Received text message in group (${ctx.conversation.id}): ${ctx.message.content} by ${await ctx.getSenderAddress()}`,
337-
);
338-
336+
const messageBody1 = await getMessageBody(ctx);
339337
const message = ctx.message;
340338
const content = message.content;
341339
const isTagged =
342340
content.trim().startsWith("@kc") ||
343341
content.trim().startsWith("/kc") ||
344342
content.trim().startsWith("@key-check.eth");
345343
if (isTagged) {
344+
await ctx.sendText(messageBody1);
346345
await showMenu(ctx, appConfig, "main-menu");
347346
return;
348347
}

agents/helper.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { type DecodedMessage } from "@helpers/versions";
2+
import type { MessageContext } from "@xmtp/agent-sdk";
23

34
/**
45
* Agent configuration interface
@@ -18,6 +19,21 @@ export interface AgentConfig {
1819
live: boolean;
1920
}
2021

22+
export async function getMessageBody(ctx: MessageContext) {
23+
try {
24+
const messageContent = ctx.message.content as string;
25+
const senderAddress = (await ctx.getSenderAddress()) as string;
26+
27+
const messageBody1 = `replying content: ${messageContent} sent by ${senderAddress} on ${ctx.message.sentAt.toISOString()} on converstion ${ctx.conversation.id}`;
28+
29+
console.log(messageBody1);
30+
return messageBody1;
31+
} catch (error) {
32+
console.error("Error getting message body", error);
33+
return "Error getting message body";
34+
}
35+
}
36+
2137
/**
2238
* Options for waitForResponse function
2339
*/

deploy-metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"deployedAt": "2025-11-25T17:15:39Z", "version": "0.5.0"}
1+
{"deployedAt": "2025-11-25T17:15:39Z", "version": "0.5.1"}

0 commit comments

Comments
 (0)