create-message-kit 1.2.21 → 1.2.23
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/README.md +2 -5
- package/index.js +7 -3
- package/package.json +2 -2
- package/templates/coinbase-agent/src/index.ts +5 -7
- package/templates/ens/src/index.ts +4 -24
- package/templates/ens/src/skills/info.ts +6 -3
- package/templates/faucet/src/index.ts +5 -16
- package/templates/gated-group/src/index.ts +2 -2
- package/templates/gm/src/index.ts +15 -7
- package/templates/hackathon-store/.env.example +6 -0
- package/templates/{thegeneralstore → hackathon-store}/package.json +1 -5
- package/templates/hackathon-store/src/index.ts +47 -0
- package/templates/{thegeneralstore → hackathon-store}/src/plugins/notion.ts +0 -29
- package/templates/hackathon-store/src/prompt.md +27 -0
- package/templates/playground/src/index.ts +9 -8
- package/templates/playground/src/vibes/chill.ts +9 -0
- package/templates/playground/src/vibes/friendly.ts +9 -0
- package/templates/playground/src/vibes/inquisitive.ts +10 -0
- package/templates/playground/src/vibes/playful.ts +10 -0
- package/templates/playground/src/vibes/professional.ts +9 -0
- package/templates/simple/src/index.ts +10 -9
- package/templates/toss/.env.example +1 -0
- package/templates/toss/src/index.ts +7 -10
- package/templates/toss/src/skills/toss.ts +0 -114
- package/templates/toss/src/skills/waas.ts +116 -0
- package/templates.json +58 -0
- package/templates/thegeneralstore/.env.example +0 -9
- package/templates/thegeneralstore/src/data/db.json +0 -812
- package/templates/thegeneralstore/src/index.ts +0 -37
- package/templates/thegeneralstore/src/plugins/learnweb3.ts +0 -96
- package/templates/thegeneralstore/src/plugins/lowdb.ts +0 -11
- package/templates/thegeneralstore/src/plugins/redis.ts +0 -15
- package/templates/thegeneralstore/src/prompt.md +0 -51
- package/templates/thegeneralstore/src/prompt.ts +0 -3
- package/templates/thegeneralstore/src/skills/faucet.ts +0 -114
- package/templates/thegeneralstore/src/skills/notion.ts +0 -17
- package/templates/thegeneralstore/src/skills/poap.ts +0 -48
- package/templates/thegeneralstore/src/skills.ts +0 -37
- /package/templates/{thegeneralstore → hackathon-store}/.cursorrules +0 -0
- /package/templates/{thegeneralstore → hackathon-store}/.yarnrc.yml +0 -0
package/README.md
CHANGED
@@ -9,13 +9,10 @@ bun create message-kit
|
|
9
9
|
```
|
10
10
|
|
11
11
|
```bash
|
12
|
-
npx create-message-kit
|
12
|
+
npx create-message-kit@latest
|
13
13
|
```
|
14
14
|
|
15
15
|
```bash
|
16
16
|
yarn create message-kit
|
17
|
-
|
18
|
-
|
19
|
-
```bash [npm]
|
20
|
-
npm init message-kit
|
17
|
+
// use yarn create message-kit@latest in yarn > v2
|
21
18
|
```
|
package/index.js
CHANGED
@@ -7,7 +7,7 @@ import { default as fs } from "fs-extra";
|
|
7
7
|
import { isCancel } from "@clack/prompts";
|
8
8
|
import { detect } from "detect-package-manager";
|
9
9
|
import pc from "picocolors";
|
10
|
-
const defVersion = "1.2.
|
10
|
+
const defVersion = "1.2.23";
|
11
11
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
12
12
|
|
13
13
|
// Read package.json to get the version
|
@@ -140,6 +140,11 @@ async function gatherProjectInfo() {
|
|
140
140
|
const name = kebabcase(displayName);
|
141
141
|
const destDir = resolve(process.cwd(), name);
|
142
142
|
|
143
|
+
// Remove existing directory if it exists
|
144
|
+
if (fs.existsSync(destDir)) {
|
145
|
+
fs.removeSync(destDir);
|
146
|
+
}
|
147
|
+
|
143
148
|
// Copy template files
|
144
149
|
fs.copySync(templateDir, destDir);
|
145
150
|
|
@@ -214,8 +219,7 @@ async function detectPackageManager() {
|
|
214
219
|
|
215
220
|
const userAgent = process.env.npm_config_user_agent;
|
216
221
|
|
217
|
-
|
218
|
-
if (userAgent?.startsWith("npm")) {
|
222
|
+
if (userAgent?.startsWith("npm") || userAgent?.startsWith("npx")) {
|
219
223
|
return "npm";
|
220
224
|
}
|
221
225
|
|
package/package.json
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"name": "create-message-kit",
|
3
|
-
"version": "1.2.
|
3
|
+
"version": "1.2.23",
|
4
4
|
"license": "MIT",
|
5
5
|
"type": "module",
|
6
6
|
"main": "index.js",
|
7
7
|
"module": "index.js",
|
8
8
|
"bin": "index.js",
|
9
9
|
"files": [
|
10
|
-
"
|
10
|
+
"templates.json",
|
11
11
|
"templates/**/*"
|
12
12
|
],
|
13
13
|
"scripts": {
|
@@ -14,11 +14,8 @@ export const agent: Agent = {
|
|
14
14
|
name: "Swap Bot",
|
15
15
|
tag: "@base",
|
16
16
|
description: "Swap bot for base.",
|
17
|
-
skills: [
|
18
|
-
|
19
|
-
|
20
|
-
run(
|
21
|
-
async (context: XMTPContext) => {
|
17
|
+
skills: [swapSkill, mintSkill, dripSkill, paySkill],
|
18
|
+
onMessage: async (context: XMTPContext) => {
|
22
19
|
const {
|
23
20
|
message: { sender },
|
24
21
|
agent,
|
@@ -27,5 +24,6 @@ run(
|
|
27
24
|
let prompt = await replaceVariables(systemPrompt, sender.address, agent);
|
28
25
|
await agentReply(context, prompt);
|
29
26
|
},
|
30
|
-
|
31
|
-
|
27
|
+
};
|
28
|
+
|
29
|
+
run(agent);
|
@@ -13,41 +13,21 @@ import { register } from "./skills/register.js";
|
|
13
13
|
import { renew } from "./skills/renew.js";
|
14
14
|
import { pay } from "./skills/pay.js";
|
15
15
|
import { reset } from "./skills/reset.js";
|
16
|
-
import fs from "fs";
|
17
16
|
|
18
|
-
// [!region skills]
|
19
17
|
export const agent: Agent = {
|
20
18
|
name: "Ens Agent",
|
21
19
|
tag: "@bot",
|
22
20
|
description: "A ens agent with a lot of skills.",
|
23
|
-
skills: [
|
24
|
-
|
25
|
-
...cool,
|
26
|
-
...info,
|
27
|
-
...register,
|
28
|
-
...renew,
|
29
|
-
...reset,
|
30
|
-
...pay,
|
31
|
-
],
|
32
|
-
};
|
33
|
-
// [!endregion skills]
|
34
|
-
|
35
|
-
// [!region run1]
|
36
|
-
run(
|
37
|
-
async (context: XMTPContext) => {
|
21
|
+
skills: [checkDomain, cool, info, register, renew, reset, pay],
|
22
|
+
onMessage: async (context: XMTPContext) => {
|
38
23
|
const {
|
39
24
|
message: { sender },
|
40
25
|
agent,
|
41
26
|
} = context;
|
42
27
|
|
43
28
|
let prompt = await replaceVariables(systemPrompt, sender.address, agent);
|
44
|
-
// [!endregion run1]
|
45
|
-
//This is only used for to update the docs.
|
46
|
-
fs.writeFileSync("example_prompt.md", prompt);
|
47
|
-
// [!region run2]
|
48
29
|
await agentReply(context, prompt);
|
49
30
|
},
|
50
|
-
|
51
|
-
);
|
31
|
+
};
|
52
32
|
|
53
|
-
|
33
|
+
run(agent);
|
@@ -48,9 +48,12 @@ export async function handler(context: XMTPContext) {
|
|
48
48
|
message += `\n\nWould you like to tip the domain owner for getting there first 🤣?`;
|
49
49
|
message = message.trim();
|
50
50
|
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
const { v2, v3 } = await context.isOnXMTP(
|
52
|
+
context.client,
|
53
|
+
context.v2client,
|
54
|
+
sender?.address,
|
55
|
+
);
|
56
|
+
if (v2 || v3) {
|
54
57
|
await context.send(
|
55
58
|
`Ah, this domains is in XMTP, you can message it directly`,
|
56
59
|
);
|
@@ -7,33 +7,22 @@ import {
|
|
7
7
|
} from "@xmtp/message-kit";
|
8
8
|
import { systemPrompt } from "./prompt.js";
|
9
9
|
import { faucet } from "./skills/faucet.js";
|
10
|
-
import fs from "fs";
|
11
10
|
|
12
11
|
// [!region skills]
|
13
12
|
export const agent: Agent = {
|
14
13
|
name: "Faucet Agent",
|
15
14
|
tag: "@bot",
|
16
15
|
description: "A faucet delivery agent.",
|
17
|
-
skills: [
|
18
|
-
|
19
|
-
// [!endregion skills]
|
20
|
-
|
21
|
-
// [!region run1]
|
22
|
-
run(
|
23
|
-
async (context: XMTPContext) => {
|
16
|
+
skills: [faucet],
|
17
|
+
onMessage: async (context: XMTPContext) => {
|
24
18
|
const {
|
25
19
|
message: { sender },
|
26
20
|
agent,
|
27
21
|
} = context;
|
28
22
|
|
29
23
|
let prompt = await replaceVariables(systemPrompt, sender.address, agent);
|
30
|
-
|
31
|
-
//This is only used for to update the docs.
|
32
|
-
fs.writeFileSync("example_prompt.md", prompt);
|
33
|
-
// [!region run2]
|
24
|
+
|
34
25
|
await agentReply(context, prompt);
|
35
26
|
},
|
36
|
-
|
37
|
-
);
|
38
|
-
|
39
|
-
// [!endregion run2]
|
27
|
+
};
|
28
|
+
run(agent);
|
@@ -1,8 +1,16 @@
|
|
1
|
-
import { run } from "@xmtp/message-kit";
|
1
|
+
import { run, Agent } from "@xmtp/message-kit";
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
const agent: Agent = {
|
4
|
+
name: "Gm Bot",
|
5
|
+
tag: "@bot",
|
6
|
+
description: "Gm bot.",
|
7
|
+
skills: [],
|
8
|
+
onMessage: async (context) => {
|
9
|
+
const { group } = context;
|
10
|
+
if (!group) {
|
11
|
+
await context.send(`gm`);
|
12
|
+
}
|
13
|
+
},
|
14
|
+
};
|
15
|
+
|
16
|
+
run(agent);
|
@@ -1,5 +1,5 @@
|
|
1
1
|
{
|
2
|
-
"name": "
|
2
|
+
"name": "hackathon-store",
|
3
3
|
"private": true,
|
4
4
|
"type": "module",
|
5
5
|
"scripts": {
|
@@ -14,10 +14,6 @@
|
|
14
14
|
"axios": "^1.7.7",
|
15
15
|
"lowdb": "^7.0.1"
|
16
16
|
},
|
17
|
-
"devDependencies": {
|
18
|
-
"@types/node": "^20.14.2",
|
19
|
-
"typescript": "^5.4.5"
|
20
|
-
},
|
21
17
|
"engines": {
|
22
18
|
"node": ">=20"
|
23
19
|
}
|
@@ -0,0 +1,47 @@
|
|
1
|
+
import {
|
2
|
+
agentReply,
|
3
|
+
XMTPContext,
|
4
|
+
replaceVariables,
|
5
|
+
run,
|
6
|
+
} from "@xmtp/message-kit";
|
7
|
+
import { downloadPage } from "./plugins/notion.js";
|
8
|
+
import fs from "fs";
|
9
|
+
import { Agent } from "@xmtp/message-kit";
|
10
|
+
setupFiles();
|
11
|
+
|
12
|
+
const agent: Agent = {
|
13
|
+
name: "Hackathon Store",
|
14
|
+
tag: "@store",
|
15
|
+
description: "Hackathon Store",
|
16
|
+
skills: [],
|
17
|
+
onMessage: async (context: XMTPContext) => {
|
18
|
+
const {
|
19
|
+
message: {
|
20
|
+
sender,
|
21
|
+
content: { skill },
|
22
|
+
},
|
23
|
+
agent,
|
24
|
+
} = context;
|
25
|
+
|
26
|
+
if (skill === "update") {
|
27
|
+
const page = await downloadPage();
|
28
|
+
fs.writeFileSync("src/prompt.md", page);
|
29
|
+
await context.reply("Notion DB updated");
|
30
|
+
}
|
31
|
+
|
32
|
+
let systemPrompt = await getPrompt();
|
33
|
+
let prompt = await replaceVariables(systemPrompt, sender.address, agent);
|
34
|
+
await agentReply(context, prompt);
|
35
|
+
},
|
36
|
+
};
|
37
|
+
|
38
|
+
run(agent);
|
39
|
+
|
40
|
+
async function getPrompt() {
|
41
|
+
return fs.readFileSync("src/prompt.md", "utf8");
|
42
|
+
}
|
43
|
+
async function setupFiles() {
|
44
|
+
const page = await downloadPage();
|
45
|
+
fs.writeFileSync("src/prompt.md", page);
|
46
|
+
console.log("Notion DB updated");
|
47
|
+
}
|
@@ -58,32 +58,3 @@ export async function downloadPage() {
|
|
58
58
|
.join("\n");
|
59
59
|
return markdown;
|
60
60
|
}
|
61
|
-
export async function downloadPoapTable() {
|
62
|
-
const response = await notion.databases.query({
|
63
|
-
database_id: poapsID as string,
|
64
|
-
});
|
65
|
-
|
66
|
-
const poapTable = response.results.map((page: any) => {
|
67
|
-
const url = page.properties.Url.url;
|
68
|
-
const address = page.properties.Address.title[0]?.plain_text;
|
69
|
-
const id = page.id;
|
70
|
-
return { url, address, id };
|
71
|
-
});
|
72
|
-
return poapTable as { url: string; address: string; id: string }[];
|
73
|
-
}
|
74
|
-
export async function updatePoapAddress(dbRowId: string, address: string) {
|
75
|
-
await notion.pages.update({
|
76
|
-
page_id: dbRowId as string,
|
77
|
-
properties: {
|
78
|
-
Address: {
|
79
|
-
type: "title",
|
80
|
-
title: [
|
81
|
-
{
|
82
|
-
type: "text",
|
83
|
-
text: { content: address },
|
84
|
-
},
|
85
|
-
],
|
86
|
-
},
|
87
|
-
},
|
88
|
-
});
|
89
|
-
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
You are a helpful agent that lives inside a messaging app. You manage the general store from XMTP that delivers goodies, POAPs and testnet funds.
|
2
|
+
|
3
|
+
{rules}
|
4
|
+
|
5
|
+
{user_context}
|
6
|
+
|
7
|
+
{skills}
|
8
|
+
|
9
|
+
### Goodies
|
10
|
+
- When greeted for the first time, give the full menu.
|
11
|
+
- The user can select the option by number or name
|
12
|
+
- Once the option is selected confirm the order
|
13
|
+
## Response Scenarios:
|
14
|
+
- Welcome message:
|
15
|
+
Welcome to The General Store powered by ENS + XMTP, where web3 builders can get supplies, anytime, day or night.
|
16
|
+
Below is our menu. Let us know the number of the item you want, and it's yours. If it's a digital good, our bot will deliver those items right to your wallet.
|
17
|
+
- Chewing Gum
|
18
|
+
- TicTacs
|
19
|
+
- Deodorant
|
20
|
+
- RedBull
|
21
|
+
- Toothbrush
|
22
|
+
- Toothpaste
|
23
|
+
- XMTP Swag
|
24
|
+
- Testnet funds
|
25
|
+
- POAP
|
26
|
+
- Delivering goodies
|
27
|
+
Let me get your TicTacs... Your order is confirmed. Enjoy!
|
@@ -15,11 +15,8 @@ export const agent: Agent = {
|
|
15
15
|
name: "Playground Agent",
|
16
16
|
tag: "@bot",
|
17
17
|
description: "A playground agent with a lot of skills.",
|
18
|
-
skills: [
|
19
|
-
|
20
|
-
|
21
|
-
run(
|
22
|
-
async (context: XMTPContext) => {
|
18
|
+
skills: [web, cryptoPrice, search],
|
19
|
+
onMessage: async (context: XMTPContext) => {
|
23
20
|
const {
|
24
21
|
message: {
|
25
22
|
sender,
|
@@ -29,9 +26,13 @@ run(
|
|
29
26
|
} = context;
|
30
27
|
|
31
28
|
let prompt = await replaceVariables(systemPrompt, sender.address, agent);
|
32
|
-
//This is only used for to update the docs.
|
29
|
+
// This is only used for to update the docs.
|
33
30
|
fs.writeFileSync("example_prompt.md", prompt);
|
34
31
|
await agentReply(context, prompt);
|
35
32
|
},
|
36
|
-
|
37
|
-
|
33
|
+
config: {
|
34
|
+
experimental: true,
|
35
|
+
},
|
36
|
+
};
|
37
|
+
|
38
|
+
run(agent);
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { Vibe } from "@xmtp/message-kit";
|
2
|
+
|
3
|
+
export const chill: Vibe = {
|
4
|
+
name: "Chill",
|
5
|
+
description:
|
6
|
+
"A relaxed and easy-going personality, embodying the essence of tranquility and serenity. This vibe exudes a sense of calmness that soothes the soul and invites a peaceful atmosphere.",
|
7
|
+
tone: "calm and composed, like a gentle breeze on a warm summer day",
|
8
|
+
style: "laid-back, with an effortless grace that flows like a serene river",
|
9
|
+
};
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { Vibe } from "@xmtp/message-kit";
|
2
|
+
|
3
|
+
export const friendly: Vibe = {
|
4
|
+
name: "Friendly",
|
5
|
+
description:
|
6
|
+
"A warm and welcoming personality, radiating kindness and empathy. This vibe is like a comforting embrace, making everyone feel at home and valued.",
|
7
|
+
tone: "cheerful and uplifting, like the first rays of sunshine after a storm",
|
8
|
+
style: "approachable and open-hearted, with a smile that lights up the room",
|
9
|
+
};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { Vibe } from "@xmtp/message-kit";
|
2
|
+
|
3
|
+
export const inquisitive: Vibe = {
|
4
|
+
name: "Inquisitive",
|
5
|
+
description:
|
6
|
+
"A curious and questioning nature, driven by an insatiable thirst for knowledge. This vibe is like a detective on a quest for truth, always seeking to uncover the mysteries of the world.",
|
7
|
+
tone: "curious and probing, like a cat exploring a new territory",
|
8
|
+
style:
|
9
|
+
"engaging and thought-provoking, with a knack for sparking lively discussions",
|
10
|
+
};
|
@@ -0,0 +1,10 @@
|
|
1
|
+
import { Vibe } from "@xmtp/message-kit";
|
2
|
+
|
3
|
+
export const playful: Vibe = {
|
4
|
+
name: "Playful",
|
5
|
+
description:
|
6
|
+
"A fun and light-hearted character, full of whimsy and joy. This vibe is like a child at play, bringing laughter and spontaneity to every moment.",
|
7
|
+
tone: "jovial and exuberant, like a carnival in full swing",
|
8
|
+
style:
|
9
|
+
"casual and carefree, with a dash of mischief and a twinkle in the eye",
|
10
|
+
};
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { Vibe } from "@xmtp/message-kit";
|
2
|
+
|
3
|
+
export const professional: Vibe = {
|
4
|
+
name: "Professional",
|
5
|
+
description:
|
6
|
+
"A formal and business-like demeanor, exuding confidence and competence. This vibe is like a seasoned diplomat, navigating complex situations with poise and precision.",
|
7
|
+
tone: "serious and authoritative, like a judge delivering a verdict",
|
8
|
+
style: "polished and refined, with an air of sophistication and elegance",
|
9
|
+
};
|
@@ -5,7 +5,6 @@ import {
|
|
5
5
|
XMTPContext,
|
6
6
|
Agent,
|
7
7
|
} from "@xmtp/message-kit";
|
8
|
-
|
9
8
|
import { systemPrompt } from "./prompt.js";
|
10
9
|
|
11
10
|
export const agent: Agent = {
|
@@ -13,13 +12,15 @@ export const agent: Agent = {
|
|
13
12
|
tag: "@bot",
|
14
13
|
description: "Use GPT to generate text responses.",
|
15
14
|
skills: [],
|
16
|
-
|
15
|
+
onMessage: async (context: XMTPContext) => {
|
16
|
+
const {
|
17
|
+
message: { sender },
|
18
|
+
agent,
|
19
|
+
} = context;
|
17
20
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
21
|
+
let prompt = await replaceVariables(systemPrompt, sender.address, agent);
|
22
|
+
await agentReply(context, prompt);
|
23
|
+
},
|
24
|
+
};
|
22
25
|
|
23
|
-
|
24
|
-
await agentReply(context, prompt);
|
25
|
-
});
|
26
|
+
run(agent);
|
@@ -2,5 +2,6 @@ KEY= # the private key of the wallet
|
|
2
2
|
TEST_ENCRYPTION_KEY= # a different private key for encryption
|
3
3
|
OPENAI_API_KEY= # the API key for OpenAI
|
4
4
|
REDIS_CONNECTION_STRING= # the connection to the toss database in Redis
|
5
|
+
COINBASE_APP_ID= # the app id for Coinbase
|
5
6
|
COINBASE_API_KEY_NAME= # the API key name for Coinbase
|
6
7
|
COINBASE_API_KEY_PRIVATE_KEY= # the private key for Coinbase
|
@@ -8,25 +8,22 @@ import {
|
|
8
8
|
|
9
9
|
import { systemPrompt } from "./prompt.js";
|
10
10
|
import { toss } from "./skills/toss.js";
|
11
|
-
import
|
11
|
+
import { waas } from "./skills/waas.js";
|
12
12
|
|
13
13
|
export const agent: Agent = {
|
14
14
|
name: "Toss Bot",
|
15
15
|
tag: "@toss",
|
16
16
|
description: "Create a coin toss.",
|
17
|
-
skills: [
|
18
|
-
|
19
|
-
|
20
|
-
run(
|
21
|
-
async (context: XMTPContext) => {
|
17
|
+
skills: [toss, waas],
|
18
|
+
onMessage: async (context: XMTPContext) => {
|
22
19
|
const {
|
23
20
|
message: { sender },
|
24
21
|
} = context;
|
25
22
|
|
26
23
|
let prompt = await replaceVariables(systemPrompt, sender.address, agent);
|
27
|
-
|
28
|
-
fs.writeFileSync("example_prompt.md", prompt);
|
24
|
+
|
29
25
|
await agentReply(context, prompt);
|
30
26
|
},
|
31
|
-
|
32
|
-
|
27
|
+
};
|
28
|
+
|
29
|
+
run(agent);
|
@@ -22,52 +22,12 @@ export const toss: Skill[] = [
|
|
22
22
|
},
|
23
23
|
},
|
24
24
|
},
|
25
|
-
{
|
26
|
-
skill: "create",
|
27
|
-
description: "Create an agent wallet.",
|
28
|
-
handler: handleDM,
|
29
|
-
examples: ["/create"],
|
30
|
-
},
|
31
|
-
{
|
32
|
-
skill: "fund",
|
33
|
-
description: "Fund your account.",
|
34
|
-
handler: handleDM,
|
35
|
-
examples: ["/fund 10"],
|
36
|
-
params: {
|
37
|
-
amount: {
|
38
|
-
type: "number",
|
39
|
-
},
|
40
|
-
},
|
41
|
-
},
|
42
|
-
{
|
43
|
-
skill: "withdraw",
|
44
|
-
description: "Withdraw funds from your account.",
|
45
|
-
handler: handleDM,
|
46
|
-
examples: ["/withdraw 10"],
|
47
|
-
params: {
|
48
|
-
amount: {
|
49
|
-
type: "number",
|
50
|
-
},
|
51
|
-
},
|
52
|
-
},
|
53
|
-
{
|
54
|
-
skill: "help",
|
55
|
-
description: "Get help with tossing.",
|
56
|
-
handler: handleDM,
|
57
|
-
examples: ["/help"],
|
58
|
-
},
|
59
25
|
{
|
60
26
|
skill: "cancel",
|
61
27
|
description: "Cancel a toss.",
|
62
28
|
handler: handleCancelToss,
|
63
29
|
examples: ["/cancel"],
|
64
30
|
},
|
65
|
-
{
|
66
|
-
skill: "balance",
|
67
|
-
description: "Check your balance.",
|
68
|
-
handler: handleDM,
|
69
|
-
examples: ["/balance"],
|
70
|
-
},
|
71
31
|
{
|
72
32
|
skill: "join",
|
73
33
|
description: "Join a toss.",
|
@@ -356,77 +316,3 @@ export async function handleTossStatus(context: XMTPContext) {
|
|
356
316
|
if (!tossData) return;
|
357
317
|
await context.reply(await generateTossStatusMessage(tossData));
|
358
318
|
}
|
359
|
-
|
360
|
-
export async function handleDM(context: XMTPContext) {
|
361
|
-
const {
|
362
|
-
message: {
|
363
|
-
content: {
|
364
|
-
skill,
|
365
|
-
params: { amount },
|
366
|
-
},
|
367
|
-
sender,
|
368
|
-
},
|
369
|
-
group,
|
370
|
-
walletService,
|
371
|
-
} = context;
|
372
|
-
if (group && skill == "help") {
|
373
|
-
await context.reply("Check your DM's");
|
374
|
-
await context.sendTo(DM_HELP_MESSAGE, [sender.address]);
|
375
|
-
return;
|
376
|
-
}
|
377
|
-
if (skill === "help") {
|
378
|
-
await context.send(DM_HELP_MESSAGE);
|
379
|
-
} else if (skill === "create") {
|
380
|
-
const walletExist = await walletService.getWallet(sender.address);
|
381
|
-
if (walletExist) {
|
382
|
-
await context.reply("You already have an agent wallet.");
|
383
|
-
return;
|
384
|
-
}
|
385
|
-
await walletService.createWallet(sender.address);
|
386
|
-
} else if (skill === "balance") {
|
387
|
-
const userWallet = await walletService.getWallet(sender.address);
|
388
|
-
|
389
|
-
context.sendTo(
|
390
|
-
`Your agent wallet for address is ${sender.address}\nBalance: $${await walletService.checkBalance(sender.address)}`,
|
391
|
-
[sender.address],
|
392
|
-
);
|
393
|
-
} else if (skill === "fund") {
|
394
|
-
const balance = await walletService.checkBalance(sender.address);
|
395
|
-
if (balance === 10) {
|
396
|
-
await context.reply("You have maxed out your funds.");
|
397
|
-
return;
|
398
|
-
} else if (amount) {
|
399
|
-
if (amount + balance <= 10) {
|
400
|
-
return walletService.requestFunds(Number(amount));
|
401
|
-
} else {
|
402
|
-
await context.send("Wrong amount. Max 10 USDC.");
|
403
|
-
return;
|
404
|
-
}
|
405
|
-
}
|
406
|
-
await context.reply(
|
407
|
-
`You have $${balance} in your account. You can fund up to $${10 - balance} more.`,
|
408
|
-
);
|
409
|
-
const options = Array.from({ length: Math.floor(10 - balance) }, (_, i) =>
|
410
|
-
(i + 1).toString(),
|
411
|
-
);
|
412
|
-
const response = await context.awaitResponse(
|
413
|
-
`Please specify the amount of USDC to prefund (1 to ${10 - balance}):`,
|
414
|
-
options,
|
415
|
-
);
|
416
|
-
return walletService.requestFunds(Number(response));
|
417
|
-
} else if (skill === "withdraw") {
|
418
|
-
const balance = await walletService.checkBalance(sender.address);
|
419
|
-
if (balance === 0) {
|
420
|
-
await context.reply("You have no funds to withdraw.");
|
421
|
-
return;
|
422
|
-
}
|
423
|
-
const options = Array.from({ length: Math.floor(balance) }, (_, i) =>
|
424
|
-
(i + 1).toString(),
|
425
|
-
);
|
426
|
-
const response = await context.awaitResponse(
|
427
|
-
`Please specify the amount of USDC to withdraw (1 to ${balance}):`,
|
428
|
-
options,
|
429
|
-
);
|
430
|
-
await walletService.withdrawFunds(Number(response));
|
431
|
-
}
|
432
|
-
}
|