create-message-kit 1.2.2 → 1.2.4

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.2.2",
3
+ "version": "1.2.4",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -1,4 +1,4 @@
1
- import { Resend } from 'resend';
1
+ import { Resend } from "resend";
2
2
  import { XMTPContext } from "@xmtp/message-kit";
3
3
  import type { Skill } from "@xmtp/message-kit";
4
4
 
@@ -9,7 +9,8 @@ export const registerSkill: Skill[] = [
9
9
  skill: "/todo",
10
10
  handler: handler,
11
11
  examples: ["/todo"],
12
- description: "Summarize your TODOs and send an email with the summary. Receives no parameters.",
12
+ description:
13
+ "Summarize your TODOs and send an email with the summary. Receives no parameters.",
13
14
  params: {},
14
15
  },
15
16
  ];
@@ -17,47 +18,57 @@ export const registerSkill: Skill[] = [
17
18
  export async function handler(context: XMTPContext) {
18
19
  const {
19
20
  message: {
20
- content: { reply },
21
+ content: { previousMsg },
21
22
  },
22
23
  } = context;
23
24
 
24
25
  let email = "";
25
-
26
- let intents=2
27
- while (intents>0) {
28
- const emailResponse = await context.awaitResponse("Please provide your email address to receive the TODO summary:");
26
+ if (!previousMsg) {
27
+ await context.send("You need to do it on a reply.");
28
+ return;
29
+ }
30
+ let intents = 2;
31
+ while (intents > 0) {
32
+ const emailResponse = await context.awaitResponse(
33
+ "Please provide your email address to receive the TODO summary:",
34
+ );
29
35
  email = emailResponse;
30
-
36
+
31
37
  // Basic email validation
32
38
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
33
39
  if (!emailRegex.test(email)) {
34
- await context.send("Invalid email format. Please try again with a valid email address.");
40
+ await context.send(
41
+ "Invalid email format. Please try again with a valid email address.",
42
+ );
35
43
  intents--;
36
44
  continue;
37
45
  }
38
46
  break;
39
47
  }
40
- if(intents==0){
41
- await context.send("I couldn't get your email address. Please try again later.");
42
- return;
43
- }
48
+ if (intents == 0) {
49
+ await context.send(
50
+ "I couldn't get your email address. Please try again later.",
51
+ );
52
+ return;
53
+ }
44
54
  try {
45
- let content={
46
- from: 'onboarding@resend.dev',
47
- to: email,
48
- subject: 'Your TODO Summary from Converse',
49
- html: `
50
- <h1>Your TODO Summary</h1>
51
- <p>${reply}</p>
52
- `
55
+ if (typeof previousMsg === "string") {
56
+ let content = {
57
+ from: "bot@mail.coin-toss.xyz",
58
+ to: email,
59
+ subject: "Your summary from Converse",
60
+ html: `
61
+ <h3>Your TODO Summary</h3>
62
+ <p>${previousMsg.replace(/\n/g, "<br>")}</p>
63
+ `,
64
+ };
65
+ await resend.emails.send(content);
66
+ await context.send(`✅ Summary sent successfully to ${email}`);
67
+ } else {
68
+ await context.send("❌ Message not found.");
53
69
  }
54
- console.log(content);
55
- // const response = await resend.emails.send(content);
56
- // console.log(response);
57
-
58
- await context.send(`✅ Summary sent successfully to ${email}`);
59
70
  } catch (error) {
60
71
  await context.send("❌ Failed to send email. Please try again later.");
61
- console.error('Error sending email:', error);
72
+ console.error("Error sending email:", error);
62
73
  }
63
- }
74
+ }
@@ -36,7 +36,7 @@ export const agent: Agent = {
36
36
  ...paySkill,
37
37
  ...tokenSkill,
38
38
  ...gameSkill,
39
- ...todoSkill,
39
+ ...(process.env.RESEND_API_KEY ? todoSkill : []),
40
40
  ],
41
41
  };
42
42
  // [!endregion skills]
@@ -56,7 +56,7 @@ run(
56
56
  // [!region run2]
57
57
  await agentReply(context, prompt);
58
58
  },
59
- { agent},
59
+ { agent },
60
60
  );
61
61
 
62
62
  // [!endregion run2]
@@ -7,14 +7,18 @@ Your are helpful and playful web3 agent called {agent_name} that lives inside a
7
7
 
8
8
  {skills}
9
9
 
10
- ## Common Issues
10
+ ## Scenarios
11
11
  1. Missing commands in responses
12
12
  **Issue**: Sometimes responses are sent without the required command.
13
13
  **Example**:
14
14
  Incorrect:
15
15
  > "Looks like vitalik.eth is registered! What about these cool alternatives?"
16
-
17
16
  Correct:
18
17
  > "Looks like vitalik.eth is registered! What about these cool alternatives?
19
18
  > /cool vitalik.eth"
19
+
20
+ Incorrect:
21
+ > Here is a summary of your TODOs. I will now send it via email.
22
+ Correct:
23
+ > /todo
20
24
  `;