create-message-kit 1.2.4 → 1.2.7
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +40 -27
- package/package.json +1 -1
- package/templates/agent/.cursorrules +227 -0
- package/templates/agent/src/index.ts +18 -25
- package/templates/agent/src/prompt.ts +1 -1
- package/templates/agent/src/{handlers → skills}/check.ts +5 -4
- package/templates/agent/src/{handlers → skills}/cool.ts +1 -1
- package/templates/agent/src/{handlers → skills}/game.ts +1 -1
- package/templates/agent/src/{handlers → skills}/info.ts +6 -5
- package/templates/agent/src/{handlers → skills}/pay.ts +20 -5
- package/templates/agent/src/{handlers → skills}/register.ts +2 -3
- package/templates/agent/src/{handlers → skills}/renew.ts +5 -4
- package/templates/agent/src/skills/reset.ts +26 -0
- package/templates/experimental/.cursorrules +227 -0
- package/templates/experimental/.env.example +2 -0
- package/templates/{gated → experimental}/package.json +5 -4
- package/templates/experimental/src/index.ts +41 -0
- package/templates/{gated/src/lib/nft.ts → experimental/src/lib/alchemy.ts} +4 -10
- package/templates/experimental/src/lib/xmtp.ts +138 -0
- package/templates/experimental/src/prompt.ts +24 -0
- package/templates/experimental/src/skills/broadcast.ts +38 -0
- package/templates/experimental/src/skills/gated.ts +100 -0
- package/templates/{agent/src/handlers → experimental/src/skills}/todo.ts +11 -5
- package/templates/{agent/src/handlers → experimental/src/skills}/token.ts +1 -1
- package/templates/gpt/.cursorrules +227 -0
- package/templates/gpt/src/index.ts +1 -0
- package/templates/agent/src/handlers/reset.ts +0 -19
- package/templates/gated/.env.example +0 -3
- package/templates/gated/src/index.ts +0 -64
- package/templates/gated/src/lib/gated.ts +0 -51
- package/templates/gated/src/skills.ts +0 -23
- /package/templates/{gated → experimental}/.yarnrc.yml +0 -0
@@ -0,0 +1,227 @@
|
|
1
|
+
# MessageKit Skill Template
|
2
|
+
|
3
|
+
## Examples
|
4
|
+
|
5
|
+
### Check if a Domain is Available
|
6
|
+
|
7
|
+
```typescript
|
8
|
+
import { ensUrl } from "../index.js";
|
9
|
+
import { XMTPContext } from "@xmtp/message-kit";
|
10
|
+
import type { Skill } from "@xmtp/message-kit";
|
11
|
+
|
12
|
+
// Define Skill
|
13
|
+
export const checkDomain: Skill[] = [
|
14
|
+
{
|
15
|
+
skill: "/check [domain]",
|
16
|
+
handler: handler,
|
17
|
+
examples: ["/check vitalik.eth", "/check fabri.base.eth"],
|
18
|
+
description: "Check if a domain is available.",
|
19
|
+
params: {
|
20
|
+
domain: {
|
21
|
+
type: "string",
|
22
|
+
},
|
23
|
+
},
|
24
|
+
},
|
25
|
+
];
|
26
|
+
|
27
|
+
// Handler Implementation
|
28
|
+
export async function handler(context: XMTPContext) {
|
29
|
+
const {
|
30
|
+
message: {
|
31
|
+
content: {
|
32
|
+
params: { domain },
|
33
|
+
},
|
34
|
+
},
|
35
|
+
} = context;
|
36
|
+
|
37
|
+
const data = await context.getUserInfo(domain);
|
38
|
+
|
39
|
+
if (!data?.address) {
|
40
|
+
let message = `Looks like ${domain} is available! Here you can register it: ${ensUrl}${domain} or would you like to see some cool alternatives?`;
|
41
|
+
return {
|
42
|
+
code: 200,
|
43
|
+
message,
|
44
|
+
};
|
45
|
+
} else {
|
46
|
+
let message = `Looks like ${domain} is already registered!`;
|
47
|
+
await context.executeSkill("/cool " + domain);
|
48
|
+
return {
|
49
|
+
code: 404,
|
50
|
+
message,
|
51
|
+
};
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
### Generate a payment request
|
56
|
+
|
57
|
+
```typescript
|
58
|
+
import { XMTPContext } from "@xmtp/message-kit";
|
59
|
+
import type { Skill } from "@xmtp/message-kit";
|
60
|
+
|
61
|
+
// Define Skill
|
62
|
+
export const paymentRequest: Skill[] = [
|
63
|
+
{
|
64
|
+
skill: "/pay [amount] [token] [username] [address]",
|
65
|
+
examples: [
|
66
|
+
"/pay 10 vitalik.eth",
|
67
|
+
"/pay 1 usdc to 0xc9925662D36DE3e1bF0fD64e779B2e5F0Aead964",
|
68
|
+
],
|
69
|
+
description:
|
70
|
+
"Send a specified amount of a cryptocurrency to a destination address. \nWhen tipping, you can assume it's 1 USDC.",
|
71
|
+
handler: handler,
|
72
|
+
params: {
|
73
|
+
amount: {
|
74
|
+
default: 10,
|
75
|
+
type: "number",
|
76
|
+
},
|
77
|
+
token: {
|
78
|
+
default: "usdc",
|
79
|
+
type: "string",
|
80
|
+
values: ["eth", "dai", "usdc", "degen"], // Accepted tokens
|
81
|
+
},
|
82
|
+
username: {
|
83
|
+
default: "",
|
84
|
+
type: "username",
|
85
|
+
},
|
86
|
+
address: {
|
87
|
+
default: "",
|
88
|
+
type: "address",
|
89
|
+
},
|
90
|
+
},
|
91
|
+
},
|
92
|
+
];
|
93
|
+
|
94
|
+
// Handler Implementation
|
95
|
+
export async function handler(context: XMTPContext) {
|
96
|
+
const {
|
97
|
+
message: {
|
98
|
+
content: {
|
99
|
+
params: { amount, token, username, address },
|
100
|
+
},
|
101
|
+
},
|
102
|
+
} = context;
|
103
|
+
let receiverAddress = address;
|
104
|
+
if (username) {
|
105
|
+
receiverAddress = (await context.getUserInfo(username))?.address;
|
106
|
+
}
|
107
|
+
if (address) {
|
108
|
+
// Prioritize address over username
|
109
|
+
receiverAddress = address;
|
110
|
+
}
|
111
|
+
|
112
|
+
await context.requestPayment(amount, token, receiverAddress);
|
113
|
+
}
|
114
|
+
```
|
115
|
+
|
116
|
+
|
117
|
+
## Types
|
118
|
+
|
119
|
+
```typescript
|
120
|
+
import { XMTPContext } from "../lib/xmtp.js";
|
121
|
+
import { ClientOptions, GroupMember } from "@xmtp/node-sdk";
|
122
|
+
import { ContentTypeId } from "@xmtp/content-type-primitives";
|
123
|
+
|
124
|
+
export type MessageAbstracted = {
|
125
|
+
id: string;
|
126
|
+
sent: Date;
|
127
|
+
content: {
|
128
|
+
text?: string | undefined;
|
129
|
+
reply?: string | undefined;
|
130
|
+
previousMsg?: string | undefined;
|
131
|
+
react?: string | undefined;
|
132
|
+
content?: any | undefined;
|
133
|
+
params?: any | undefined;
|
134
|
+
reference?: string | undefined;
|
135
|
+
skill?: string | undefined;
|
136
|
+
};
|
137
|
+
version: "v2" | "v3";
|
138
|
+
sender: AbstractedMember;
|
139
|
+
typeId: string;
|
140
|
+
};
|
141
|
+
export type GroupAbstracted = {
|
142
|
+
id: string;
|
143
|
+
sync: () => Promise<void>;
|
144
|
+
addMembers: (addresses: string[]) => Promise<void>;
|
145
|
+
addMembersByInboxId: (inboxIds: string[]) => Promise<void>;
|
146
|
+
send: (content: string, contentType?: ContentTypeId) => Promise<string>;
|
147
|
+
isAdmin: (inboxId: string) => boolean;
|
148
|
+
isSuperAdmin: (inboxId: string) => boolean;
|
149
|
+
admins: string[];
|
150
|
+
superAdmins: string[];
|
151
|
+
createdAt: Date;
|
152
|
+
members: GroupMember[];
|
153
|
+
};
|
154
|
+
export type SkillResponse = {
|
155
|
+
code: number;
|
156
|
+
message: string;
|
157
|
+
data?: any;
|
158
|
+
};
|
159
|
+
|
160
|
+
export type SkillHandler = (
|
161
|
+
context: XMTPContext,
|
162
|
+
) => Promise<SkillResponse | void>;
|
163
|
+
|
164
|
+
export type Handler = (context: XMTPContext) => Promise<void>;
|
165
|
+
|
166
|
+
export type RunConfig = {
|
167
|
+
// client options from XMTP client
|
168
|
+
client?: ClientOptions;
|
169
|
+
// private key to be used for the client, if not, default from env
|
170
|
+
privateKey?: string;
|
171
|
+
// if true, the init log message with messagekit logo and stuff will be hidden
|
172
|
+
experimental?: boolean;
|
173
|
+
// hide the init log message with messagekit logo and stuff
|
174
|
+
hideInitLogMessage?: boolean;
|
175
|
+
// if true, attachments will be enabled
|
176
|
+
attachments?: boolean;
|
177
|
+
// if true, member changes will be enabled, like adding members to the group
|
178
|
+
memberChange?: boolean;
|
179
|
+
// skills to be used
|
180
|
+
agent?: Agent;
|
181
|
+
// model to be used
|
182
|
+
gptModel?: string;
|
183
|
+
};
|
184
|
+
export interface SkillParamConfig {
|
185
|
+
default?: string | number | boolean;
|
186
|
+
type:
|
187
|
+
| "number"
|
188
|
+
| "string"
|
189
|
+
| "username"
|
190
|
+
| "quoted"
|
191
|
+
| "address"
|
192
|
+
| "prompt"
|
193
|
+
| "url";
|
194
|
+
plural?: boolean;
|
195
|
+
values?: string[]; // Accepted values for the parameter
|
196
|
+
}
|
197
|
+
|
198
|
+
export interface Frame {
|
199
|
+
title: string;
|
200
|
+
buttons: { content: string; action: string; target: string }[];
|
201
|
+
image: string;
|
202
|
+
}
|
203
|
+
export interface Agent {
|
204
|
+
name: string;
|
205
|
+
description: string;
|
206
|
+
tag: string;
|
207
|
+
skills: Skill[];
|
208
|
+
}
|
209
|
+
export interface Skill {
|
210
|
+
skill: string;
|
211
|
+
handler?: SkillHandler | undefined;
|
212
|
+
adminOnly?: boolean;
|
213
|
+
description: string;
|
214
|
+
examples: string[];
|
215
|
+
params: Record<string, SkillParamConfig>;
|
216
|
+
}
|
217
|
+
|
218
|
+
export interface AbstractedMember {
|
219
|
+
inboxId: string;
|
220
|
+
address: string;
|
221
|
+
accountAddresses: string[];
|
222
|
+
installationIds?: string[];
|
223
|
+
}
|
224
|
+
|
225
|
+
export type MetadataValue = string | number | boolean;
|
226
|
+
export type Metadata = Record<string, MetadataValue | MetadataValue[]>;
|
227
|
+
```
|
@@ -1,5 +1,5 @@
|
|
1
1
|
{
|
2
|
-
"name": "
|
2
|
+
"name": "experimental",
|
3
3
|
"private": true,
|
4
4
|
"type": "module",
|
5
5
|
"scripts": {
|
@@ -9,11 +9,12 @@
|
|
9
9
|
},
|
10
10
|
"dependencies": {
|
11
11
|
"@xmtp/message-kit": "workspace:*",
|
12
|
-
"alchemy-sdk": "^3.
|
13
|
-
"express": "^4.19.2"
|
12
|
+
"alchemy-sdk": "^3.0.0",
|
13
|
+
"express": "^4.19.2",
|
14
|
+
"resend": "^4.0.1"
|
14
15
|
},
|
15
16
|
"devDependencies": {
|
16
|
-
"@types/express": "^4",
|
17
|
+
"@types/express": "^4.17.20",
|
17
18
|
"@types/node": "^20.14.2",
|
18
19
|
"typescript": "^5.4.5"
|
19
20
|
},
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import {
|
2
|
+
run,
|
3
|
+
agentReply,
|
4
|
+
replaceVariables,
|
5
|
+
XMTPContext,
|
6
|
+
Agent,
|
7
|
+
} from "@xmtp/message-kit";
|
8
|
+
import { systemPrompt } from "./prompt.js";
|
9
|
+
import fs from "fs";
|
10
|
+
//Local imports
|
11
|
+
import { token } from "./skills/token.js";
|
12
|
+
import { todo } from "./skills/todo.js";
|
13
|
+
import { gated } from "./skills/gated.js";
|
14
|
+
import { broadcast } from "./skills/broadcast.js";
|
15
|
+
|
16
|
+
export const agent: Agent = {
|
17
|
+
name: "Experimental Agent",
|
18
|
+
tag: "@exp",
|
19
|
+
description: "An experimental agent with a lot of skills.",
|
20
|
+
skills: [
|
21
|
+
...token,
|
22
|
+
...(process?.env?.RESEND_API_KEY ? todo : []),
|
23
|
+
...(process?.env?.ALCHEMY_SDK ? gated : []),
|
24
|
+
...broadcast,
|
25
|
+
],
|
26
|
+
};
|
27
|
+
run(
|
28
|
+
async (context: XMTPContext) => {
|
29
|
+
const {
|
30
|
+
message: { sender },
|
31
|
+
agent,
|
32
|
+
} = context;
|
33
|
+
|
34
|
+
let prompt = await replaceVariables(systemPrompt, sender.address, agent);
|
35
|
+
|
36
|
+
//This is only used for to update the docs.
|
37
|
+
fs.writeFileSync("example_prompt.md", prompt);
|
38
|
+
await agentReply(context, prompt);
|
39
|
+
},
|
40
|
+
{ agent },
|
41
|
+
);
|
@@ -5,27 +5,21 @@ const settings = {
|
|
5
5
|
network: Network.BASE_MAINNET, // Use the appropriate network
|
6
6
|
};
|
7
7
|
|
8
|
-
export async function
|
8
|
+
export async function checkNft(
|
9
9
|
walletAddress: string,
|
10
|
-
|
10
|
+
collectionSlug: string,
|
11
11
|
): Promise<boolean> {
|
12
|
-
console.log("new-request", {
|
13
|
-
groupId,
|
14
|
-
walletAddress,
|
15
|
-
});
|
16
|
-
|
17
12
|
const alchemy = new Alchemy(settings);
|
18
13
|
try {
|
19
14
|
const nfts = await alchemy.nft.getNftsForOwner(walletAddress);
|
20
|
-
const collectionSlug = "XMTPeople"; // The slug for the collection
|
21
15
|
|
22
16
|
const ownsNft = nfts.ownedNfts.some(
|
23
17
|
(nft: any) =>
|
24
|
-
nft.contract.name.toLowerCase() === collectionSlug.toLowerCase()
|
18
|
+
nft.contract.name.toLowerCase() === collectionSlug.toLowerCase(),
|
25
19
|
);
|
26
20
|
console.log(
|
27
21
|
`NFTs owned on ${Network.BASE_MAINNET}:`,
|
28
|
-
nfts.ownedNfts.length
|
22
|
+
nfts.ownedNfts.length,
|
29
23
|
);
|
30
24
|
console.log("is the nft owned: ", ownsNft);
|
31
25
|
return ownsNft as boolean;
|
@@ -0,0 +1,138 @@
|
|
1
|
+
import { isOnXMTP, V3Client, V2Client } from "@xmtp/message-kit";
|
2
|
+
|
3
|
+
export async function createGroup(
|
4
|
+
client: V3Client,
|
5
|
+
senderAddress: string,
|
6
|
+
clientAddress: string,
|
7
|
+
) {
|
8
|
+
try {
|
9
|
+
let senderInboxId = "";
|
10
|
+
await client.conversations.sync();
|
11
|
+
const conversations = await client.conversations.list();
|
12
|
+
console.log("Conversations", conversations.length);
|
13
|
+
const group = await client?.conversations.newGroup([
|
14
|
+
senderAddress,
|
15
|
+
clientAddress,
|
16
|
+
]);
|
17
|
+
console.log("Group created", group?.id);
|
18
|
+
const members = await group.members();
|
19
|
+
const senderMember = members.find((member) =>
|
20
|
+
member.accountAddresses.includes(senderAddress.toLowerCase()),
|
21
|
+
);
|
22
|
+
if (senderMember) {
|
23
|
+
const senderInboxId = senderMember.inboxId;
|
24
|
+
console.log("Sender's inboxId:", senderInboxId);
|
25
|
+
} else {
|
26
|
+
console.log("Sender not found in members list");
|
27
|
+
}
|
28
|
+
await group.addSuperAdmin(senderInboxId);
|
29
|
+
console.log(
|
30
|
+
"Sender is superAdmin",
|
31
|
+
await group.isSuperAdmin(senderInboxId),
|
32
|
+
);
|
33
|
+
await group.send(`Welcome to the new group!`);
|
34
|
+
await group.send(`You are now the admin of this group as well as the bot`);
|
35
|
+
return group;
|
36
|
+
} catch (error) {
|
37
|
+
console.log("Error creating group", error);
|
38
|
+
return null;
|
39
|
+
}
|
40
|
+
}
|
41
|
+
|
42
|
+
export async function removeFromGroup(
|
43
|
+
groupId: string,
|
44
|
+
client: V3Client,
|
45
|
+
v2client: V2Client,
|
46
|
+
senderAddress: string,
|
47
|
+
): Promise<{ code: number; message: string }> {
|
48
|
+
try {
|
49
|
+
let lowerAddress = senderAddress.toLowerCase();
|
50
|
+
const { v2, v3 } = await isOnXMTP(client, v2client, lowerAddress);
|
51
|
+
console.warn("Checking if on XMTP: v2", v2, "v3", v3);
|
52
|
+
if (!v3)
|
53
|
+
return {
|
54
|
+
code: 400,
|
55
|
+
message: "You don't seem to have a v3 identity ",
|
56
|
+
};
|
57
|
+
const conversation =
|
58
|
+
await client.conversations.getConversationById(groupId);
|
59
|
+
console.warn("removing from group", conversation?.id);
|
60
|
+
await conversation?.sync();
|
61
|
+
await conversation?.removeMembers([lowerAddress]);
|
62
|
+
console.warn("Removed member from group");
|
63
|
+
await conversation?.sync();
|
64
|
+
const members = await conversation?.members();
|
65
|
+
console.warn("Number of members", members?.length);
|
66
|
+
|
67
|
+
let wasRemoved = true;
|
68
|
+
if (members) {
|
69
|
+
for (const member of members) {
|
70
|
+
let lowerMemberAddress = member.accountAddresses[0].toLowerCase();
|
71
|
+
if (lowerMemberAddress === lowerAddress) {
|
72
|
+
wasRemoved = false;
|
73
|
+
break;
|
74
|
+
}
|
75
|
+
}
|
76
|
+
}
|
77
|
+
return {
|
78
|
+
code: wasRemoved ? 200 : 400,
|
79
|
+
message: wasRemoved
|
80
|
+
? "You have been removed from the group"
|
81
|
+
: "Failed to remove from group",
|
82
|
+
};
|
83
|
+
} catch (error) {
|
84
|
+
console.log("Error removing from group", error);
|
85
|
+
return {
|
86
|
+
code: 400,
|
87
|
+
message: "Failed to remove from group",
|
88
|
+
};
|
89
|
+
}
|
90
|
+
}
|
91
|
+
export async function addToGroup(
|
92
|
+
groupId: string,
|
93
|
+
client: V3Client,
|
94
|
+
v2client: V2Client,
|
95
|
+
senderAddress: string,
|
96
|
+
): Promise<{ code: number; message: string }> {
|
97
|
+
try {
|
98
|
+
let lowerAddress = senderAddress.toLowerCase();
|
99
|
+
const { v2, v3 } = await isOnXMTP(client, v2client, lowerAddress);
|
100
|
+
if (!v3)
|
101
|
+
return {
|
102
|
+
code: 400,
|
103
|
+
message: "You don't seem to have a v3 identity ",
|
104
|
+
};
|
105
|
+
const conversation =
|
106
|
+
await client.conversations.getConversationById(groupId);
|
107
|
+
console.warn("Adding to group", conversation?.id);
|
108
|
+
await conversation?.sync();
|
109
|
+
//DON'T TOUCH THIS LINE
|
110
|
+
await conversation?.addMembers([lowerAddress]);
|
111
|
+
console.warn("Added member to group");
|
112
|
+
await conversation?.sync();
|
113
|
+
const members = await conversation?.members();
|
114
|
+
console.warn("Number of members", members?.length);
|
115
|
+
|
116
|
+
if (members) {
|
117
|
+
for (const member of members) {
|
118
|
+
let lowerMemberAddress = member.accountAddresses[0].toLowerCase();
|
119
|
+
if (lowerMemberAddress === lowerAddress) {
|
120
|
+
console.warn("Member exists", lowerMemberAddress);
|
121
|
+
return {
|
122
|
+
code: 200,
|
123
|
+
message: "You have been added to the group",
|
124
|
+
};
|
125
|
+
}
|
126
|
+
}
|
127
|
+
}
|
128
|
+
return {
|
129
|
+
code: 400,
|
130
|
+
message: "Failed to add to group",
|
131
|
+
};
|
132
|
+
} catch (error) {
|
133
|
+
return {
|
134
|
+
code: 400,
|
135
|
+
message: "Failed to add to group",
|
136
|
+
};
|
137
|
+
}
|
138
|
+
}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
export const systemPrompt = `
|
2
|
+
Your are helpful and playful experimental agent called {agent_name} that lives inside a messaging app called Converse.
|
3
|
+
|
4
|
+
{rules}
|
5
|
+
|
6
|
+
{user_context}
|
7
|
+
|
8
|
+
{skills}
|
9
|
+
|
10
|
+
## Scenarios
|
11
|
+
1. Missing commands in responses
|
12
|
+
**Issue**: Sometimes responses are sent without the required command.
|
13
|
+
**Example**:
|
14
|
+
Incorrect:
|
15
|
+
> "Looks like vitalik.eth is registered! What about these cool alternatives?"
|
16
|
+
Correct:
|
17
|
+
> "Looks like vitalik.eth is registered! What about these cool alternatives?
|
18
|
+
> /cool vitalik.eth"
|
19
|
+
|
20
|
+
Incorrect:
|
21
|
+
> Here is a summary of your TODOs. I will now send it via email.
|
22
|
+
Correct:
|
23
|
+
> /todo
|
24
|
+
`;
|
@@ -0,0 +1,38 @@
|
|
1
|
+
import { XMTPContext, Skill } from "@xmtp/message-kit";
|
2
|
+
|
3
|
+
export const broadcast: Skill[] = [
|
4
|
+
{
|
5
|
+
skill: "/send",
|
6
|
+
adminOnly: true,
|
7
|
+
handler: handler,
|
8
|
+
examples: ["/send Hello everyone, the event is starting now!"],
|
9
|
+
description: "Send updates to all subscribers.",
|
10
|
+
params: {
|
11
|
+
message: {
|
12
|
+
type: "prompt",
|
13
|
+
},
|
14
|
+
},
|
15
|
+
},
|
16
|
+
];
|
17
|
+
|
18
|
+
async function handler(context: XMTPContext) {
|
19
|
+
const {
|
20
|
+
message: {
|
21
|
+
content: { params },
|
22
|
+
},
|
23
|
+
} = context;
|
24
|
+
|
25
|
+
const fakeSubscribers = ["0x93E2fc3e99dFb1238eB9e0eF2580EFC5809C7204"];
|
26
|
+
const { message } = params;
|
27
|
+
await context.send("This is how your message will look like:");
|
28
|
+
await context.send(message);
|
29
|
+
const emailResponse = await context.awaitResponse(
|
30
|
+
"Are you sure you want to send this broadcast?\nType 'yes' to confirm.",
|
31
|
+
["yes", "no"],
|
32
|
+
);
|
33
|
+
if (emailResponse === "yes") {
|
34
|
+
await context.send("Sending broadcast...");
|
35
|
+
await context.sendTo(message, fakeSubscribers);
|
36
|
+
await context.send("Broadcast sent!");
|
37
|
+
}
|
38
|
+
}
|
@@ -0,0 +1,100 @@
|
|
1
|
+
import { XMTPContext, Skill, V3Client } from "@xmtp/message-kit";
|
2
|
+
import { createGroup } from "../lib/xmtp.js";
|
3
|
+
import express from "express";
|
4
|
+
import { checkNft } from "../lib/alchemy.js";
|
5
|
+
|
6
|
+
export const gated: Skill[] = [
|
7
|
+
{
|
8
|
+
skill: "/create",
|
9
|
+
examples: ["/create"],
|
10
|
+
handler: handler,
|
11
|
+
adminOnly: true,
|
12
|
+
params: {},
|
13
|
+
description: "Create a new group.",
|
14
|
+
},
|
15
|
+
{
|
16
|
+
skill: "/id",
|
17
|
+
examples: ["/id"],
|
18
|
+
handler: handler,
|
19
|
+
adminOnly: true,
|
20
|
+
params: {},
|
21
|
+
description: "Get group id.",
|
22
|
+
},
|
23
|
+
];
|
24
|
+
|
25
|
+
async function handler(context: XMTPContext) {
|
26
|
+
const {
|
27
|
+
message: {
|
28
|
+
sender,
|
29
|
+
content: { skill },
|
30
|
+
},
|
31
|
+
client,
|
32
|
+
group,
|
33
|
+
} = context;
|
34
|
+
|
35
|
+
if (skill == "id") {
|
36
|
+
console.log(group?.id);
|
37
|
+
} else if (skill === "create") {
|
38
|
+
console.log(client, sender.address, client.accountAddress);
|
39
|
+
const group = await createGroup(
|
40
|
+
client,
|
41
|
+
sender.address,
|
42
|
+
client.accountAddress,
|
43
|
+
);
|
44
|
+
|
45
|
+
// await context.send(
|
46
|
+
// `Group created!\n- ID: ${group.id}\n- Group Frame URL: https://converse.xyz/group/${group.id}: \n- This url will deelink to the group inside Converse\n- Once in the other group you can share the invite with your friends.`,
|
47
|
+
// );
|
48
|
+
//startServer(client);
|
49
|
+
return;
|
50
|
+
} else {
|
51
|
+
await context.send(
|
52
|
+
"👋 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!",
|
53
|
+
);
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
export function startServer(client: V3Client) {
|
58
|
+
async function addWalletToGroup(
|
59
|
+
walletAddress: string,
|
60
|
+
groupId: string,
|
61
|
+
): Promise<string> {
|
62
|
+
const conversation =
|
63
|
+
await client.conversations.getConversationById(groupId);
|
64
|
+
const verified = await checkNft(walletAddress, "XMTPeople");
|
65
|
+
if (!verified) {
|
66
|
+
console.log("User cant be added to the group");
|
67
|
+
return "not verified";
|
68
|
+
} else {
|
69
|
+
try {
|
70
|
+
await conversation?.addMembers([walletAddress]);
|
71
|
+
console.log(`Added wallet address: ${walletAddress} to the group`);
|
72
|
+
return "success";
|
73
|
+
} catch (error: any) {
|
74
|
+
console.log(error.message);
|
75
|
+
return "error";
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
// Endpoint to add wallet address to a group from an external source
|
81
|
+
const app = express();
|
82
|
+
app.use(express.json());
|
83
|
+
app.post("/add-wallet", async (req, res) => {
|
84
|
+
try {
|
85
|
+
const { walletAddress, groupId } = req.body;
|
86
|
+
const result = await addWalletToGroup(walletAddress, groupId);
|
87
|
+
res.status(200).send(result);
|
88
|
+
} catch (error: any) {
|
89
|
+
res.status(400).send(error.message);
|
90
|
+
}
|
91
|
+
});
|
92
|
+
// Start the servfalcheer
|
93
|
+
const PORT = process.env.PORT || 3000;
|
94
|
+
const url = process.env.URL || `http://localhost:${PORT}`;
|
95
|
+
app.listen(PORT, () => {
|
96
|
+
console.warn(
|
97
|
+
`Use this endpoint to add a wallet to a group indicated by the groupId\n${url}/add-wallet <body: {walletAddress, groupId}>`,
|
98
|
+
);
|
99
|
+
});
|
100
|
+
}
|
@@ -4,7 +4,7 @@ import type { Skill } from "@xmtp/message-kit";
|
|
4
4
|
|
5
5
|
const resend = new Resend(process.env.RESEND_API_KEY); // Replace with your Resend API key
|
6
6
|
|
7
|
-
export const
|
7
|
+
export const todo: Skill[] = [
|
8
8
|
{
|
9
9
|
skill: "/todo",
|
10
10
|
handler: handler,
|
@@ -30,7 +30,7 @@ export async function handler(context: XMTPContext) {
|
|
30
30
|
let intents = 2;
|
31
31
|
while (intents > 0) {
|
32
32
|
const emailResponse = await context.awaitResponse(
|
33
|
-
"Please provide your email address to receive the
|
33
|
+
"Please provide your email address to receive the to-dos summary:",
|
34
34
|
);
|
35
35
|
email = emailResponse;
|
36
36
|
|
@@ -52,14 +52,20 @@ export async function handler(context: XMTPContext) {
|
|
52
52
|
return;
|
53
53
|
}
|
54
54
|
try {
|
55
|
-
|
55
|
+
let { reply } = await context.textGeneration(
|
56
|
+
email,
|
57
|
+
"Make this summary concise and to the point to be sent in an html email. Just return the content inside the body tag.\n msg: " +
|
58
|
+
previousMsg,
|
59
|
+
"You are an expert at summarizing to-dos.",
|
60
|
+
);
|
61
|
+
if (typeof reply === "string") {
|
56
62
|
let content = {
|
57
63
|
from: "bot@mail.coin-toss.xyz",
|
58
64
|
to: email,
|
59
65
|
subject: "Your summary from Converse",
|
60
66
|
html: `
|
61
|
-
<h3>Your
|
62
|
-
<p>${
|
67
|
+
<h3>Your Converse Summary</h3>
|
68
|
+
<p>${reply}</p>
|
63
69
|
`,
|
64
70
|
};
|
65
71
|
await resend.emails.send(content);
|