There is a more updated version of the code in this article written to keep up with the changes in the Todoist API in 2023, you can find it here.
I had previously made a YouTube video of how I use Drafts 5 to process my meeting notes. Most people who talk to me about that post are particularly interested in how I process the note to automatically add items to my Todo list app and to my calendar. Therefore, I’m using this post to explain this.
As I mention in the video, I’ve created two custom tags TTodoist: and Cal:to identify lines in my notes as Todo items and calendar events respectively. These tags go before the item or event, for example
TTodoist: Read flagged email today
Ccal: Dinner with wife today at 7PM
The first will add an entry in my todo list for checking my flagged email and the second will create an event in my calendar to remind me of my dinner date with my wife — you have no idea how much of a lifesaver that last one is!
I then define a custom Drafts 5 action that executes a piece of code written in JavaScript. The JavaScript code processes the text of a note using regular expressions and identifies the lines that contain calendar events or todo items.
The code then uses URL schemes to send the todo items to Todoist and the calendar events to Fantastical 2, natural language processing does the rest in each of these apps.
Below is the JavaScript code, which I modified from an existing action on the action directory of Drafts, that I use to do this:
// Process Meeting Notes
// Function for removing ("Ccal:" || "TTodoist:")
function taskrep(s) {
var f = ('Ccal: '||'TTodoist: ')
, r = ''
, re = new RegExp(f, 'g')
, matches = s.match(re);
if (matches) {
return s.replace(re,r);
}
}
function taskrep2(s) {
var f = ('Ccal: '||'TTodoist: ')
, r = ''
, re = new RegExp('TTodoist: ', 'g')
, matches = s.match(re);
if (matches) {
return s.replace(re,r);
}
}
// Scan for ("Ccal:" || "TTodoist:")
var d = draft.content;
var lines = d.split("\n");
var n = '';
for (var line of lines) {
if (line.includes("Ccal:")) {
line = taskrep(line);
const baseURL = "fantastical2://x-callback-url/parse/";
var cb = CallbackURL.create();
cb.baseURL = baseURL;
cb.addParameter("sentence", line);
cb.addParameter("add",1);
// open and wait for result
var success = cb.open();
if (success) {
console.log("Event created");
}else{
console.log("error!");
}
n += line + "\n";
} else if (line.includes("TTodoist:")) {
var x=line;
line = taskrep2(line);
// Todoist Action
var credential = Credential.create("Todoist", "Todoist API");
credential.addTextField("token", "Token");
credential.authorize();
// Call API
var http = HTTP.create(); // create HTTP object
var response = http.request({
"url": "https://todoist.com/api/v7/quick/add",
"method": "POST",
"data": {
"token":credential.getValue("token"),
"text":line,
}
});
n += line + "\n";
}
else {
n += line + "\n";
}
}
draft.content = n;
draft.update();
I hope you find this action useful, I use it for all my meeting notes.
1 Comment