Skip to content

Commit 3c554b3

Browse files
committed
gm comments
1 parent de59711 commit 3c554b3

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

examples/gm/README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This agent replies `gm`
66
77
![](/media/gm.png)
88

9-
## Basic usage
9+
## Overview
1010

1111
```tsx
1212
import { Client, type XmtpEnv } from "@xmtp/node-sdk";
@@ -22,26 +22,32 @@ if (!ENCRYPTION_KEY) {
2222
throw new Error("ENCRYPTION_KEY must be set");
2323
}
2424

25+
/* Create the signer using viem and parse the encryption key for the local db */
2526
const signer = createSigner(WALLET_KEY);
2627
const encryptionKey = getEncryptionKeyFromHex(ENCRYPTION_KEY);
2728

29+
/* Set the environment to dev or production */
2830
const env: XmtpEnv = "dev";
2931

3032
async function main() {
3133
console.log(`Creating client on the '${env}' network...`);
34+
/* Initialize the xmtp client */
3235
const client = await Client.create(signer, encryptionKey, { env });
3336

3437
console.log("Syncing conversations...");
38+
/* Sync the conversations from the network to update the local db */
3539
await client.conversations.sync();
3640

3741
console.log(
3842
`Agent initialized on ${client.accountAddress}\nSend a message on http://xmtp.chat/dm/${client.accountAddress}?env=${env}`,
3943
);
4044

4145
console.log("Waiting for messages...");
46+
/* Stream all messages from the network */
4247
const stream = client.conversations.streamAllMessages();
4348

4449
for await (const message of await stream) {
50+
/* Ignore messages from the same agent or non-text messages */
4551
if (
4652
message?.senderInboxId.toLowerCase() === client.inboxId.toLowerCase() ||
4753
message?.contentType?.typeId !== "text"
@@ -53,6 +59,7 @@ async function main() {
5359
`Received message: ${message.content as string} by ${message.senderInboxId}`,
5460
);
5561

62+
/* Get the conversation by id */
5663
const conversation = client.conversations.getConversationById(
5764
message.conversationId,
5865
);
@@ -63,6 +70,7 @@ async function main() {
6370
}
6471

6572
console.log(`Sending "gm" response...`);
73+
/* Send a message to the conversation */
6674
await conversation.send("gm");
6775

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

examples/gm/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async function main() {
3636
const stream = client.conversations.streamAllMessages();
3737

3838
for await (const message of await stream) {
39-
/* Ignore messages from the same account or non-text messages */
39+
/* Ignore messages from the same agent or non-text messages */
4040
if (
4141
message?.senderInboxId.toLowerCase() === client.inboxId.toLowerCase() ||
4242
message?.contentType?.typeId !== "text"

0 commit comments

Comments
 (0)