create-message-kit 1.1.7-beta.1 → 1.1.7-beta.11

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-message-kit",
3
- "version": "1.1.7-beta.1",
3
+ "version": "1.1.7-beta.11",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -1,7 +1,7 @@
1
1
  import { HandlerContext, SkillResponse } from "@xmtp/message-kit";
2
- import { getUserInfo, clearInfoCache, isOnXMTP } from "../lib/resolver.js";
2
+ import { getUserInfo, clearInfoCache, isOnXMTP } from "@xmtp/message-kit";
3
3
  import { isAddress } from "viem";
4
- import { clearMemory } from "../lib/gpt.js";
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
- content: { command, params, sender },
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 skill("/cool " + domain);
115
+ await context.executeSkill("/cool " + domain);
122
116
  return {
123
117
  code: 404,
124
118
  message,
@@ -1,26 +1,18 @@
1
1
  import { run, HandlerContext } from "@xmtp/message-kit";
2
- import { textGeneration, processMultilineResponse } from "./lib/gpt.js";
2
+ import { textGeneration, processMultilineResponse } from "@xmtp/message-kit";
3
3
  import { agent_prompt } from "./prompt.js";
4
- import { getUserInfo } from "./lib/resolver.js";
4
+ import { getUserInfo } from "@xmtp/message-kit";
5
5
 
6
6
  run(async (context: HandlerContext) => {
7
- /*All the skills are handled through the skills file*/
8
- /* If its just text, it will be handled by the ensAgent*/
9
- /* If its a group message, it will be handled by the groupAgent*/
10
- if (!process?.env?.OPEN_AI_API_KEY) {
11
- console.warn("No OPEN_AI_API_KEY found in .env");
12
- return;
13
- }
14
-
15
7
  const {
16
8
  message: {
17
- content: { content, params },
9
+ content: { text, params },
18
10
  sender,
19
11
  },
20
12
  } = context;
21
13
 
22
14
  try {
23
- let userPrompt = params?.prompt ?? content;
15
+ let userPrompt = params?.prompt ?? text;
24
16
  const userInfo = await getUserInfo(sender.address);
25
17
  if (!userInfo) {
26
18
  console.log("User info not found");
@@ -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.skill(message);
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
- console.log("Converse data", keyToUse, converseData);
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 { UserInfo, PROMPT_USER_CONTENT } from "./lib/resolver.js";
3
- import { PROMPT_RULES, PROMPT_SKILLS_AND_EXAMPLES } from "./lib/gpt.js";
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,30 +1,30 @@
1
1
  import { HandlerContext, AbstractedMember } from "@xmtp/message-kit";
2
- import { textGeneration } from "../lib/gpt.js";
2
+ import { textGeneration } from "@xmtp/message-kit";
3
3
 
4
4
  export async function handler(context: HandlerContext) {
5
- if (!process?.env?.OPEN_AI_API_KEY) {
6
- console.warn("No OPEN_AI_API_KEY found in .env");
7
- return;
8
- }
9
-
10
5
  const {
11
6
  message: {
12
7
  sender,
13
- content: { content, params },
8
+ content: { params, text },
14
9
  },
15
- skill,
16
10
  } = context;
17
11
 
18
12
  const systemPrompt = generateSystemPrompt(context);
19
13
  try {
20
- let userPrompt = params?.prompt ?? content;
14
+ let userPrompt = params?.prompt ?? text;
21
15
 
22
16
  const { reply } = await textGeneration(
23
17
  sender.address,
24
18
  userPrompt,
25
19
  systemPrompt,
26
20
  );
27
- skill(reply);
21
+
22
+ try {
23
+ await context.executeSkill(reply);
24
+ } catch (error) {
25
+ console.error("Error executing skill:", error);
26
+ await context.reply("Failed to execute the requested action.");
27
+ }
28
28
  } catch (error) {
29
29
  console.error("Error during OpenAI call:", error);
30
30
  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: { sender, typeId, content },
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 } = content;
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 { HandlerContext, AbstractedMember } from "@xmtp/message-kit";
2
- import { getUserInfo } from "../lib/resolver.js";
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: { content, sender, typeId },
12
+ message: {
13
+ content: { reference, reply, text, params },
14
+ sender,
15
+ typeId,
16
+ },
9
17
  } = context;
10
- const msg = await getMessageById(content.reference);
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
- const { content: reply } = content;
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
- const { content: text, params } = content;
29
- if (text.startsWith("/tip") && params) {
30
- // Process text skills starting with "/tip"
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
- receivers = await Promise.all(
37
- username.map((username: string) => getUserInfo(username)),
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
- break;
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
- break;
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
- break;
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
- async (context: HandlerContext) => {
7
- const {
8
- message: { typeId },
9
- } = context;
10
- switch (typeId) {
11
- case "reply":
12
- handleReply(context);
13
- break;
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.skill(message);
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
- console.log("Converse data", keyToUse, converseData);
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 { helpHandler } from "./index.js";
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: helpHandler,
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
  ];