1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { fetch } from "https://esm.town/v/std/fetch";
import { email } from "https://esm.town/v/std/email?v=9";
export async function getTangleComments({ lastRunAt }) {
let response = await fetch(
"https://www.readtangle.com/members/api/comments/?limit=5&order=created_at%20DESC%2C%20id%20DESC&filter=post_id%3A6525827c68f969000134e052%2Bcreated_at%3A%3C%3D2023-10-13T20%3A55%3A23.163Z&page=2",
);
let commentsData = await response.json();
console.log("Fetched Data:", commentsData);
console.log(commentsData);
const newComments = commentsData.comments.filter((comment) =>
new Date(comment.created_at) >= new Date(lastRunAt)
);
const emailBody = newComments.map((comment) =>
`${comment.member.name}: ${comment.html}`
).join("\n\n");
if (newComments.length > 0) {
await email({
html: emailBody,
subject: "Re: New Tangle Comments",
});
}
}