create-message-kit 1.0.11 → 1.0.12

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 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
- npx create-message-kit@latest
8
+ bun create message-kit
9
9
  ```
10
10
 
11
11
  ```bash
12
- bun create message-kit
12
+ npx create-message-kit@latest
13
13
  ```
14
14
 
15
15
  ```bash
@@ -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
- // To reply, just call `reply` on the HandlerContext.
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 as string, history: messages };
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
@@ -244,7 +243,7 @@ Follow these steps to set up and run the project:
244
243
 
245
244
  3. **Run the project:**
246
245
  \`\`\`sh
247
- ${packageManager} dev
246
+ ${packageManager === "npm" ? "npm run" : packageManager} dev
248
247
  \`\`\`
249
248
 
250
249
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-message-kit",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "index.js",