feat: add AI extract webhook placeholders

This commit is contained in:
Dream Hunter
2026-05-29 02:27:46 +08:00
committed by GitHub
parent cfb31807f1
commit bf786947e3
10 changed files with 56 additions and 6 deletions

View File

@@ -37,7 +37,11 @@ async function testWebhookSettings(c: Context<HonoCustomType>): Promise<Response
subject: parsedEmail?.subject || "test subject",
raw: raw || "test raw email",
parsedText: parsedEmail?.text || "test parsed text",
parsedHtml: parsedEmail?.html || "test parsed html"
parsedHtml: parsedEmail?.html || "test parsed html",
aiExtract: null,
aiExtractType: "",
aiExtractResult: "",
aiExtractResultText: ""
});
if (!res.success) {
return c.text(res.message || "send webhook error", 400);

View File

@@ -5,7 +5,7 @@ import { WorkerMailerOptions } from 'worker-mailer';
import { getBooleanValue, getDomains, getStringArray, getStringValue, getIntValue, getUserRoles, getDefaultDomains, getJsonSetting, getAnotherWorkerList, hashPassword, getJsonObjectValue, getRandomSubdomainDomains, getDomainMapValue, normalizeDomains, trimLower } from './utils';
import { unbindTelegramByAddress } from './telegram_api/common';
import { CONSTANTS } from './constants';
import { AddressCreationSettings, AdminWebhookSettings, WebhookMail, WebhookSettings } from './models';
import { AddressCreationSettings, AdminWebhookSettings, ExtractResult, WebhookMail, WebhookSettings } from './models';
import i18n from './i18n';
const DEFAULT_NAME_REGEX = /[^a-z0-9]/g;
@@ -810,7 +810,8 @@ export async function triggerWebhook(
c: Context<HonoCustomType>,
address: string,
parsedEmailContext: ParsedEmailContext,
message_id: string | null
message_id: string | null,
aiExtract?: ExtractResult | null
): Promise<void> {
if (!c.env.KV || !getBooleanValue(c.env.ENABLE_WEBHOOK)) {
return
@@ -843,6 +844,9 @@ export async function triggerWebhook(
).bind(address, message_id).first<string>("id");
const parsedEmail = await commonParseMail(parsedEmailContext);
const usableAiExtract = aiExtract?.type !== "none" && aiExtract?.result
? aiExtract
: null;
const webhookMail = {
id: mailId || "",
url: c.env.FRONTEND_URL ? `${c.env.FRONTEND_URL}?mail_id=${mailId}` : "",
@@ -852,6 +856,10 @@ export async function triggerWebhook(
raw: parsedEmailContext.rawEmail || "",
parsedText: parsedEmail?.text || "",
parsedHtml: parsedEmail?.html || "",
aiExtract: usableAiExtract,
aiExtractType: usableAiExtract?.type || "",
aiExtractResult: usableAiExtract?.result || "",
aiExtractResultText: usableAiExtract?.result_text || "",
}
for (const settings of webhookList) {
const res = await sendWebhook(settings, webhookMail);

View File

@@ -138,7 +138,7 @@ async function email(message: ForwardableEmailMessage, env: Bindings, ctx: Execu
try {
await triggerWebhook(
{ env: env } as Context<HonoCustomType>,
toAddress, parsedEmailContext, message_id
toAddress, parsedEmailContext, message_id, aiExtractResult
);
} catch (error) {
console.error("send webhook error", error);

View File

@@ -53,7 +53,11 @@ async function testWebhookSettings(c: Context<HonoCustomType>): Promise<Response
subject: parsedEmail?.subject || "test subject",
raw: raw || "test raw email",
parsedText: parsedEmail?.text || "test parsed text",
parsedHtml: parsedEmail?.html || "test parsed html"
parsedHtml: parsedEmail?.html || "test parsed html",
aiExtract: null,
aiExtractType: "",
aiExtractResult: "",
aiExtractResultText: ""
});
if (!res.success) {
return c.text(res.message || "send webhook error", 400);

View File

@@ -32,6 +32,10 @@ export type WebhookMail = {
raw: string;
parsedText: string;
parsedHtml: string;
aiExtract: ExtractResult | null;
aiExtractType: string;
aiExtractResult: string;
aiExtractResultText: string;
}
export type CustomSqlCleanup = {
@@ -156,6 +160,9 @@ export class WebhookSettings {
"raw": "${raw}",
"parsedText": "${parsedText}",
"parsedHtml": "${parsedHtml}",
"aiExtractType": "${aiExtractType}",
"aiExtractResult": "${aiExtractResult}",
"aiExtractResultText": "${aiExtractResultText}",
}, null, 2)
}