Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions apps/web/components/PlanBadge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ export function ActionBadgeExpanded({ action }: { action: ExecutedAction }) {
return <ActionBadge type={ActionType.MARK_SPAM} />;
case ActionType.CALL_WEBHOOK:
return <ActionBadge type={ActionType.CALL_WEBHOOK} />;
case ActionType.MARK_READ:
return <ActionBadge type={ActionType.MARK_READ} />;
default:
return <ActionBadge type={action.type} />;
}
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- AlterEnum
ALTER TYPE "ActionType" ADD VALUE 'MARK_READ';
Comment thread
elie222 marked this conversation as resolved.
3 changes: 2 additions & 1 deletion apps/web/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ model User {
rulesPrompt String?
webhookSecret String?

// categorization
// categorization
autoCategorizeSenders Boolean @default(false)

// premium can be shared among multiple users
Expand Down Expand Up @@ -375,6 +375,7 @@ enum ActionType {
DRAFT_EMAIL
MARK_SPAM
CALL_WEBHOOK
MARK_READ
// SUMMARIZE
// SNOOZE
// ADD_TO_DO
Expand Down
1 change: 1 addition & 0 deletions apps/web/utils/actionType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export const actionInputs: Record<
},
],
},
[ActionType.MARK_READ]: { fields: [] },
};

export function getActionFields(fields: Action | ExecutedAction | undefined) {
Expand Down
1 change: 1 addition & 0 deletions apps/web/utils/actions/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export const zodActionType = z.enum([
ActionType.REPLY,
ActionType.SEND_EMAIL,
ActionType.CALL_WEBHOOK,
ActionType.MARK_READ,
]);

const zodField = z
Expand Down
22 changes: 22 additions & 0 deletions apps/web/utils/ai/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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, ActionFunctionDef> = {
[ActionType.ARCHIVE]: ARCHIVE,
[ActionType.LABEL]: LABEL,
Expand All @@ -257,6 +269,7 @@ export const actionFunctionDefs: Record<ActionType, ActionFunctionDef> = {
[ActionType.FORWARD]: FORWARD_EMAIL,
[ActionType.MARK_SPAM]: MARK_SPAM,
[ActionType.CALL_WEBHOOK]: CALL_WEBHOOK,
[ActionType.MARK_READ]: MARK_READ,
};

const archive: ActionFunction<Record<string, unknown>> = async (
Expand Down Expand Up @@ -420,6 +433,13 @@ const call_webhook: ActionFunction<any> = async (
});
};

const mark_read: ActionFunction<any> = 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,
Expand Down Expand Up @@ -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}`);
}
Expand Down