feat: add mail id and url in webhook (#443)

This commit is contained in:
Dream Hunter
2024-09-09 22:29:18 +08:00
committed by GitHub
parent 5ece49a576
commit 393c5902c3
11 changed files with 87 additions and 12 deletions

View File

@@ -22,12 +22,14 @@ async function saveWebhookSettings(c: Context<HonoCustomType>): Promise<Response
async function testWebhookSettings(c: Context<HonoCustomType>): Promise<Response> {
const settings = await c.req.json<WebhookSettings>();
// random raw email
const raw = await c.env.DB.prepare(
`SELECT raw FROM raw_mails ORDER BY RANDOM() LIMIT 1`
).first<string>("raw");
const { id: mailId, raw } = await c.env.DB.prepare(
`SELECT id, raw FROM raw_mails ORDER BY RANDOM() LIMIT 1`
).first<{ id: string, raw: string }>() || {};
const parsedEmail = await commonParseMail(raw);
const res = await sendWebhook(settings, {
id: mailId || "0",
url: c.env.FRONTEND_URL ? `${c.env.FRONTEND_URL}?mail_id=${mailId}` : "",
from: parsedEmail?.sender || "test@test.com",
to: "admin@test.com",
subject: parsedEmail?.subject || "test subject",