feat: trigger another worker (#547)

This commit is contained in:
刘志聪
2025-01-08 20:02:48 +08:00
committed by GitHub
parent 92620cdedb
commit 5bfa588f70
14 changed files with 302 additions and 9 deletions

View File

@@ -2,10 +2,10 @@ import { Context } from "hono";
import { getEnvStringList } from "../utils";
import { sendMailToTelegram } from "../telegram_api";
import { Bindings, HonoCustomType } from "../types";
import { Bindings, HonoCustomType, RPCEmailMessage } from "../types";
import { auto_reply } from "./auto_reply";
import { isBlocked } from "./black_list";
import { triggerWebhook } from "../common";
import { triggerWebhook, triggerAnotherWorker, commonParseMail} from "../common";
import { check_if_junk_mail } from "./check_junk";
@@ -61,8 +61,9 @@ async function email(message: ForwardableEmailMessage, env: Bindings, ctx: Execu
}
// send webhook
let parsedText;
try {
await triggerWebhook(
parsedText = await triggerWebhook(
{ env: env } as Context<HonoCustomType>,
message.to, rawEmail, message_id
);
@@ -70,6 +71,26 @@ async function email(message: ForwardableEmailMessage, env: Bindings, ctx: Execu
console.log("send webhook error", error);
}
// trigger another worker
try {
const headersMap = new Map<string, string>();
if(message.headers) {
message.headers.forEach((value, key) => {headersMap.set(key, value);});
}
if (!parsedText){
parsedText = (await commonParseMail(rawEmail))?.text ?? ""
}
const rpcEmail: RPCEmailMessage = {
from: message.from,
to: message.to,
rawEmail: rawEmail,
headers: headersMap
}
await triggerAnotherWorker({ env: env } as Context<HonoCustomType>, rpcEmail, parsedText);
} catch (error) {
console.error("trigger another worker error", error);
}
// auto reply email
await auto_reply(message, env);
}