create-message-kit 1.1.7-beta.1 → 1.1.7-beta.10
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +1 -1
- package/templates/agent/src/handler/ens.ts +7 -13
- package/templates/agent/src/index.ts +2 -2
- package/templates/agent/src/lib/gpt.ts +1 -1
- package/templates/agent/src/lib/resolver.ts +2 -2
- package/templates/agent/src/prompt.ts +7 -2
- package/templates/group/src/handler/agent.ts +10 -5
- package/templates/group/src/handler/game.ts +1 -2
- package/templates/group/src/handler/group.ts +24 -0
- package/templates/group/src/handler/helpers.ts +23 -0
- package/templates/group/src/handler/loyalty.ts +6 -3
- package/templates/group/src/handler/tipping.ts +29 -21
- package/templates/group/src/handler/transaction.ts +28 -8
- package/templates/group/src/index.ts +9 -54
- package/templates/group/src/lib/gpt.ts +1 -1
- package/templates/group/src/lib/resolver.ts +2 -2
- package/templates/group/src/skills.ts +11 -2
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { HandlerContext, SkillResponse } from "@xmtp/message-kit";
|
2
|
-
import { getUserInfo, clearInfoCache, isOnXMTP } from "
|
2
|
+
import { getUserInfo, clearInfoCache, isOnXMTP } from "@xmtp/message-kit";
|
3
3
|
import { isAddress } from "viem";
|
4
|
-
import { clearMemory } from "
|
4
|
+
import { clearMemory } from "@xmtp/message-kit";
|
5
5
|
|
6
6
|
export const frameUrl = "https://ens.steer.fun/";
|
7
7
|
export const ensUrl = "https://app.ens.domains/";
|
@@ -9,12 +9,12 @@ export const baseTxUrl = "https://base-tx-frame.vercel.app";
|
|
9
9
|
|
10
10
|
export async function handleEns(
|
11
11
|
context: HandlerContext,
|
12
|
-
): Promise<SkillResponse> {
|
12
|
+
): Promise<SkillResponse | undefined> {
|
13
13
|
const {
|
14
14
|
message: {
|
15
|
-
|
15
|
+
sender,
|
16
|
+
content: { command, params },
|
16
17
|
},
|
17
|
-
skill,
|
18
18
|
} = context;
|
19
19
|
if (command == "reset") {
|
20
20
|
clearMemory();
|
@@ -87,13 +87,7 @@ export async function handleEns(
|
|
87
87
|
}
|
88
88
|
message += `\n\nWould you like to tip the domain owner for getting there first 🤣?`;
|
89
89
|
message = message.trim();
|
90
|
-
if (
|
91
|
-
await isOnXMTP(
|
92
|
-
context.v2client,
|
93
|
-
data?.ensInfo?.ens,
|
94
|
-
data?.ensInfo?.address,
|
95
|
-
)
|
96
|
-
) {
|
90
|
+
if (await isOnXMTP(context.client, context.v2client, sender?.address)) {
|
97
91
|
await context.send(
|
98
92
|
`Ah, this domains is in XMTP, you can message it directly: https://converse.xyz/dm/${domain}`,
|
99
93
|
);
|
@@ -118,7 +112,7 @@ export async function handleEns(
|
|
118
112
|
};
|
119
113
|
} else {
|
120
114
|
let message = `Looks like ${domain} is already registered!`;
|
121
|
-
await
|
115
|
+
await context.executeSkill("/cool " + domain);
|
122
116
|
return {
|
123
117
|
code: 404,
|
124
118
|
message,
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { run, HandlerContext } from "@xmtp/message-kit";
|
2
|
-
import { textGeneration, processMultilineResponse } from "
|
2
|
+
import { textGeneration, processMultilineResponse } from "@xmtp/message-kit";
|
3
3
|
import { agent_prompt } from "./prompt.js";
|
4
|
-
import { getUserInfo } from "
|
4
|
+
import { getUserInfo } from "@xmtp/message-kit";
|
5
5
|
|
6
6
|
run(async (context: HandlerContext) => {
|
7
7
|
/*All the skills are handled through the skills file*/
|
@@ -126,7 +126,7 @@ export async function processMultilineResponse(
|
|
126
126
|
console.log(messages);
|
127
127
|
for (const message of messages) {
|
128
128
|
if (message.startsWith("/")) {
|
129
|
-
const response = await context.
|
129
|
+
const response = await context.executeSkill(message);
|
130
130
|
if (response && typeof response.message === "string") {
|
131
131
|
let msg = parseMarkdown(response.message);
|
132
132
|
chatMemory.addEntry(memoryKey, {
|
@@ -108,8 +108,8 @@ export const getUserInfo = async (
|
|
108
108
|
}),
|
109
109
|
});
|
110
110
|
const converseData = (await response.json()) as ConverseProfile;
|
111
|
-
if (process.env.MSG_LOG === "true")
|
112
|
-
|
111
|
+
//if (process.env.MSG_LOG === "true")
|
112
|
+
//console.log("Converse data", keyToUse, converseData);
|
113
113
|
data.converseUsername =
|
114
114
|
converseData?.formattedName || converseData?.name || undefined;
|
115
115
|
data.address = converseData?.address || undefined;
|
@@ -1,6 +1,11 @@
|
|
1
1
|
import { skills } from "./skills.js";
|
2
|
-
import {
|
3
|
-
|
2
|
+
import {
|
3
|
+
getUserInfo,
|
4
|
+
UserInfo,
|
5
|
+
PROMPT_USER_CONTENT,
|
6
|
+
PROMPT_RULES,
|
7
|
+
PROMPT_SKILLS_AND_EXAMPLES,
|
8
|
+
} from "@xmtp/message-kit";
|
4
9
|
|
5
10
|
export async function agent_prompt(userInfo: UserInfo) {
|
6
11
|
let { address, ensDomain, converseUsername, preferredName } = userInfo;
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { HandlerContext, AbstractedMember } from "@xmtp/message-kit";
|
2
|
-
import { textGeneration } from "
|
2
|
+
import { textGeneration } from "@xmtp/message-kit";
|
3
3
|
|
4
4
|
export async function handler(context: HandlerContext) {
|
5
5
|
if (!process?.env?.OPEN_AI_API_KEY) {
|
@@ -10,21 +10,26 @@ export async function handler(context: HandlerContext) {
|
|
10
10
|
const {
|
11
11
|
message: {
|
12
12
|
sender,
|
13
|
-
content: {
|
13
|
+
content: { params, text },
|
14
14
|
},
|
15
|
-
skill,
|
16
15
|
} = context;
|
17
16
|
|
18
17
|
const systemPrompt = generateSystemPrompt(context);
|
19
18
|
try {
|
20
|
-
let userPrompt = params?.prompt ??
|
19
|
+
let userPrompt = params?.prompt ?? text;
|
21
20
|
|
22
21
|
const { reply } = await textGeneration(
|
23
22
|
sender.address,
|
24
23
|
userPrompt,
|
25
24
|
systemPrompt,
|
26
25
|
);
|
27
|
-
|
26
|
+
|
27
|
+
try {
|
28
|
+
await context.executeSkill(reply);
|
29
|
+
} catch (error) {
|
30
|
+
console.error("Error executing skill:", error);
|
31
|
+
await context.reply("Failed to execute the requested action.");
|
32
|
+
}
|
28
33
|
} catch (error) {
|
29
34
|
console.error("Error during OpenAI call:", error);
|
30
35
|
await context.reply("An error occurred while processing your request.");
|
@@ -4,11 +4,10 @@ import { HandlerContext } from "@xmtp/message-kit";
|
|
4
4
|
export async function handler(context: HandlerContext) {
|
5
5
|
const {
|
6
6
|
message: {
|
7
|
-
content: { command, params },
|
7
|
+
content: { command, params, text },
|
8
8
|
},
|
9
9
|
} = context;
|
10
10
|
if (!command) {
|
11
|
-
const { content: text } = context?.message?.content;
|
12
11
|
if (text === "🔎" || text === "🔍") {
|
13
12
|
// Send the URL for the requested game
|
14
13
|
context.reply("https://framedl.xyz/");
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import { HandlerContext } from "@xmtp/message-kit";
|
2
|
+
|
3
|
+
export async function handler(context: HandlerContext) {
|
4
|
+
const {
|
5
|
+
skills,
|
6
|
+
group,
|
7
|
+
message: {
|
8
|
+
content: { command },
|
9
|
+
},
|
10
|
+
} = context;
|
11
|
+
|
12
|
+
if (command == "help") {
|
13
|
+
const intro =
|
14
|
+
"Available experiences:\n" +
|
15
|
+
skills
|
16
|
+
?.flatMap((app) => app.skills)
|
17
|
+
.map((skill) => `${skill.command} - ${skill.description}`)
|
18
|
+
.join("\n") +
|
19
|
+
"\nUse these skills to interact with specific apps.";
|
20
|
+
context.send(intro);
|
21
|
+
} else if (command == "id") {
|
22
|
+
context.send(context.group?.id);
|
23
|
+
}
|
24
|
+
}
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import { HandlerContext } from "@xmtp/message-kit";
|
2
|
+
|
3
|
+
export async function handler(context: HandlerContext) {
|
4
|
+
const {
|
5
|
+
skills,
|
6
|
+
message: {
|
7
|
+
content: { command },
|
8
|
+
},
|
9
|
+
} = context;
|
10
|
+
|
11
|
+
if (command == "help") {
|
12
|
+
const intro =
|
13
|
+
"Available experiences:\n" +
|
14
|
+
skills
|
15
|
+
?.flatMap((app) => app.skills)
|
16
|
+
.map((skill) => `${skill.command} - ${skill.description}`)
|
17
|
+
.join("\n") +
|
18
|
+
"\nUse these skills to interact with specific apps.";
|
19
|
+
context.send(intro);
|
20
|
+
} else if (command == "id") {
|
21
|
+
context.send(context.group?.id);
|
22
|
+
}
|
23
|
+
}
|
@@ -6,10 +6,13 @@ export async function handler(context: HandlerContext, fake?: boolean) {
|
|
6
6
|
const {
|
7
7
|
members,
|
8
8
|
group,
|
9
|
-
message: {
|
9
|
+
message: {
|
10
|
+
sender,
|
11
|
+
typeId,
|
12
|
+
content: { command, params, text },
|
13
|
+
},
|
10
14
|
} = context;
|
11
15
|
if (typeId === "text" && group) {
|
12
|
-
const { command } = content;
|
13
16
|
if (command === "points") {
|
14
17
|
const points = await stack?.getPoints(sender.address);
|
15
18
|
context.reply(`You have ${points} points`);
|
@@ -31,7 +34,7 @@ export async function handler(context: HandlerContext, fake?: boolean) {
|
|
31
34
|
return;
|
32
35
|
}
|
33
36
|
} else if (typeId === "group_updated" && group) {
|
34
|
-
const { initiatedByInboxId, addedInboxes } =
|
37
|
+
const { initiatedByInboxId, addedInboxes } = params;
|
35
38
|
const adminAddress = members?.find(
|
36
39
|
(member: AbstractedMember) => member.inboxId === initiatedByInboxId,
|
37
40
|
);
|
@@ -1,13 +1,21 @@
|
|
1
|
-
import {
|
2
|
-
|
1
|
+
import {
|
2
|
+
HandlerContext,
|
3
|
+
AbstractedMember,
|
4
|
+
SkillResponse,
|
5
|
+
} from "@xmtp/message-kit";
|
6
|
+
import { getUserInfo } from "@xmtp/message-kit";
|
3
7
|
|
4
|
-
export async function handler(context: HandlerContext) {
|
8
|
+
export async function handler(context: HandlerContext): Promise<SkillResponse> {
|
5
9
|
const {
|
6
10
|
members,
|
7
11
|
getMessageById,
|
8
|
-
message: {
|
12
|
+
message: {
|
13
|
+
content: { reference, reply, text, params },
|
14
|
+
sender,
|
15
|
+
typeId,
|
16
|
+
},
|
9
17
|
} = context;
|
10
|
-
const msg = await getMessageById(
|
18
|
+
const msg = reference ? await getMessageById(reference) : undefined;
|
11
19
|
const replyReceiver = members?.find(
|
12
20
|
(member) => member.inboxId === msg?.senderInboxId,
|
13
21
|
);
|
@@ -15,32 +23,28 @@ export async function handler(context: HandlerContext) {
|
|
15
23
|
receivers: AbstractedMember[] = [];
|
16
24
|
// Handle different types of messages
|
17
25
|
if (typeId === "reply" && replyReceiver) {
|
18
|
-
|
19
|
-
|
20
|
-
if (reply.includes("degen")) {
|
26
|
+
if (reply?.includes("degen")) {
|
21
27
|
receivers = [replyReceiver];
|
22
28
|
const match = reply.match(/(\d+)/);
|
23
29
|
if (match)
|
24
30
|
amount = parseInt(match[0]); // Extract amount from reply
|
25
31
|
else amount = 10;
|
26
32
|
}
|
27
|
-
} else if (typeId === "text") {
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
const {
|
32
|
-
params: { amount: extractedAmount, username },
|
33
|
-
} = content;
|
34
|
-
amount = extractedAmount || 10; // Default amount if not specified
|
33
|
+
} else if (typeId === "text" && text?.startsWith("/tip") && params) {
|
34
|
+
// Process text skills starting with "/tip"
|
35
|
+
const { amount: extractedAmount, username } = params;
|
36
|
+
amount = extractedAmount || 10; // Default amount if not specified
|
35
37
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
}
|
38
|
+
receivers = await Promise.all(
|
39
|
+
username.map((username: string) => getUserInfo(username)),
|
40
|
+
);
|
40
41
|
}
|
41
42
|
if (!sender || receivers.length === 0 || amount === 0) {
|
42
43
|
context.reply("Sender or receiver or amount not found.");
|
43
|
-
return
|
44
|
+
return {
|
45
|
+
code: 400,
|
46
|
+
message: "Sender or receiver or amount not found.",
|
47
|
+
};
|
44
48
|
}
|
45
49
|
const receiverAddresses = receivers.map((receiver) => receiver.address);
|
46
50
|
// Process sending tokens to each receiver
|
@@ -55,4 +59,8 @@ export async function handler(context: HandlerContext) {
|
|
55
59
|
`You sent ${amount * receiverAddresses.length} tokens in total.`,
|
56
60
|
[sender.address],
|
57
61
|
);
|
62
|
+
return {
|
63
|
+
code: 200,
|
64
|
+
message: "Success",
|
65
|
+
};
|
58
66
|
}
|
@@ -1,8 +1,7 @@
|
|
1
|
-
import { HandlerContext } from "@xmtp/message-kit";
|
2
|
-
import { getUserInfo } from "../lib/resolver.js";
|
1
|
+
import { getUserInfo, HandlerContext, SkillResponse } from "@xmtp/message-kit";
|
3
2
|
|
4
3
|
// Main handler function for processing commands
|
5
|
-
export async function handler(context: HandlerContext) {
|
4
|
+
export async function handler(context: HandlerContext): Promise<SkillResponse> {
|
6
5
|
const {
|
7
6
|
message: {
|
8
7
|
content: { command, params },
|
@@ -19,12 +18,19 @@ export async function handler(context: HandlerContext) {
|
|
19
18
|
context.reply(
|
20
19
|
"Missing required parameters. Please provide amount, token, and username.",
|
21
20
|
);
|
22
|
-
return
|
21
|
+
return {
|
22
|
+
code: 400,
|
23
|
+
message:
|
24
|
+
"Missing required parameters. Please provide amount, token, and username.",
|
25
|
+
};
|
23
26
|
}
|
24
27
|
|
25
28
|
let sendUrl = `${baseUrl}/?transaction_type=send&amount=${amountSend}&token=${tokenSend}&receiver=${senderInfo.address}`;
|
26
29
|
context.send(`${sendUrl}`);
|
27
|
-
|
30
|
+
return {
|
31
|
+
code: 200,
|
32
|
+
message: `${sendUrl}`,
|
33
|
+
};
|
28
34
|
case "swap":
|
29
35
|
// Destructure and validate parameters for the swap command
|
30
36
|
const { amount, token_from, token_to } = params; // [!code hl] // [!code focus]
|
@@ -33,18 +39,32 @@ export async function handler(context: HandlerContext) {
|
|
33
39
|
context.reply(
|
34
40
|
"Missing required parameters. Please provide amount, token_from, and token_to.",
|
35
41
|
);
|
36
|
-
return
|
42
|
+
return {
|
43
|
+
code: 400,
|
44
|
+
message:
|
45
|
+
"Missing required parameters. Please provide amount, token_from, and token_to.",
|
46
|
+
};
|
37
47
|
}
|
38
48
|
|
39
49
|
let swapUrl = `${baseUrl}/?transaction_type=swap&token_from=${token_from}&token_to=${token_to}&amount=${amount}`;
|
40
50
|
context.send(`${swapUrl}`);
|
41
|
-
|
51
|
+
return {
|
52
|
+
code: 200,
|
53
|
+
message: `${swapUrl}`,
|
54
|
+
};
|
42
55
|
case "show": // [!code hl] // [!code focus]
|
43
56
|
// Show the base URL without the transaction path
|
44
57
|
context.reply(`${baseUrl.replace("/transaction", "")}`);
|
45
|
-
|
58
|
+
return {
|
59
|
+
code: 200,
|
60
|
+
message: `${baseUrl.replace("/transaction", "")}`,
|
61
|
+
};
|
46
62
|
default:
|
47
63
|
// Handle unknown commands
|
48
64
|
context.reply("Unknown command. Use help to see all available commands.");
|
65
|
+
return {
|
66
|
+
code: 400,
|
67
|
+
message: "Unknown command. Use help to see all available commands.",
|
68
|
+
};
|
49
69
|
}
|
50
70
|
}
|
@@ -1,57 +1,12 @@
|
|
1
1
|
import { run, HandlerContext } from "@xmtp/message-kit";
|
2
|
-
import { handler as splitpayment } from "./handler/splitpayment.js";
|
3
2
|
|
4
3
|
// Main function to run the app
|
5
|
-
run(
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
case "remoteStaticAttachment":
|
15
|
-
handleAttachment(context);
|
16
|
-
break;
|
17
|
-
}
|
18
|
-
if (!context.group) {
|
19
|
-
context.send("This is a group bot, add this address to a group");
|
20
|
-
}
|
21
|
-
},
|
22
|
-
{ attachments: true },
|
23
|
-
);
|
24
|
-
async function handleReply(context: HandlerContext) {
|
25
|
-
const {
|
26
|
-
v2client,
|
27
|
-
getReplyChain,
|
28
|
-
version,
|
29
|
-
message: {
|
30
|
-
content: { reference },
|
31
|
-
},
|
32
|
-
} = context;
|
33
|
-
|
34
|
-
const { chain, isSenderInChain } = await getReplyChain(
|
35
|
-
reference,
|
36
|
-
version,
|
37
|
-
v2client.address,
|
38
|
-
);
|
39
|
-
//await context.skill(chain);
|
40
|
-
}
|
41
|
-
|
42
|
-
// Handle attachment messages
|
43
|
-
async function handleAttachment(context: HandlerContext) {
|
44
|
-
await splitpayment(context);
|
45
|
-
}
|
46
|
-
|
47
|
-
export async function helpHandler(context: HandlerContext) {
|
48
|
-
const { skills } = context;
|
49
|
-
const intro =
|
50
|
-
"Available experiences:\n" +
|
51
|
-
skills
|
52
|
-
?.flatMap((app) => app.skills)
|
53
|
-
.map((skill) => `${skill.command} - ${skill.description}`)
|
54
|
-
.join("\n") +
|
55
|
-
"\nUse these skills to interact with specific apps.";
|
56
|
-
context.send(intro);
|
57
|
-
}
|
4
|
+
run(async (context: HandlerContext) => {
|
5
|
+
const { group } = context;
|
6
|
+
|
7
|
+
if (!group) {
|
8
|
+
context.send(
|
9
|
+
"This This bot only works in group chats. Please add this bot to a group to continue",
|
10
|
+
);
|
11
|
+
}
|
12
|
+
});
|
@@ -126,7 +126,7 @@ export async function processMultilineResponse(
|
|
126
126
|
console.log(messages);
|
127
127
|
for (const message of messages) {
|
128
128
|
if (message.startsWith("/")) {
|
129
|
-
const response = await context.
|
129
|
+
const response = await context.executeSkill(message);
|
130
130
|
if (response && typeof response.message === "string") {
|
131
131
|
let msg = parseMarkdown(response.message);
|
132
132
|
chatMemory.addEntry(memoryKey, {
|
@@ -108,8 +108,8 @@ export const getUserInfo = async (
|
|
108
108
|
}),
|
109
109
|
});
|
110
110
|
const converseData = (await response.json()) as ConverseProfile;
|
111
|
-
if (process.env.MSG_LOG === "true")
|
112
|
-
|
111
|
+
/// if (process.env.MSG_LOG === "true")
|
112
|
+
//console.log("Converse data", keyToUse, converseData);
|
113
113
|
data.converseUsername =
|
114
114
|
converseData?.formattedName || converseData?.name || undefined;
|
115
115
|
data.address = converseData?.address || undefined;
|
@@ -3,7 +3,7 @@ import { handler as agent } from "./handler/agent.js";
|
|
3
3
|
import { handler as transaction } from "./handler/transaction.js";
|
4
4
|
import { handler as games } from "./handler/game.js";
|
5
5
|
import { handler as loyalty } from "./handler/loyalty.js";
|
6
|
-
import {
|
6
|
+
import { handler as groupHelp } from "./handler/helpers.js";
|
7
7
|
import type { SkillGroup } from "@xmtp/message-kit";
|
8
8
|
|
9
9
|
export const skills: SkillGroup[] = [
|
@@ -31,6 +31,7 @@ export const skills: SkillGroup[] = [
|
|
31
31
|
},
|
32
32
|
],
|
33
33
|
},
|
34
|
+
|
34
35
|
{
|
35
36
|
name: "Transactions",
|
36
37
|
description: "Multipurpose transaction frame built onbase.",
|
@@ -159,10 +160,18 @@ export const skills: SkillGroup[] = [
|
|
159
160
|
command: "/help",
|
160
161
|
triggers: ["/help"],
|
161
162
|
examples: ["/help"],
|
162
|
-
handler:
|
163
|
+
handler: groupHelp,
|
163
164
|
description: "Get help with the bot.",
|
164
165
|
params: {},
|
165
166
|
},
|
167
|
+
{
|
168
|
+
command: "/id",
|
169
|
+
adminOnly: true,
|
170
|
+
handler: groupHelp,
|
171
|
+
triggers: ["/id"],
|
172
|
+
description: "Get the group ID.",
|
173
|
+
params: {},
|
174
|
+
},
|
166
175
|
],
|
167
176
|
},
|
168
177
|
];
|