From 72aca307592f7f13ac7fe8efdf82ba77a541b2b1 Mon Sep 17 00:00:00 2001 From: arndom Date: Thu, 16 Jan 2025 11:33:37 +0100 Subject: [PATCH 1/4] add mark_read action type to schema --- .../migrations/20250116101856_mark_read_action/migration.sql | 2 ++ apps/web/prisma/schema.prisma | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 apps/web/prisma/migrations/20250116101856_mark_read_action/migration.sql diff --git a/apps/web/prisma/migrations/20250116101856_mark_read_action/migration.sql b/apps/web/prisma/migrations/20250116101856_mark_read_action/migration.sql new file mode 100644 index 0000000000..e533172034 --- /dev/null +++ b/apps/web/prisma/migrations/20250116101856_mark_read_action/migration.sql @@ -0,0 +1,2 @@ +-- AlterEnum +ALTER TYPE "ActionType" ADD VALUE 'MARK_READ'; diff --git a/apps/web/prisma/schema.prisma b/apps/web/prisma/schema.prisma index a8d55a9e4f..5b4ec9d95f 100644 --- a/apps/web/prisma/schema.prisma +++ b/apps/web/prisma/schema.prisma @@ -75,7 +75,7 @@ model User { rulesPrompt String? webhookSecret String? - // categorization + // categorization autoCategorizeSenders Boolean @default(false) // premium can be shared among multiple users @@ -375,6 +375,7 @@ enum ActionType { DRAFT_EMAIL MARK_SPAM CALL_WEBHOOK + MARK_READ // SUMMARIZE // SNOOZE // ADD_TO_DO From ec5d987737e23c00d1ef5839a6143ca99d823d0f Mon Sep 17 00:00:00 2001 From: arndom Date: Thu, 16 Jan 2025 12:05:16 +0100 Subject: [PATCH 2/4] add mark_read action --- apps/web/components/PlanBadge.tsx | 5 +++++ apps/web/utils/actionType.ts | 1 + apps/web/utils/actions/validation.ts | 1 + apps/web/utils/ai/actions.ts | 22 ++++++++++++++++++++++ 4 files changed, 29 insertions(+) diff --git a/apps/web/components/PlanBadge.tsx b/apps/web/components/PlanBadge.tsx index 2f81ba876e..e226200443 100644 --- a/apps/web/components/PlanBadge.tsx +++ b/apps/web/components/PlanBadge.tsx @@ -120,6 +120,8 @@ export function ActionBadgeExpanded({ action }: { action: ExecutedAction }) { return ; case ActionType.CALL_WEBHOOK: return ; + case ActionType.MARK_READ: + return ; default: return ; } @@ -151,6 +153,8 @@ function getActionLabel(type: ActionType) { return "Webhook"; case ActionType.MARK_SPAM: return "Mark as spam"; + case ActionType.MARK_READ: + return "Mark as read"; default: return capitalCase(type); } @@ -182,6 +186,7 @@ export function getActionColor(actionType: ActionType): Color { case ActionType.DRAFT_EMAIL: return "green"; case ActionType.ARCHIVE: + case ActionType.MARK_READ: return "yellow"; case ActionType.LABEL: return "blue"; diff --git a/apps/web/utils/actionType.ts b/apps/web/utils/actionType.ts index 1f67035c50..63b11a37a3 100644 --- a/apps/web/utils/actionType.ts +++ b/apps/web/utils/actionType.ts @@ -116,6 +116,7 @@ export const actionInputs: Record< }, ], }, + [ActionType.MARK_READ]: { fields: [] }, }; export function getActionFields(fields: Action | ExecutedAction | undefined) { diff --git a/apps/web/utils/actions/validation.ts b/apps/web/utils/actions/validation.ts index 6334a3b707..6ede9d3fe5 100644 --- a/apps/web/utils/actions/validation.ts +++ b/apps/web/utils/actions/validation.ts @@ -36,6 +36,7 @@ export const zodActionType = z.enum([ ActionType.REPLY, ActionType.SEND_EMAIL, ActionType.CALL_WEBHOOK, + ActionType.MARK_READ, ]); const zodField = z diff --git a/apps/web/utils/ai/actions.ts b/apps/web/utils/ai/actions.ts index 0e8029a92c..61e1be69d9 100644 --- a/apps/web/utils/ai/actions.ts +++ b/apps/web/utils/ai/actions.ts @@ -10,6 +10,7 @@ import { archiveThread, getOrCreateLabel, labelThread, + markReadThread, } from "@/utils/gmail/label"; import { markSpam } from "@/utils/gmail/spam"; import type { Attachment } from "@/utils/types/mail"; @@ -248,6 +249,17 @@ const CALL_WEBHOOK: ActionFunctionDef = { action: ActionType.CALL_WEBHOOK, }; +const MARK_READ: ActionFunctionDef = { + name: "mark_read", + description: "Mark as read.", + parameters: { + type: "object", + properties: {}, + required: [], + }, + action: ActionType.MARK_READ, +}; + export const actionFunctionDefs: Record = { [ActionType.ARCHIVE]: ARCHIVE, [ActionType.LABEL]: LABEL, @@ -257,6 +269,7 @@ export const actionFunctionDefs: Record = { [ActionType.FORWARD]: FORWARD_EMAIL, [ActionType.MARK_SPAM]: MARK_SPAM, [ActionType.CALL_WEBHOOK]: CALL_WEBHOOK, + [ActionType.MARK_READ]: MARK_READ, }; const archive: ActionFunction> = async ( @@ -420,6 +433,13 @@ const call_webhook: ActionFunction = async ( }); }; +const mark_read: ActionFunction = async ( + gmail: gmail_v1.Gmail, + email: EmailForAction, +) => { + return await markReadThread({ gmail, threadId: email.threadId, read: true }); +}; + export const runActionFunction = async ( gmail: gmail_v1.Gmail, email: EmailForAction, @@ -452,6 +472,8 @@ export const runActionFunction = async ( return mark_spam(gmail, email, args, userEmail, executedRule); case ActionType.CALL_WEBHOOK: return call_webhook(gmail, email, args, userEmail, executedRule); + case ActionType.MARK_READ: + return mark_read(gmail, email, args, userEmail, executedRule); default: throw new Error(`Unknown action: ${action}`); } From e0f1c164c6a35a77dd135d55b5ee736ae75873df Mon Sep 17 00:00:00 2001 From: Eliezer Steinbock <3090527+elie222@users.noreply.github.com> Date: Thu, 30 Jan 2025 23:15:13 +0200 Subject: [PATCH 3/4] Use mark as read in switches --- apps/web/utils/action-item.ts | 1 + apps/web/utils/ai/rule/create-prompt-from-rule.ts | 3 +++ 2 files changed, 4 insertions(+) diff --git a/apps/web/utils/action-item.ts b/apps/web/utils/action-item.ts index 6c3ff3da22..27b0605adb 100644 --- a/apps/web/utils/action-item.ts +++ b/apps/web/utils/action-item.ts @@ -169,6 +169,7 @@ export function sanitizeActionFields( switch (action.type) { case ActionType.ARCHIVE: case ActionType.MARK_SPAM: + case ActionType.MARK_READ: return base; case ActionType.LABEL: { return { diff --git a/apps/web/utils/ai/rule/create-prompt-from-rule.ts b/apps/web/utils/ai/rule/create-prompt-from-rule.ts index 39e0c17493..7df8c60969 100644 --- a/apps/web/utils/ai/rule/create-prompt-from-rule.ts +++ b/apps/web/utils/ai/rule/create-prompt-from-rule.ts @@ -81,6 +81,9 @@ export function createPromptFromRule(rule: RuleWithRelations): string { case ActionType.CALL_WEBHOOK: if (action.url) actions.push(`call webhook at ${action.url}`); break; + case ActionType.MARK_READ: + actions.push("mark as read"); + break; default: console.warn(`Unknown action type: ${action.type}`); // biome-ignore lint/correctness/noSwitchDeclarations: intentional exhaustive check From b632a5a86451c9dffecb00e44c297629bfb11d3d Mon Sep 17 00:00:00 2001 From: Eliezer Steinbock <3090527+elie222@users.noreply.github.com> Date: Thu, 30 Jan 2025 23:29:24 +0200 Subject: [PATCH 4/4] Adjust form optiosn --- apps/web/app/(app)/automation/RuleForm.tsx | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/apps/web/app/(app)/automation/RuleForm.tsx b/apps/web/app/(app)/automation/RuleForm.tsx index b149aac83e..da2100aa57 100644 --- a/apps/web/app/(app)/automation/RuleForm.tsx +++ b/apps/web/app/(app)/automation/RuleForm.tsx @@ -177,6 +177,20 @@ export function RuleForm({ rule }: { rule: CreateRuleBody & { id?: string } }) { const conditionalOperator = watch("conditionalOperator"); + const typeOptions = useMemo(() => { + return [ + { label: "Archive", value: ActionType.ARCHIVE }, + { label: "Label", value: ActionType.LABEL }, + { label: "Draft email", value: ActionType.DRAFT_EMAIL }, + { label: "Reply", value: ActionType.REPLY }, + { label: "Send email", value: ActionType.SEND_EMAIL }, + { label: "Forward", value: ActionType.FORWARD }, + { label: "Mark read", value: ActionType.MARK_READ }, + { label: "Mark spam", value: ActionType.MARK_SPAM }, + { label: "Call webhook", value: ActionType.CALL_WEBHOOK }, + ]; + }, []); + return (
{isSubmitted && Object.keys(errors).length > 0 && ( @@ -520,10 +534,7 @@ export function RuleForm({ rule }: { rule: CreateRuleBody & { id?: string } }) {