Skip to content

Commit de59711

Browse files
committed
gm comments
1 parent a1f629f commit de59711

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

examples/gm/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
This agent replies `gm`
44

5-
> Try XMTP using [xmtp.chat](https://xmtp.chat)
5+
> Try XMTP using [xmtp.chat](https://xmtp.chat) and sending a message to `gm.xmtp.eth`
66
77
![](/media/gm.png)
88

examples/gm/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,32 @@ if (!ENCRYPTION_KEY) {
1111
throw new Error("ENCRYPTION_KEY must be set");
1212
}
1313

14+
/* Create the signer using viem and parse the encryption key for the local db */
1415
const signer = createSigner(WALLET_KEY);
1516
const encryptionKey = getEncryptionKeyFromHex(ENCRYPTION_KEY);
1617

18+
/* Set the environment to dev or production */
1719
const env: XmtpEnv = "dev";
1820

1921
async function main() {
2022
console.log(`Creating client on the '${env}' network...`);
23+
/* Initialize the xmtp client */
2124
const client = await Client.create(signer, encryptionKey, { env });
2225

2326
console.log("Syncing conversations...");
27+
/* Sync the conversations from the network to update the local db */
2428
await client.conversations.sync();
2529

2630
console.log(
2731
`Agent initialized on ${client.accountAddress}\nSend a message on http://xmtp.chat/dm/${client.accountAddress}?env=${env}`,
2832
);
2933

3034
console.log("Waiting for messages...");
35+
/* Stream all messages from the network */
3136
const stream = client.conversations.streamAllMessages();
3237

3338
for await (const message of await stream) {
39+
/* Ignore messages from the same account or non-text messages */
3440
if (
3541
message?.senderInboxId.toLowerCase() === client.inboxId.toLowerCase() ||
3642
message?.contentType?.typeId !== "text"
@@ -42,6 +48,7 @@ async function main() {
4248
`Received message: ${message.content as string} by ${message.senderInboxId}`,
4349
);
4450

51+
/* Get the conversation by id */
4552
const conversation = client.conversations.getConversationById(
4653
message.conversationId,
4754
);
@@ -52,6 +59,7 @@ async function main() {
5259
}
5360

5461
console.log(`Sending "gm" response...`);
62+
/* Send a message to the conversation */
5563
await conversation.send("gm");
5664

5765
console.log("Waiting for messages...");

0 commit comments

Comments
 (0)