Created
November 9, 2024 23:31
-
-
Save dettmering/6ef2aa4f1f10b9c3a36047fa8692624a to your computer and use it in GitHub Desktop.
Cloudflare E-Mail Worker pushing to Todoist
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export default { | |
| async email(message, env, ctx) { | |
| switch (message.to) { | |
| case "recipient@domain.com": | |
| const taskContent = message.headers.get('subject'); // Use email subject as the task content | |
| const requestBody = JSON.stringify({ | |
| content: taskContent, | |
| due_string: "today", | |
| due_lang: "en", | |
| project_id: 123456, // Inbox project ID | |
| labels: ["E-Mail"] | |
| }); | |
| const requestOptions = { | |
| method: "POST", | |
| headers: { | |
| "Authorization": "Bearer abcd123", | |
| "Content-Type": "application/json" | |
| }, | |
| body: requestBody | |
| }; | |
| // Send the request to Todoist API to create a new task | |
| ctx.waitUntil(fetch("https://api.todoist.com/rest/v2/tasks", requestOptions)); | |
| break; | |
| default: | |
| message.setReject("Unknown address"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment