Compare commits

..

2 Commits

Author SHA1 Message Date
Rıdvan Akca
d9c311d045 feat(gmail): add star email action 2024-04-24 15:40:03 +02:00
Rıdvan Akca
7985a79adc feat(gmail): add send to trash action 2024-04-24 13:24:13 +02:00
6 changed files with 121 additions and 2 deletions

View File

@@ -1,5 +1,7 @@
import createDraft from './create-draft/index.js'; import createDraft from './create-draft/index.js';
import replyToEmail from './reply-to-email/index.js'; import replyToEmail from './reply-to-email/index.js';
import sendEmail from './send-email/index.js'; import sendEmail from './send-email/index.js';
import sendToTrash from './send-to-trash/index.js';
import starEmail from './star-email/index.js';
export default [createDraft, replyToEmail, sendEmail]; export default [createDraft, replyToEmail, sendEmail, sendToTrash, starEmail];

View File

@@ -0,0 +1,30 @@
import defineAction from '../../../../helpers/define-action.js';
export default defineAction({
name: 'Send to trash',
key: 'sendToTrash',
description: 'Send an existing email message to the trash.',
arguments: [
{
label: 'Message ID',
key: 'messageId',
type: 'string',
required: true,
description: '',
variables: true,
},
],
async run($) {
const { messageId } = $.step.parameters;
const userId = $.auth.data.userId;
const { data } = await $.http.post(
`/gmail/v1/users/${userId}/messages/${messageId}/trash`
);
$.setActionItem({
raw: data,
});
},
});

View File

@@ -0,0 +1,45 @@
import defineAction from '../../../../helpers/define-action.js';
export default defineAction({
name: 'Star an email',
key: 'starEmail',
description: 'Star an email message.',
arguments: [
{
label: 'Message ID',
key: 'messageId',
type: 'dropdown',
required: true,
description: '',
variables: true,
source: {
type: 'query',
name: 'getDynamicData',
arguments: [
{
name: 'key',
value: 'listMessages',
},
],
},
},
],
async run($) {
const { messageId } = $.step.parameters;
const userId = $.auth.data.userId;
const body = {
addLabelIds: ['STARRED'],
};
const { data } = await $.http.post(
`/gmail/v1/users/${userId}/messages/${messageId}/modify`,
body
);
$.setActionItem({
raw: data,
});
},
});

View File

@@ -1,6 +1,13 @@
import listEmails from './list-emails/index.js'; import listEmails from './list-emails/index.js';
import listLabels from './list-labels/index.js'; import listLabels from './list-labels/index.js';
import listMessages from './list-messages/index.js';
import listSignatures from './list-signatures/index.js'; import listSignatures from './list-signatures/index.js';
import listThreads from './list-threads/index.js'; import listThreads from './list-threads/index.js';
export default [listEmails, listLabels, listSignatures, listThreads]; export default [
listEmails,
listLabels,
listMessages,
listSignatures,
listThreads,
];

View File

@@ -0,0 +1,31 @@
export default {
name: 'List messages',
key: 'listMessages',
async run($) {
const messages = {
data: [],
};
const userId = $.auth.data.userId;
const { data } = await $.http.get(`/gmail/v1/users/${userId}/messages`);
if (data.messages) {
for (const message of data.messages) {
const { data: messageData } = await $.http.get(
`/gmail/v1/users/${userId}/messages/${message.id}`
);
const subject = messageData.payload.headers.find(
(header) => header.name === 'Subject'
);
messages.data.push({
value: message.id,
name: subject?.value,
});
}
}
return messages;
},
};

View File

@@ -7,6 +7,10 @@ items:
desc: Respond to an email. desc: Respond to an email.
- name: Send email - name: Send email
desc: Send a new email message. desc: Send a new email message.
- name: Send to trash
desc: Send an existing email message to the trash.
- name: Star an email
desc: Star an email message.
--- ---
<script setup> <script setup>