Skip to content

Commit 22d77de

Browse files
committed
removed obvious comments
1 parent 5bb1063 commit 22d77de

File tree

5 files changed

+10
-36
lines changed

5 files changed

+10
-36
lines changed

examples/gated-group/index.ts

+4-16
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Client, type XmtpEnv } from "@xmtp/node-sdk";
22
import { Alchemy, Network } from "alchemy-sdk";
33
import { createSigner, getEncryptionKeyFromHex } from "@/helpers";
44

5-
/* Set the Alchemy API key and network */
65
const settings = {
76
apiKey: process.env.ALCHEMY_API_KEY,
87
network: Network.BASE_MAINNET,
@@ -28,26 +27,20 @@ const encryptionKey = getEncryptionKeyFromHex(ENCRYPTION_KEY);
2827
/* Set the environment to dev or production */
2928
const env: XmtpEnv = "dev";
3029

31-
/**
32-
* Main function to run the agent
33-
*/
3430
async function main() {
3531
console.log(`Creating client on the '${env}' network...`);
36-
/* Initialize the xmtp client */
3732
const client = await Client.create(signer, encryptionKey, {
3833
env,
3934
});
4035

4136
console.log("Syncing conversations...");
42-
/* Sync the conversations from the network to update the local db */
4337
await client.conversations.sync();
4438

4539
console.log(
4640
`Agent initialized on ${client.accountAddress}\nSend a message on http://xmtp.chat/dm/${client.accountAddress}`,
4741
);
4842

4943
console.log("Waiting for messages...");
50-
/* Stream all messages from the network */
5144
const stream = client.conversations.streamAllMessages();
5245

5346
for await (const message of await stream) {
@@ -63,7 +56,6 @@ async function main() {
6356
`Received message: ${message.content as string} by ${message.senderInboxId}`,
6457
);
6558

66-
/* Get the conversation from the local db */
6759
const conversation = client.conversations.getConversationById(
6860
message.conversationId,
6961
);
@@ -73,9 +65,11 @@ async function main() {
7365
continue;
7466
}
7567

76-
/* If the message is to create a new group */
68+
/* This example works by parsing slash commands to create a new group or add a member to a group
69+
* /create - create a new group
70+
* /add <group_id> <wallet_address> - add a member to a group */
71+
7772
if (message.content === "/create") {
78-
/* Create a new group */
7973
console.log("Creating group");
8074
const group = await client.conversations.newGroup([]);
8175
console.log("Group created", group.id);
@@ -99,38 +93,32 @@ async function main() {
9993
typeof message.content === "string" &&
10094
message.content.startsWith("/add")
10195
) {
102-
/* Extract the group id and wallet address from the message */
10396
const groupId = message.content.split(" ")[1];
10497
if (!groupId) {
10598
await conversation.send("Please provide a group id");
10699
return;
107100
}
108-
/* Get the group from the local db */
109101
const group = client.conversations.getConversationById(groupId);
110102
if (!group) {
111103
await conversation.send("Please provide a valid group id");
112104
return;
113105
}
114-
/* Extract the wallet address from the message */
115106
const walletAddress = message.content.split(" ")[2];
116107
if (!walletAddress) {
117108
await conversation.send("Please provide a wallet address");
118109
return;
119110
}
120-
/* Check if the user has the NFT */
121111
const result = await checkNft(walletAddress, "XMTPeople");
122112
if (!result) {
123113
console.log("User can't be added to the group");
124114
return;
125115
} else {
126-
/* Add the user to the group */
127116
await group.addMembers([walletAddress]);
128117
await conversation.send(
129118
`User added to the group\n- Group ID: ${groupId}\n- Wallet Address: ${walletAddress}`,
130119
);
131120
}
132121
} else {
133-
/* Send a welcome message to the user */
134122
await conversation.send(
135123
"👋 Welcome to the Gated Bot Group!\nTo get started, type /create to set up a new group. 🚀\nThis example will check if the user has a particular nft and add them to the group if they do.\nOnce your group is created, you'll receive a unique Group ID and URL.\nShare the URL with friends to invite them to join your group!",
136124
);

examples/gm/README.md

-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ 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 */
2625
const signer = createSigner(WALLET_KEY);
2726
const encryptionKey = getEncryptionKeyFromHex(ENCRYPTION_KEY);
2827

@@ -31,7 +30,6 @@ const env: XmtpEnv = "dev";
3130

3231
async function main() {
3332
console.log(`Creating client on the '${env}' network...`);
34-
/* Initialize the xmtp client */
3533
const client = await Client.create(signer, encryptionKey, { env });
3634

3735
console.log("Syncing conversations...");
@@ -43,7 +41,6 @@ async function main() {
4341
);
4442

4543
console.log("Waiting for messages...");
46-
/* Stream all messages from the network */
4744
const stream = client.conversations.streamAllMessages();
4845

4946
for await (const message of await stream) {
@@ -59,7 +56,6 @@ async function main() {
5956
`Received message: ${message.content as string} by ${message.senderInboxId}`,
6057
);
6158

62-
/* Get the conversation by id */
6359
const conversation = client.conversations.getConversationById(
6460
message.conversationId,
6561
);
@@ -70,7 +66,6 @@ async function main() {
7066
}
7167

7268
console.log(`Sending "gm" response...`);
73-
/* Send a message to the conversation */
7469
await conversation.send("gm");
7570

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

examples/gm/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { Client, type XmtpEnv } from "@xmtp/node-sdk";
22
import { createSigner, getEncryptionKeyFromHex } from "@/helpers";
33

4+
/* Get the wallet key associated to the public key of
5+
* the agent and the encryption key for the local db
6+
* that stores your agent's messages */
47
const { WALLET_KEY, ENCRYPTION_KEY } = process.env;
58

69
if (!WALLET_KEY) {

examples/gpt/README.md

-15
Original file line numberDiff line numberDiff line change
@@ -30,37 +30,27 @@ import { createSigner, getEncryptionKeyFromHex } from "@/helpers";
3030

3131
const { WALLET_KEY, ENCRYPTION_KEY, OPENAI_API_KEY } = process.env;
3232

33-
/* Check if the environment variables are set */
3433
if (!WALLET_KEY) {
3534
throw new Error("WALLET_KEY must be set");
3635
}
3736

38-
/* Check if the encryption key is set */
3937
if (!ENCRYPTION_KEY) {
4038
throw new Error("ENCRYPTION_KEY must be set");
4139
}
4240

43-
/* Check if the OpenAI API key is set */
4441
if (!OPENAI_API_KEY) {
4542
throw new Error("OPENAI_API_KEY must be set");
4643
}
4744

48-
/* Create the signer using viem and parse the encryption key for the local db */
4945
const signer = createSigner(WALLET_KEY);
5046
const encryptionKey = getEncryptionKeyFromHex(ENCRYPTION_KEY);
51-
52-
/* Initialize the OpenAI client */
5347
const openai = new OpenAI({ apiKey: OPENAI_API_KEY });
5448

5549
/* Set the environment to dev or production */
5650
const env: XmtpEnv = "dev";
5751

58-
/**
59-
* Main function to run the agent
60-
*/
6152
async function main() {
6253
console.log(`Creating client on the '${env}' network...`);
63-
/* Initialize the xmtp client */
6454
const client = await Client.create(signer, encryptionKey, {
6555
env,
6656
});
@@ -74,7 +64,6 @@ async function main() {
7464
);
7565

7666
console.log("Waiting for messages...");
77-
/* Stream all messages from the network */
7867
const stream = client.conversations.streamAllMessages();
7968

8069
for await (const message of await stream) {
@@ -90,19 +79,16 @@ async function main() {
9079
`Received message: ${message.content as string} by ${message.senderInboxId}`,
9180
);
9281

93-
/* Get the conversation from the local db */
9482
const conversation = client.conversations.getConversationById(
9583
message.conversationId,
9684
);
9785

98-
/* If the conversation is not found, skip the message */
9986
if (!conversation) {
10087
console.log("Unable to find conversation, skipping");
10188
continue;
10289
}
10390

10491
try {
105-
/* Get the AI response */
10692
const completion = await openai.chat.completions.create({
10793
messages: [{ role: "user", content: message.content as string }],
10894
model: "gpt-3.5-turbo",
@@ -114,7 +100,6 @@ async function main() {
114100
"I'm not sure how to respond to that.";
115101

116102
console.log(`Sending AI response: ${response}`);
117-
/* Send the AI response to the conversation */
118103
await conversation.send(response);
119104
} catch (error) {
120105
console.error("Error getting AI response:", error);

examples/gpt/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { Client, type XmtpEnv } from "@xmtp/node-sdk";
22
import OpenAI from "openai";
33
import { createSigner, getEncryptionKeyFromHex } from "@/helpers";
44

5+
/* Get the wallet key associated to the public key of
6+
* the agent and the encryption key for the local db
7+
* that stores your agent's messages */
58
const { WALLET_KEY, ENCRYPTION_KEY, OPENAI_API_KEY } = process.env;
69

710
/* Check if the environment variables are set */

0 commit comments

Comments
 (0)