Skip to content

Commit 57a90a4

Browse files
authored
readme improvements (#24)
1 parent c953fe4 commit 57a90a4

File tree

3 files changed

+30
-35
lines changed

3 files changed

+30
-35
lines changed

examples/gated-group/README.md

+29-34
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
To create a gated group chat using XMTP, you will need an admin bot within the group to manage member additions and removals. The admin bot will create the group, assign you as the admin, and then verify NFT ownership before adding new members.
44

5+
![](/media/gated.png)
6+
57
#### Environment variables
68

79
```bash
@@ -26,45 +28,38 @@ yarn gen:keys
2628
Start your XMTP client and begin listening to messages. The bot responds to the following commands:
2729

2830
- `/create` - Creates a new gated group
29-
- `/add <wallet_address> <group_id>` - Adds a wallet to an existing group (if they own the required NFT)
3031

3132
```tsx
32-
const client = await Client.create(signer, encryptionKey, {
33-
env,
34-
});
35-
36-
// Listen for messages
37-
const stream = client.conversations.streamAllMessages();
33+
if (message.content === "/create") {
34+
console.log("Creating group");
35+
const group = await client.conversations.newGroup([]);
36+
await group.addMembersByInboxId([message.senderInboxId]);
37+
await group.addSuperAdmin(message.senderInboxId);
38+
39+
await conversation.send(
40+
`Group created!\n- ID: ${group.id}\n- Group URL: https://xmtp.chat/conversations/${group.id}`,
41+
);
42+
return;
43+
}
44+
```
3845

39-
for await (const message of await stream) {
40-
// Handle /create command
41-
if (message.content === "/create") {
42-
console.log("Creating group");
43-
const group = await client.conversations.newGroup([]);
44-
await group.addMembersByInboxId([message.senderInboxId]);
45-
await group.addSuperAdmin(message.senderInboxId);
46+
- `/add <group_id> <wallet_address>` - Adds a wallet to an existing group (if they own the required NFT)
4647

48+
```tsx
49+
// Handle /add command
50+
if (message.content.startsWith("/add")) {
51+
const groupId = message.content.split(" ")[1];
52+
const walletAddress = message.content.split(" ")[2];
53+
54+
const result = await checkNft(walletAddress, "XMTPeople");
55+
if (!result) {
56+
console.log("User can't be added to the group");
57+
return;
58+
} else {
59+
await group.addMembers([walletAddress]);
4760
await conversation.send(
48-
`Group created!\n- ID: ${group.id}\n- Group URL: https://xmtp.chat/conversations/${group.id}`,
61+
`User added to the group\n- Group ID: ${groupId}\n- Wallet Address: ${walletAddress}`,
4962
);
50-
return;
51-
}
52-
53-
// Handle /add command
54-
if (message.content.startsWith("/add")) {
55-
const walletAddress = message.content.split(" ")[1];
56-
const groupId = message.content.split(" ")[2];
57-
58-
const result = await checkNft(walletAddress, "XMTPeople");
59-
if (!result) {
60-
console.log("User can't be added to the group");
61-
return;
62-
} else {
63-
await group.addMembers([walletAddress]);
64-
await conversation.send(
65-
`User added to the group\n- Group ID: ${groupId}\n- Wallet Address: ${walletAddress}`,
66-
);
67-
}
6863
}
6964
}
7065
```
@@ -99,7 +94,7 @@ async function checkNft(
9994

10095
1. Start the bot with your environment variables configured
10196
2. Message the bot at its address to create a new group using `/create`
102-
3. Once you have the group ID, you can add members using `/add <wallet_address> <group_id>`
97+
3. Once you have the group ID, you can add members using `/add <group_id> <wallet_address>`
10398
4. The bot will verify NFT ownership and add the wallet if they own the required NFT
10499

105100
The bot will automatically make the group creator a super admin and can optionally make new members admins as well.

examples/gated-group/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ async function main() {
8383
);
8484

8585
await conversation.send(
86-
`Group created!\n- ID: ${group.id}\n- Group URL: https://xmtp.chat/conversations/${group.id}: \n- This url will deeplink to the group created\n- Once in the other group you can share the invite with your friends.\n- You can add more members to the group by using the /add <group.id> <wallet-address>.`,
86+
`Group created!\n- ID: ${group.id}\n- Group URL: https://xmtp.chat/conversations/${group.id}: \n- This url will deeplink to the group created\n- Once in the other group you can share the invite with your friends.\n- You can add more members to the group by using the /add <group_id> <wallet_address>.`,
8787
);
8888
return;
8989
} else if (

media/gated.png

1 MB
Loading

0 commit comments

Comments
 (0)