Today's-Todoist-Tasks-Plugin

name

Today's Todoist Tasks

icon

task_alt

description

Enables the action to add today's Todoist tasks to the daily jot

instructions

This plugin enables an action in the jots-view so that on today's jot you can import all tasks from Todoist that are due today. For the plugin to function you need to add your personal Todoist API token in the plugin's settings. For that, open Todoist, then navigate to Settings -> Integrations -> Developer -> API token and copy the token. In Amplenote, you can find the plugin's Settings in Account Settings -> Plugins, then press the cog and add your token in the appropriate field.

In the plugin's settings you can also give a comma separated list of default projects (make sure that the names are correct, case matters!). If set, only the tasks belonging to these projects are added to the jot in Amplenote

❗Currently the plugin only adds the name of the task. If there is a need for additional Information for each task, e.g. due date, or if you need a more powerful integration that also enables ticking off tasks in Todoist, feel free to reach out! Comments and suggestions are welcome :)

setting

Todoist API Token

setting

Default Projects

https://amplenoteplugins.featureupvote.com/suggestions/503464/add-todoist-tasks-due-today-to-todays-jot-or-note

/*
- get all tasks that are due today from todoist
- add these tasks to the daily jot
- specify the project
- structure with functions
- null handling? e.g. if there are no tasks/projects?
- multiple executions? should tasks only be added once?
- additional task information?
*/
{
dailyJotOption: {
check(app, noteHandle) {
return "Add today's Todoist-tasks to jot"
},
async run(app, noteHandle) {
if (!app.settings["Todoist API Token"]){
app.alert("Unset Todoist API token! Go to the plugin settings and supply your Todoist API token (found in Settings -> Integrations -> Developer in your Todoist account).")
} else {
let projects = null
if (app.settings["Default Projects"]) {
projects = app.settings["Default Projects"].split(",").map(s => s.trim())
console.log("PROJECTS")
console.log(projects)
}
let response = await fetch('https://api.todoist.com/rest/v2/tasks', { headers: { 'Authorization': 'Bearer ' + app.settings["Todoist API Token"]}})
if (!response.ok) {
app.alert("There was an error getting your tasks. Check your API token / internet connection and try again. If nothing helps, contact the plugin developer for support.")
} else {
let tasks = await response.json()
console.log(tasks)
if (projects) {
let projectResponse = await fetch('https://api.todoist.com/rest/v2/projects', { headers: { 'Authorization': 'Bearer ' + app.settings["Todoist API Token"]}})
if (!projectResponse.ok) {
app.alert("There was an error reaching Todoist. Check your internet connection and try again, if the issue persists contact the plugin developer.")
} else {
let validProjects = await projectResponse.json()
console.log("VALID PROJECTS")
console.log(validProjects)
let filteredProjects = validProjects.filter((proj) => projects.includes(proj["name"]))
console.log("FILTERED PROJECTS")
console.log(filteredProjects)
let filteredIDs = filteredProjects.map(s => s["id"])
console.log("FILTERED IDS")
console.log(filteredIDs)
tasks = tasks.filter(t => filteredIDs.includes(t["project_id"]))
console.log("FILTERED TASKS")
console.log(tasks)
}
}
let formatDate = (date) => {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const localDate = `${year}-${month}-${day}`;
return localDate;
}
let today = new Date();
tasks = tasks.filter(t => t["due"]["date"] === formatDate(today))
console.log("DUE TODAY")
console.log(tasks)
for (let t in tasks) {
console.log("CONTENT")
console.log(tasks[t]["content"])
await app.insertTask(noteHandle, { content: tasks[t]["content"]})
}
}
}
}
},
_requestTasks() {
return "Hello :)"
}
}