create-message-kit 1.0.11 → 1.0.13
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 -2
- package/examples/gm/src/index.ts +2 -1
- package/examples/group/src/handler/loyalty.ts +0 -19
- package/examples/group/src/handler/tipping.ts +0 -7
- package/examples/group/src/index.ts +0 -25
- package/examples/group/src/lib/openai.ts +22 -7
- package/index.js +15 -15
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,11 +5,11 @@ Is a command-line interface tool designed to help developers create and manage t
|
|
|
5
5
|
To install it run the following command:
|
|
6
6
|
|
|
7
7
|
```bash
|
|
8
|
-
|
|
8
|
+
bun create message-kit
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
|
-
|
|
12
|
+
npx create-message-kit@latest
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
```bash
|
package/examples/gm/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { run, HandlerContext } from "@xmtp/message-kit";
|
|
|
3
3
|
run(async (context: HandlerContext) => {
|
|
4
4
|
// Get the message and the address from the sender
|
|
5
5
|
const { content, sender } = context.message;
|
|
6
|
-
|
|
6
|
+
|
|
7
|
+
// To reply, just call `reply` on the HandlerContext
|
|
7
8
|
await context.send(`gm`);
|
|
8
9
|
});
|
|
@@ -50,24 +50,5 @@ export async function handler(context: HandlerContext, fake?: boolean) {
|
|
|
50
50
|
uniqueId: adminAddress?.username ?? "",
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
|
-
} else if (typeId === "reaction" && group) {
|
|
54
|
-
const { content: emoji, action } = content;
|
|
55
|
-
const msg = await getMessageById(content.reference);
|
|
56
|
-
if (action === "added") {
|
|
57
|
-
const adminAddress = members?.find(
|
|
58
|
-
(member: User) => member.inboxId === msg?.senderInboxId,
|
|
59
|
-
);
|
|
60
|
-
let points = 1;
|
|
61
|
-
if (emoji === "👎") {
|
|
62
|
-
points = -10;
|
|
63
|
-
} else if (emoji === "🎩") {
|
|
64
|
-
points = 10;
|
|
65
|
-
}
|
|
66
|
-
await stack?.track("reaction", {
|
|
67
|
-
points,
|
|
68
|
-
account: adminAddress?.address ?? "",
|
|
69
|
-
uniqueId: adminAddress?.username ?? "",
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
53
|
}
|
|
73
54
|
}
|
|
@@ -36,13 +36,6 @@ export async function handler(context: HandlerContext) {
|
|
|
36
36
|
amount = extractedAmount || 10; // Default amount if not specified
|
|
37
37
|
receivers = username; // Extract receiver from parameters
|
|
38
38
|
}
|
|
39
|
-
} else if (typeId === "reaction" && replyReceiver) {
|
|
40
|
-
const { content: reaction, action } = content;
|
|
41
|
-
// Process reactions, specifically tipping added reactions
|
|
42
|
-
if ((reaction === "🎩" || reaction === "degen") && action === "added") {
|
|
43
|
-
amount = 10; // Set a fixed amount for reactions
|
|
44
|
-
receivers = [replyReceiver];
|
|
45
|
-
}
|
|
46
39
|
}
|
|
47
40
|
if (!sender || receivers.length === 0 || amount === 0) {
|
|
48
41
|
context.reply("Sender or receiver or amount not found.");
|
|
@@ -9,9 +9,6 @@ run(async (context: HandlerContext) => {
|
|
|
9
9
|
message: { typeId },
|
|
10
10
|
} = context;
|
|
11
11
|
switch (typeId) {
|
|
12
|
-
case "reaction":
|
|
13
|
-
handleReaction(context);
|
|
14
|
-
break;
|
|
15
12
|
case "reply":
|
|
16
13
|
handleReply(context);
|
|
17
14
|
break;
|
|
@@ -41,28 +38,6 @@ async function handleReply(context: HandlerContext) {
|
|
|
41
38
|
console.log(chain);
|
|
42
39
|
handleTextMessage(context);
|
|
43
40
|
}
|
|
44
|
-
// Handle reaction messages
|
|
45
|
-
async function handleReaction(context: HandlerContext) {
|
|
46
|
-
const {
|
|
47
|
-
v2client,
|
|
48
|
-
getReplyChain,
|
|
49
|
-
version,
|
|
50
|
-
message: {
|
|
51
|
-
content: { content: emoji, action, reference },
|
|
52
|
-
},
|
|
53
|
-
} = context;
|
|
54
|
-
|
|
55
|
-
const { chain, isSenderInChain } = await getReplyChain(
|
|
56
|
-
reference,
|
|
57
|
-
version,
|
|
58
|
-
v2client.address,
|
|
59
|
-
);
|
|
60
|
-
console.log(chain);
|
|
61
|
-
|
|
62
|
-
if (action === "added" && (emoji === "degen" || emoji === "🎩")) {
|
|
63
|
-
await tipping(context);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
41
|
|
|
67
42
|
// Handle attachment messages
|
|
68
43
|
async function handleAttachment(context: HandlerContext) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import dotenv from "dotenv";
|
|
2
|
+
import { response } from "express";
|
|
2
3
|
dotenv.config();
|
|
3
4
|
|
|
4
5
|
import OpenAI from "openai";
|
|
@@ -32,14 +33,9 @@ export async function textGeneration(
|
|
|
32
33
|
role: "assistant",
|
|
33
34
|
content: reply || "No response from OpenAI.",
|
|
34
35
|
});
|
|
35
|
-
const cleanedReply = reply
|
|
36
|
-
?.replace(/(\*\*|__)(.*?)\1/g, "$2")
|
|
37
|
-
?.replace(/\[([^\]]+)\]\(([^)]+)\)/g, "$2")
|
|
38
|
-
?.replace(/^#+\s*(.*)$/gm, "$1")
|
|
39
|
-
?.replace(/`([^`]+)`/g, "$1")
|
|
40
|
-
?.replace(/^`|`$/g, "");
|
|
36
|
+
const cleanedReply = responseParser(reply as string);
|
|
41
37
|
|
|
42
|
-
return { reply: cleanedReply
|
|
38
|
+
return { reply: cleanedReply, history: messages };
|
|
43
39
|
} catch (error) {
|
|
44
40
|
console.error("Failed to fetch from OpenAI:", error);
|
|
45
41
|
throw error;
|
|
@@ -82,3 +78,22 @@ export async function vision(imageData: Uint8Array, systemPrompt: string) {
|
|
|
82
78
|
throw error;
|
|
83
79
|
}
|
|
84
80
|
}
|
|
81
|
+
|
|
82
|
+
export function responseParser(message: string) {
|
|
83
|
+
let trimmedMessage = message;
|
|
84
|
+
// Remove bold and underline markdown
|
|
85
|
+
trimmedMessage = trimmedMessage?.replace(/(\*\*|__)(.*?)\1/g, "$2");
|
|
86
|
+
// Remove markdown links, keeping only the URL
|
|
87
|
+
trimmedMessage = trimmedMessage?.replace(/\[([^\]]+)\]\(([^)]+)\)/g, "$2");
|
|
88
|
+
// Remove markdown headers
|
|
89
|
+
trimmedMessage = trimmedMessage?.replace(/^#+\s*(.*)$/gm, "$1");
|
|
90
|
+
// Remove inline code formatting
|
|
91
|
+
trimmedMessage = trimmedMessage?.replace(/`([^`]+)`/g, "$1");
|
|
92
|
+
// Remove single backticks at the start or end of the message
|
|
93
|
+
trimmedMessage = trimmedMessage?.replace(/^`|`$/g, "");
|
|
94
|
+
// Remove leading and trailing whitespace
|
|
95
|
+
trimmedMessage = trimmedMessage?.replace(/^\s+|\s+$/g, "");
|
|
96
|
+
// Remove any remaining leading or trailing whitespace
|
|
97
|
+
trimmedMessage = trimmedMessage.trim();
|
|
98
|
+
return trimmedMessage;
|
|
99
|
+
}
|
package/index.js
CHANGED
|
@@ -172,7 +172,6 @@ function createGitignore(destDir) {
|
|
|
172
172
|
.env
|
|
173
173
|
node_modules/
|
|
174
174
|
.gitignore
|
|
175
|
-
.cache/
|
|
176
175
|
.data/
|
|
177
176
|
dist/
|
|
178
177
|
.DS_Store
|
|
@@ -233,29 +232,30 @@ This project is generated using the [MessageKit](https://message-kit.vercel.app)
|
|
|
233
232
|
Follow these steps to set up and run the project:
|
|
234
233
|
|
|
235
234
|
1. **Navigate to the project directory:**
|
|
236
|
-
\`\`\`sh
|
|
237
|
-
cd ./${projectName}
|
|
238
|
-
\`\`\`
|
|
239
235
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
\`\`\`
|
|
236
|
+
\`\`\`sh
|
|
237
|
+
cd ./${projectName}
|
|
238
|
+
\`\`\`
|
|
244
239
|
|
|
245
|
-
|
|
246
|
-
\`\`\`sh
|
|
247
|
-
${packageManager} dev
|
|
248
|
-
\`\`\`
|
|
240
|
+
2. **Set up your environment variables:**
|
|
249
241
|
|
|
242
|
+
\`\`\`sh
|
|
243
|
+
${envExampleContent}
|
|
244
|
+
\`\`\`
|
|
250
245
|
|
|
251
|
-
|
|
246
|
+
3. **Install dependencies:**
|
|
252
247
|
|
|
253
|
-
|
|
248
|
+
\`\`\`sh
|
|
249
|
+
${packageManager} install
|
|
250
|
+
\`\`\`
|
|
251
|
+
|
|
252
|
+
4. **Run the project:**
|
|
254
253
|
|
|
255
254
|
\`\`\`sh
|
|
256
|
-
${
|
|
255
|
+
${packageManager === "npm" ? "npm run" : packageManager} dev
|
|
257
256
|
\`\`\`
|
|
258
257
|
|
|
258
|
+
5. Enjoy!
|
|
259
259
|
---
|
|
260
260
|
Made with ❤️ by [Ephemera](https://ephemerahq.com)
|
|
261
261
|
`;
|