create-message-kit 1.2.13 → 1.2.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +15 -15
- package/package.json +1 -1
- package/templates/coinbase-agent/.cursorrules +290 -0
- package/templates/coinbase-agent/.env.example +4 -0
- package/templates/coinbase-agent/.yarnrc.yml +9 -0
- package/templates/coinbase-agent/package.json +22 -0
- package/templates/coinbase-agent/src/index.ts +31 -0
- package/templates/coinbase-agent/src/plugins/learnweb3.ts +96 -0
- package/templates/coinbase-agent/src/plugins/redis.ts +15 -0
- package/templates/coinbase-agent/src/prompt.ts +64 -0
- package/templates/coinbase-agent/src/skills/drip.ts +83 -0
- package/templates/coinbase-agent/src/skills/mint.ts +99 -0
- package/templates/coinbase-agent/src/skills/pay.ts +35 -0
- package/templates/coinbase-agent/src/skills/swap.ts +52 -0
- package/templates/ens/.env.example +1 -0
- package/templates/ens/.yarnrc.yml +5 -0
- package/templates/ens/src/index.ts +1 -1
- package/templates/ens/src/prompt.ts +1 -14
- package/templates/faucet/.cursorrules +290 -0
- package/templates/faucet/.env.example +5 -0
- package/templates/faucet/.yarnrc.yml +9 -0
- package/templates/faucet/package.json +22 -0
- package/templates/faucet/src/index.ts +39 -0
- package/templates/faucet/src/plugins/learnweb3.ts +96 -0
- package/templates/faucet/src/plugins/redis.ts +15 -0
- package/templates/faucet/src/prompt.ts +11 -0
- package/templates/faucet/src/skills/faucet.ts +140 -0
- package/templates/gated-group/.cursorrules +290 -0
- package/templates/gated-group/.env.example +3 -0
- package/templates/gated-group/.yarnrc.yml +9 -0
- package/templates/gated-group/package.json +23 -0
- package/templates/gated-group/src/index.ts +17 -0
- package/templates/gated-group/src/plugins/alchemy.ts +27 -0
- package/templates/gated-group/src/plugins/xmtp.ts +137 -0
- package/templates/gated-group/src/prompt.ts +11 -0
- package/templates/gated-group/src/skills/gated.ts +88 -0
- package/templates/gm/.cursorrules +290 -0
- package/templates/gm/.env.example +2 -0
- package/templates/gm/.yarnrc.yml +9 -0
- package/templates/gm/package.json +20 -0
- package/templates/gm/src/index.ts +8 -0
- package/templates/playground/.cursorrules +290 -0
- package/templates/playground/.env.example +6 -0
- package/templates/playground/.yarnrc.yml +9 -0
- package/templates/playground/package.json +26 -0
- package/templates/playground/src/index.ts +40 -0
- package/templates/playground/src/plugins/alchemy.ts +27 -0
- package/templates/playground/src/plugins/minilog.ts +26 -0
- package/templates/playground/src/plugins/usdc.ts +99 -0
- package/templates/playground/src/plugins/xmtp.ts +137 -0
- package/templates/playground/src/prompt.ts +11 -0
- package/templates/playground/src/skills/broadcast.ts +39 -0
- package/templates/playground/src/skills/cash.ts +122 -0
- package/templates/playground/src/skills/cryptoPrice.ts +63 -0
- package/templates/playground/src/skills/dalle.ts +61 -0
- package/templates/playground/src/skills/gated.ts +88 -0
- package/templates/playground/src/skills/search.ts +159 -0
- package/templates/playground/src/skills/todo.ts +79 -0
- package/templates/playground/src/skills/token.ts +57 -0
- package/templates/playground/src/skills/web.ts +83 -0
- package/templates/playground/src/skills/wordle.ts +96 -0
- package/templates/simple/.env.example +1 -0
- package/templates/simple/.yarnrc.yml +5 -0
- package/templates/simple/src/index.ts +1 -1
- package/templates/simple/src/prompt.ts +2 -0
- package/templates/thegeneralstore/.cursorrules +290 -0
- package/templates/thegeneralstore/.env.example +9 -0
- package/templates/thegeneralstore/.yarnrc.yml +9 -0
- package/templates/thegeneralstore/package.json +24 -0
- package/templates/thegeneralstore/src/data/db.json +812 -0
- package/templates/thegeneralstore/src/index.ts +37 -0
- package/templates/thegeneralstore/src/plugins/learnweb3.ts +96 -0
- package/templates/thegeneralstore/src/plugins/lowdb.ts +11 -0
- package/templates/thegeneralstore/src/plugins/notion.ts +89 -0
- package/templates/thegeneralstore/src/plugins/redis.ts +15 -0
- package/templates/thegeneralstore/src/prompt.md +51 -0
- package/templates/thegeneralstore/src/prompt.ts +3 -0
- package/templates/thegeneralstore/src/skills/faucet.ts +114 -0
- package/templates/thegeneralstore/src/skills/notion.ts +17 -0
- package/templates/thegeneralstore/src/skills/poap.ts +48 -0
- package/templates/thegeneralstore/src/skills.ts +37 -0
- package/templates/toss/.cursorrules +290 -0
- package/templates/toss/.env.example +7 -0
- package/templates/toss/.yarnrc.yml +9 -0
- package/templates/toss/package.json +21 -0
- package/templates/toss/src/index.ts +33 -0
- package/templates/toss/src/plugins/helpers.ts +185 -0
- package/templates/toss/src/plugins/redis.ts +78 -0
- package/templates/toss/src/prompt.ts +54 -0
- package/templates/toss/src/skills/toss.ts +489 -0
@@ -0,0 +1,88 @@
|
|
1
|
+
import { XMTPContext, Skill, V3Client } from "@xmtp/message-kit";
|
2
|
+
import { createGroup } from "../plugins/xmtp.js";
|
3
|
+
import express from "express";
|
4
|
+
import { checkNft } from "../plugins/alchemy.js";
|
5
|
+
import { addToGroup } from "../plugins/xmtp.js";
|
6
|
+
export const gated: Skill[] = [
|
7
|
+
{
|
8
|
+
skill: "create",
|
9
|
+
examples: ["/create"],
|
10
|
+
handler: handler,
|
11
|
+
adminOnly: true,
|
12
|
+
description: "Create a new group.",
|
13
|
+
},
|
14
|
+
];
|
15
|
+
|
16
|
+
async function handler(context: XMTPContext) {
|
17
|
+
const {
|
18
|
+
message: {
|
19
|
+
sender,
|
20
|
+
content: { skill },
|
21
|
+
},
|
22
|
+
client,
|
23
|
+
} = context;
|
24
|
+
|
25
|
+
if (skill === "create") {
|
26
|
+
const group = await createGroup(
|
27
|
+
client,
|
28
|
+
sender.address,
|
29
|
+
client.accountAddress,
|
30
|
+
);
|
31
|
+
|
32
|
+
await context.send(
|
33
|
+
`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.`,
|
34
|
+
);
|
35
|
+
return;
|
36
|
+
} else {
|
37
|
+
await context.send(
|
38
|
+
"👋 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!",
|
39
|
+
);
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
export function startGatedGroupServer(client: V3Client) {
|
44
|
+
async function addWalletToGroup(
|
45
|
+
walletAddress: string,
|
46
|
+
groupId: string,
|
47
|
+
): Promise<string> {
|
48
|
+
const verified = await checkNft(walletAddress, "XMTPeople");
|
49
|
+
if (!verified) {
|
50
|
+
console.log("User cant be added to the group");
|
51
|
+
return "not verified";
|
52
|
+
} else {
|
53
|
+
try {
|
54
|
+
const added = await addToGroup(groupId, client, walletAddress);
|
55
|
+
if (added.code === 200) {
|
56
|
+
console.log(`Added wallet address: ${walletAddress} to the group`);
|
57
|
+
return "success";
|
58
|
+
} else {
|
59
|
+
return added.message;
|
60
|
+
}
|
61
|
+
} catch (error: any) {
|
62
|
+
console.log(error.message);
|
63
|
+
return "error";
|
64
|
+
}
|
65
|
+
}
|
66
|
+
}
|
67
|
+
|
68
|
+
// Endpoint to add wallet address to a group from an external source
|
69
|
+
const app = express();
|
70
|
+
app.use(express.json());
|
71
|
+
app.post("/add-wallet", async (req, res) => {
|
72
|
+
try {
|
73
|
+
const { walletAddress, groupId } = req.body;
|
74
|
+
const result = await addWalletToGroup(walletAddress, groupId);
|
75
|
+
res.status(200).send(result);
|
76
|
+
} catch (error: any) {
|
77
|
+
res.status(400).send(error.message);
|
78
|
+
}
|
79
|
+
});
|
80
|
+
// Start the servfalcheer
|
81
|
+
const PORT = process.env.PORT || 3000;
|
82
|
+
const url = process.env.URL || `http://localhost:${PORT}`;
|
83
|
+
app.listen(PORT, () => {
|
84
|
+
console.warn(
|
85
|
+
`Use this endpoint to add a wallet to a group indicated by the groupId\n${url}/add-wallet <body: {walletAddress, groupId}>`,
|
86
|
+
);
|
87
|
+
});
|
88
|
+
}
|
@@ -0,0 +1,159 @@
|
|
1
|
+
import { XMTPContext } from "@xmtp/message-kit";
|
2
|
+
import type { Skill } from "@xmtp/message-kit";
|
3
|
+
import OpenAI from "openai";
|
4
|
+
|
5
|
+
const openai = new OpenAI({
|
6
|
+
apiKey: process.env.OPENAI_API_KEY,
|
7
|
+
});
|
8
|
+
|
9
|
+
export const search: Skill[] = [
|
10
|
+
{
|
11
|
+
skill: "search",
|
12
|
+
examples: [
|
13
|
+
"/search what is the capital of France?",
|
14
|
+
"/search latest news about ethereum",
|
15
|
+
],
|
16
|
+
handler: handler,
|
17
|
+
description:
|
18
|
+
"Search the internet and get summarized information from top results.",
|
19
|
+
params: {
|
20
|
+
query: {
|
21
|
+
type: "prompt",
|
22
|
+
},
|
23
|
+
},
|
24
|
+
},
|
25
|
+
];
|
26
|
+
|
27
|
+
export async function handler(context: XMTPContext) {
|
28
|
+
const {
|
29
|
+
message: {
|
30
|
+
content: {
|
31
|
+
params: { query },
|
32
|
+
},
|
33
|
+
},
|
34
|
+
} = context;
|
35
|
+
|
36
|
+
try {
|
37
|
+
// Search and get top results
|
38
|
+
const searchResults = await searchDuckDuckGo(query);
|
39
|
+
if (!searchResults.length) {
|
40
|
+
return {
|
41
|
+
code: 404,
|
42
|
+
message: "No results found for your query.",
|
43
|
+
};
|
44
|
+
}
|
45
|
+
|
46
|
+
// Fetch content from each result
|
47
|
+
const contents = await Promise.all(
|
48
|
+
searchResults.slice(0, 3).map(async (url) => {
|
49
|
+
try {
|
50
|
+
const response = await fetch(url, {
|
51
|
+
headers: {
|
52
|
+
"User-Agent":
|
53
|
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
|
54
|
+
},
|
55
|
+
});
|
56
|
+
const html = await response.text();
|
57
|
+
return extractContent(html);
|
58
|
+
} catch (error) {
|
59
|
+
console.error(`Error fetching ${url}:`, error);
|
60
|
+
return "";
|
61
|
+
}
|
62
|
+
}),
|
63
|
+
);
|
64
|
+
|
65
|
+
// Combine and summarize the content
|
66
|
+
const summary = await getAISummary(contents.join("\n"), query);
|
67
|
+
|
68
|
+
return {
|
69
|
+
code: 200,
|
70
|
+
message: summary,
|
71
|
+
};
|
72
|
+
} catch (error: any) {
|
73
|
+
return {
|
74
|
+
code: 500,
|
75
|
+
message: `Search failed: ${error.message}`,
|
76
|
+
};
|
77
|
+
}
|
78
|
+
}
|
79
|
+
|
80
|
+
async function searchDuckDuckGo(query: string): Promise<string[]> {
|
81
|
+
try {
|
82
|
+
// DuckDuckGo's lite version is more friendly to programmatic access
|
83
|
+
const response = await fetch(
|
84
|
+
`https://duckduckgo.com/lite?q=${encodeURIComponent(query)}`,
|
85
|
+
{
|
86
|
+
headers: {
|
87
|
+
"User-Agent":
|
88
|
+
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36",
|
89
|
+
},
|
90
|
+
},
|
91
|
+
);
|
92
|
+
|
93
|
+
const html = await response.text();
|
94
|
+
|
95
|
+
// Extract URLs from the results
|
96
|
+
const urlRegex = /<a class="result-link" href="([^"]+)"/g;
|
97
|
+
const urls: string[] = [];
|
98
|
+
let match;
|
99
|
+
|
100
|
+
while ((match = urlRegex.exec(html)) !== null) {
|
101
|
+
if (match[1] && !match[1].includes("duckduckgo.com")) {
|
102
|
+
urls.push(match[1]);
|
103
|
+
}
|
104
|
+
}
|
105
|
+
|
106
|
+
// If no results from regex, try alternative pattern
|
107
|
+
if (urls.length === 0) {
|
108
|
+
const altRegex = /rel="nofollow" href="([^"]+)"/g;
|
109
|
+
while ((match = altRegex.exec(html)) !== null) {
|
110
|
+
if (match[1] && !match[1].includes("duckduckgo.com")) {
|
111
|
+
urls.push(match[1]);
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
return urls;
|
117
|
+
} catch (error) {
|
118
|
+
console.error("Search failed:", error);
|
119
|
+
return [];
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
function extractContent(html: string): string {
|
124
|
+
// Remove scripts and style elements
|
125
|
+
html = html
|
126
|
+
.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "")
|
127
|
+
.replace(/<style\b[^<]*(?:(?!<\/style>)<[^<]*)*<\/style>/gi, "");
|
128
|
+
|
129
|
+
// Get text content
|
130
|
+
const text = html
|
131
|
+
.replace(/<[^>]+>/g, " ")
|
132
|
+
.replace(/\s+/g, " ")
|
133
|
+
.trim()
|
134
|
+
.slice(0, 2000); // Get more content for search results
|
135
|
+
|
136
|
+
return text;
|
137
|
+
}
|
138
|
+
|
139
|
+
async function getAISummary(content: string, query: string): Promise<string> {
|
140
|
+
const completion = await openai.chat.completions.create({
|
141
|
+
messages: [
|
142
|
+
{
|
143
|
+
role: "system",
|
144
|
+
content:
|
145
|
+
"You are a helpful assistant that provides clear, accurate summaries (2-3 sentences) of search results.",
|
146
|
+
},
|
147
|
+
{
|
148
|
+
role: "user",
|
149
|
+
content: `Based on the following search results, please provide a comprehensive answer to the query: "${query}"\n\nSearch results:\n${content}`,
|
150
|
+
},
|
151
|
+
],
|
152
|
+
model: "gpt-4o-mini",
|
153
|
+
});
|
154
|
+
|
155
|
+
return (
|
156
|
+
completion.choices[0].message.content ||
|
157
|
+
"Could not generate a summary of the search results."
|
158
|
+
);
|
159
|
+
}
|
@@ -0,0 +1,79 @@
|
|
1
|
+
import { Resend } from "resend";
|
2
|
+
import { XMTPContext } from "@xmtp/message-kit";
|
3
|
+
import type { Skill } from "@xmtp/message-kit";
|
4
|
+
|
5
|
+
const resend = new Resend(process.env.RESEND_API_KEY); // Replace with your Resend API key
|
6
|
+
|
7
|
+
export const todo: Skill[] = [
|
8
|
+
{
|
9
|
+
skill: "todo",
|
10
|
+
handler: handler,
|
11
|
+
examples: ["/todo"],
|
12
|
+
description:
|
13
|
+
"Summarize your TODOs and send an email with the summary. Receives no parameters.",
|
14
|
+
},
|
15
|
+
];
|
16
|
+
|
17
|
+
export async function handler(context: XMTPContext) {
|
18
|
+
const {
|
19
|
+
message: {
|
20
|
+
content: { previousMsg },
|
21
|
+
},
|
22
|
+
} = context;
|
23
|
+
|
24
|
+
let email = "";
|
25
|
+
if (!previousMsg) {
|
26
|
+
await context.send("You need to do it on a reply.");
|
27
|
+
return;
|
28
|
+
}
|
29
|
+
let intents = 2;
|
30
|
+
while (intents > 0) {
|
31
|
+
const emailResponse = await context.awaitResponse(
|
32
|
+
"Please provide your email address to receive the to-dos summary:",
|
33
|
+
);
|
34
|
+
email = emailResponse;
|
35
|
+
|
36
|
+
// Basic email validation
|
37
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
38
|
+
if (!emailRegex.test(email)) {
|
39
|
+
await context.send(
|
40
|
+
"Invalid email format. Please try again with a valid email address.",
|
41
|
+
);
|
42
|
+
intents--;
|
43
|
+
continue;
|
44
|
+
}
|
45
|
+
break;
|
46
|
+
}
|
47
|
+
if (intents == 0) {
|
48
|
+
await context.send(
|
49
|
+
"I couldn't get your email address. Please try again later.",
|
50
|
+
);
|
51
|
+
return;
|
52
|
+
}
|
53
|
+
try {
|
54
|
+
let { reply } = await context.textGeneration(
|
55
|
+
email,
|
56
|
+
"Make this summary concise and to the point to be sent in an email.\n msg: " +
|
57
|
+
previousMsg,
|
58
|
+
"You are an expert at summarizing to-dos. Return in format html and just the content inside the body tag. Dont return `html` or `body` tags",
|
59
|
+
);
|
60
|
+
if (typeof reply === "string") {
|
61
|
+
let content = {
|
62
|
+
from: "bot@mail.coin-toss.xyz",
|
63
|
+
to: email,
|
64
|
+
subject: "Your summary from Converse",
|
65
|
+
html: `
|
66
|
+
<h3>Your Converse Summary</h3>
|
67
|
+
<p>${reply}</p>
|
68
|
+
`,
|
69
|
+
};
|
70
|
+
await resend.emails.send(content);
|
71
|
+
await context.send(`✅ Summary sent successfully to ${email}`);
|
72
|
+
} else {
|
73
|
+
await context.send("❌ Message not found.");
|
74
|
+
}
|
75
|
+
} catch (error) {
|
76
|
+
await context.send("❌ Failed to send email. Please try again later.");
|
77
|
+
console.error("Error sending email:", error);
|
78
|
+
}
|
79
|
+
}
|
@@ -0,0 +1,57 @@
|
|
1
|
+
import { XMTPContext } from "@xmtp/message-kit";
|
2
|
+
import type { Skill } from "@xmtp/message-kit";
|
3
|
+
|
4
|
+
export const token: Skill[] = [
|
5
|
+
{
|
6
|
+
skill: "token",
|
7
|
+
handler: handler,
|
8
|
+
examples: ["/token bitcoin", "/token ethereum"],
|
9
|
+
description: "Get real time price of a any token.",
|
10
|
+
params: {
|
11
|
+
symbol: {
|
12
|
+
type: "string",
|
13
|
+
},
|
14
|
+
},
|
15
|
+
},
|
16
|
+
];
|
17
|
+
export async function handler(context: XMTPContext) {
|
18
|
+
const {
|
19
|
+
message: {
|
20
|
+
content: {
|
21
|
+
params: { symbol },
|
22
|
+
},
|
23
|
+
},
|
24
|
+
} = context;
|
25
|
+
const response = await fetch(
|
26
|
+
`https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&ids=${symbol}`,
|
27
|
+
);
|
28
|
+
if (!response.ok) {
|
29
|
+
context.send("Token not found");
|
30
|
+
context.send("try with its full name, instead of btc it would be bitcoin");
|
31
|
+
return;
|
32
|
+
}
|
33
|
+
const data = (await response.json()) as any;
|
34
|
+
const token = data[0];
|
35
|
+
|
36
|
+
const tokenInfo = {
|
37
|
+
name: token.name,
|
38
|
+
symbol: token.symbol.toUpperCase(),
|
39
|
+
price: token.current_price,
|
40
|
+
image: token.image,
|
41
|
+
link: `https://www.coingecko.com/en/coins/${token.id}`,
|
42
|
+
};
|
43
|
+
|
44
|
+
let frame = {
|
45
|
+
title: tokenInfo.name,
|
46
|
+
buttons: [
|
47
|
+
{ content: "Buy", action: "link", target: tokenInfo.link },
|
48
|
+
{
|
49
|
+
content: `Price (${tokenInfo.price})`,
|
50
|
+
action: "link",
|
51
|
+
target: tokenInfo.link,
|
52
|
+
},
|
53
|
+
],
|
54
|
+
image: tokenInfo.image,
|
55
|
+
};
|
56
|
+
await context.sendCustomFrame(frame);
|
57
|
+
}
|
@@ -0,0 +1,83 @@
|
|
1
|
+
import { XMTPContext } from "@xmtp/message-kit";
|
2
|
+
import type { Skill } from "@xmtp/message-kit";
|
3
|
+
import OpenAI from "openai";
|
4
|
+
|
5
|
+
const openai = new OpenAI({
|
6
|
+
apiKey: process.env.OPENAI_API_KEY,
|
7
|
+
});
|
8
|
+
|
9
|
+
export const web: Skill[] = [
|
10
|
+
{
|
11
|
+
skill: "web",
|
12
|
+
examples: ["/web https://message-kit.org"],
|
13
|
+
handler: handler,
|
14
|
+
description: "Get information about a website.",
|
15
|
+
params: {
|
16
|
+
url: {
|
17
|
+
type: "url",
|
18
|
+
},
|
19
|
+
},
|
20
|
+
},
|
21
|
+
];
|
22
|
+
|
23
|
+
export async function handler(context: XMTPContext) {
|
24
|
+
const {
|
25
|
+
message: {
|
26
|
+
content: {
|
27
|
+
params: { url },
|
28
|
+
},
|
29
|
+
},
|
30
|
+
} = context;
|
31
|
+
|
32
|
+
try {
|
33
|
+
const response = await fetch(url);
|
34
|
+
if (!response.ok) {
|
35
|
+
return {
|
36
|
+
code: response.status,
|
37
|
+
message: `Unable to access website: ${response.statusText}`,
|
38
|
+
};
|
39
|
+
}
|
40
|
+
|
41
|
+
const html = await response.text();
|
42
|
+
const content = extractContent(html);
|
43
|
+
const summary = await getAISummary(content, url);
|
44
|
+
|
45
|
+
return {
|
46
|
+
code: 200,
|
47
|
+
message: summary,
|
48
|
+
};
|
49
|
+
} catch (error: any) {
|
50
|
+
return {
|
51
|
+
code: 500,
|
52
|
+
message: `Could not analyze website: ${error.message}`,
|
53
|
+
};
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
function extractContent(html: string): string {
|
58
|
+
// Remove scripts and style elements
|
59
|
+
html = html.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '')
|
60
|
+
.replace(/<style\b[^<]*(?:(?!<\/style>)<[^<]*)*<\/style>/gi, '');
|
61
|
+
|
62
|
+
// Get text content
|
63
|
+
const text = html.replace(/<[^>]+>/g, ' ')
|
64
|
+
.replace(/\s+/g, ' ')
|
65
|
+
.trim()
|
66
|
+
.slice(0, 1000);
|
67
|
+
|
68
|
+
return text;
|
69
|
+
}
|
70
|
+
|
71
|
+
async function getAISummary(content: string, url: string): Promise<string> {
|
72
|
+
const completion = await openai.chat.completions.create({
|
73
|
+
messages: [
|
74
|
+
{
|
75
|
+
role: "user",
|
76
|
+
content: `What is ${url} about? Summarize it in 2-3 sentences based on the following content: \n${content}\n\nDon't include any pretext but include the url in the summary.`
|
77
|
+
}
|
78
|
+
],
|
79
|
+
model: "gpt-4o-mini",
|
80
|
+
});
|
81
|
+
|
82
|
+
return completion.choices[0].message.content || "Could not generate summary. Please visit the website directly.";
|
83
|
+
}
|
@@ -0,0 +1,96 @@
|
|
1
|
+
import { XMTPContext } from "@xmtp/message-kit";
|
2
|
+
import type { Skill } from "@xmtp/message-kit";
|
3
|
+
|
4
|
+
export const wordle: Skill[] = [
|
5
|
+
{
|
6
|
+
skill: "wordle",
|
7
|
+
handler: handler,
|
8
|
+
examples: ["/wordle"],
|
9
|
+
description: "Play wordle.",
|
10
|
+
},
|
11
|
+
{
|
12
|
+
skill: "arena",
|
13
|
+
examples: ["/arena 3 15"],
|
14
|
+
handler: handler,
|
15
|
+
description: "Play arena.",
|
16
|
+
params: {
|
17
|
+
wordCount: {
|
18
|
+
default: 3,
|
19
|
+
type: "number",
|
20
|
+
},
|
21
|
+
audienceSize: {
|
22
|
+
default: 15,
|
23
|
+
type: "number",
|
24
|
+
},
|
25
|
+
},
|
26
|
+
},
|
27
|
+
];
|
28
|
+
|
29
|
+
async function handler(context: XMTPContext) {
|
30
|
+
const {
|
31
|
+
message: {
|
32
|
+
content: { skill },
|
33
|
+
},
|
34
|
+
} = context;
|
35
|
+
|
36
|
+
if (skill === "arena") {
|
37
|
+
await handleArenaMessage(context);
|
38
|
+
} else if (skill === "wordle") {
|
39
|
+
await context.send("https://framedl.xyz");
|
40
|
+
} else if (skill === "help") {
|
41
|
+
await context.send(
|
42
|
+
"For using this bot you can use the following commands:\n\n" +
|
43
|
+
"/wordle, @wordle, 🔍, 🔎 - To start the game\n" +
|
44
|
+
"/arena <word count> <audience size> - To start the arena game\n" +
|
45
|
+
"/help - To see commands",
|
46
|
+
);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
async function handleArenaMessage(context: XMTPContext) {
|
50
|
+
const {
|
51
|
+
message: {
|
52
|
+
content: { text },
|
53
|
+
},
|
54
|
+
members,
|
55
|
+
} = context;
|
56
|
+
|
57
|
+
const apiKey = process.env.FRAMEDL_API_KEY;
|
58
|
+
if (!apiKey) {
|
59
|
+
console.log("FRAMEDL_API_KEY is not set");
|
60
|
+
await context.send("https://www.framedl.xyz/games/arena/create");
|
61
|
+
return;
|
62
|
+
}
|
63
|
+
const participantCount = members && members.length ? members.length - 1 : 0;
|
64
|
+
const args = text?.split(" ") ?? [];
|
65
|
+
const wordCountArg = args[1] ? parseInt(args[1], 10) : 3;
|
66
|
+
const audienceSizeArg = args[2] ? parseInt(args[2], 10) : participantCount;
|
67
|
+
if (isNaN(wordCountArg) || isNaN(audienceSizeArg)) {
|
68
|
+
await context.send(
|
69
|
+
"usage: /arena <word count> <audience size>\n\n" +
|
70
|
+
"word count: number of words in the arena (default: 3, min: 1, max: 9)\n" +
|
71
|
+
"audience size: number of audience members (default: number of participants excluding wordle bot, min: 1, max: 15)",
|
72
|
+
);
|
73
|
+
return;
|
74
|
+
}
|
75
|
+
|
76
|
+
const audienceSize = Math.max(1, Math.min(15, audienceSizeArg));
|
77
|
+
const wordCount = Math.max(1, Math.min(9, wordCountArg));
|
78
|
+
|
79
|
+
try {
|
80
|
+
const response = await fetch("https://www.framedl.xyz/api/arenas", {
|
81
|
+
method: "POST",
|
82
|
+
body: JSON.stringify({ wordCount, audienceSize }),
|
83
|
+
headers: {
|
84
|
+
"Content-Type": "application/json",
|
85
|
+
"x-framedl-api-key": apiKey,
|
86
|
+
},
|
87
|
+
});
|
88
|
+
|
89
|
+
const data = (await response.json()) as { arenaUrl: string };
|
90
|
+
|
91
|
+
await context.send(data.arenaUrl);
|
92
|
+
} catch (error) {
|
93
|
+
console.error(error);
|
94
|
+
await context.send("https://www.framedl.xyz/games/arena/create");
|
95
|
+
}
|
96
|
+
}
|