accounting_automation: опция gmailIncludeSpam (письма подрядчиков в спаме)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -68,6 +68,8 @@ export class GmailClient implements MailSource {
|
||||
processedIds: (ids: string[]) => Promise<Set<string>>;
|
||||
fetchFn?: FetchFn;
|
||||
query?: string;
|
||||
/** Искать и в папке «Спам» (письма подрядчиков иногда попадают туда). */
|
||||
includeSpam?: boolean;
|
||||
},
|
||||
) {}
|
||||
|
||||
@@ -85,6 +87,7 @@ export class GmailClient implements MailSource {
|
||||
let pageToken: string | undefined;
|
||||
do {
|
||||
const params: Record<string, string> = { q: this.o.query ?? "has:attachment filename:pdf", maxResults: "50" };
|
||||
if (this.o.includeSpam) params.includeSpamTrash = "true";
|
||||
if (pageToken) params.pageToken = pageToken;
|
||||
const list = await this.get<{ messages?: { id: string }[]; nextPageToken?: string }>("/messages", params);
|
||||
const ids = (list.messages ?? []).map((x) => x.id);
|
||||
|
||||
@@ -65,6 +65,7 @@ const app = buildApi({
|
||||
auth,
|
||||
user: s.google.gmailUser,
|
||||
query: s.google.gmailQuery,
|
||||
includeSpam: s.google.gmailIncludeSpam,
|
||||
processedIds: async (ids) => {
|
||||
const { rows } = await pool.query("select message_id from acc_mail_processed where message_id = any($1) and result <> 'error'", [ids]);
|
||||
return new Set(rows.map((r) => r.message_id as string));
|
||||
|
||||
@@ -30,6 +30,8 @@ export const accountingSchema = z.object({
|
||||
/** Ящик пользователя, который читаем (делегирование домена; группа invoice@ доставляет письма в ящик участника agents@). */
|
||||
gmailUser: z.string().default("agents@khbuild.pro"),
|
||||
/** Поиск писем в ящике: только письма, пришедшие на группу invoice@ (или алиас invoices@), с PDF. */
|
||||
/** Искать письма и в «Спаме» (Gmail при этом захватывает и корзину). */
|
||||
gmailIncludeSpam: z.boolean().default(false),
|
||||
gmailQuery: z.string().default("has:attachment filename:pdf (to:invoice@khbuild.pro OR cc:invoice@khbuild.pro OR to:invoices@khbuild.pro OR cc:invoices@khbuild.pro)"),
|
||||
/** Корневая папка Google Drive для инвойсов, чеков и т.д. (подпапки создаются сервисом). */
|
||||
rootFolderId: z.string().optional(),
|
||||
|
||||
Reference in New Issue
Block a user