mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-06-30 11:52:07 +08:00
feat: add AI extract webhook placeholders
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user