create-message-kit 1.2.0 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
package/package.json
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
import { Resend } from
|
1
|
+
import { Resend } from "resend";
|
2
2
|
import { XMTPContext } from "@xmtp/message-kit";
|
3
3
|
import type { Skill } from "@xmtp/message-kit";
|
4
|
-
|
4
|
+
if (!process.env.RESEND_API_KEY) {
|
5
|
+
console.warn("RESEND_API_KEY is not set");
|
6
|
+
}
|
5
7
|
const resend = new Resend(process.env.RESEND_API_KEY); // Replace with your Resend API key
|
6
8
|
|
7
9
|
export const registerSkill: Skill[] = [
|
@@ -9,7 +11,8 @@ export const registerSkill: Skill[] = [
|
|
9
11
|
skill: "/todo",
|
10
12
|
handler: handler,
|
11
13
|
examples: ["/todo"],
|
12
|
-
description:
|
14
|
+
description:
|
15
|
+
"Summarize your TODOs and send an email with the summary. Receives no parameters.",
|
13
16
|
params: {},
|
14
17
|
},
|
15
18
|
];
|
@@ -17,42 +20,57 @@ export const registerSkill: Skill[] = [
|
|
17
20
|
export async function handler(context: XMTPContext) {
|
18
21
|
const {
|
19
22
|
message: {
|
20
|
-
content: {
|
23
|
+
content: { previousMsg },
|
21
24
|
},
|
22
25
|
} = context;
|
23
26
|
|
24
27
|
let email = "";
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
+
if (!previousMsg) {
|
29
|
+
await context.send("You need to do it on a reply.");
|
30
|
+
return;
|
31
|
+
}
|
32
|
+
let intents = 2;
|
33
|
+
while (intents > 0) {
|
34
|
+
const emailResponse = await context.awaitResponse(
|
35
|
+
"Please provide your email address to receive the TODO summary:",
|
36
|
+
);
|
28
37
|
email = emailResponse;
|
29
|
-
|
38
|
+
|
30
39
|
// Basic email validation
|
31
40
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
32
41
|
if (!emailRegex.test(email)) {
|
33
|
-
await context.send(
|
42
|
+
await context.send(
|
43
|
+
"Invalid email format. Please try again with a valid email address.",
|
44
|
+
);
|
45
|
+
intents--;
|
34
46
|
continue;
|
35
47
|
}
|
36
48
|
break;
|
37
49
|
}
|
38
|
-
|
50
|
+
if (intents == 0) {
|
51
|
+
await context.send(
|
52
|
+
"I couldn't get your email address. Please try again later.",
|
53
|
+
);
|
54
|
+
return;
|
55
|
+
}
|
39
56
|
try {
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
<
|
47
|
-
|
57
|
+
if (typeof previousMsg === "string") {
|
58
|
+
let content = {
|
59
|
+
from: "bot@mail.coin-toss.xyz",
|
60
|
+
to: email,
|
61
|
+
subject: "Your summary from Converse",
|
62
|
+
html: `
|
63
|
+
<h3>Your TODO Summary</h3>
|
64
|
+
<p>${previousMsg.replace(/\n/g, "<br>")}</p>
|
65
|
+
`,
|
66
|
+
};
|
67
|
+
await resend.emails.send(content);
|
68
|
+
await context.send(`✅ Summary sent successfully to ${email}`);
|
69
|
+
} else {
|
70
|
+
await context.send("❌ Message not found.");
|
48
71
|
}
|
49
|
-
console.log(content);
|
50
|
-
const response = await resend.emails.send(content);
|
51
|
-
console.log(response);
|
52
|
-
|
53
|
-
await context.send(`✅ Summary sent successfully to ${email}`);
|
54
72
|
} catch (error) {
|
55
73
|
await context.send("❌ Failed to send email. Please try again later.");
|
56
|
-
console.error(
|
74
|
+
console.error("Error sending email:", error);
|
57
75
|
}
|
58
|
-
}
|
76
|
+
}
|
@@ -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
|
-
##
|
10
|
+
## Scenarios
|
11
11
|
1. Missing commands in responses
|
12
|
-
**Issue**: Sometimes responses
|
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
|
`;
|