Skip to content

Instantly share code, notes, and snippets.

@dettmering
Created November 9, 2024 23:31
Show Gist options
  • Select an option

  • Save dettmering/6ef2aa4f1f10b9c3a36047fa8692624a to your computer and use it in GitHub Desktop.

Select an option

Save dettmering/6ef2aa4f1f10b9c3a36047fa8692624a to your computer and use it in GitHub Desktop.
Cloudflare E-Mail Worker pushing to Todoist
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