create-message-kit 1.2.2 → 1.2.3
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/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,47 +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
|
-
|
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
|
+
);
|
29
37
|
email = emailResponse;
|
30
|
-
|
38
|
+
|
31
39
|
// Basic email validation
|
32
40
|
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
33
41
|
if (!emailRegex.test(email)) {
|
34
|
-
await context.send(
|
42
|
+
await context.send(
|
43
|
+
"Invalid email format. Please try again with a valid email address.",
|
44
|
+
);
|
35
45
|
intents--;
|
36
46
|
continue;
|
37
47
|
}
|
38
48
|
break;
|
39
49
|
}
|
40
|
-
if(intents==0){
|
41
|
-
|
42
|
-
|
43
|
-
|
50
|
+
if (intents == 0) {
|
51
|
+
await context.send(
|
52
|
+
"I couldn't get your email address. Please try again later.",
|
53
|
+
);
|
54
|
+
return;
|
55
|
+
}
|
44
56
|
try {
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
<
|
52
|
-
|
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.");
|
53
71
|
}
|
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
72
|
} catch (error) {
|
60
73
|
await context.send("❌ Failed to send email. Please try again later.");
|
61
|
-
console.error(
|
74
|
+
console.error("Error sending email:", error);
|
62
75
|
}
|
63
|
-
}
|
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
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
|
`;
|