Action
crosslink Todoist task & Craft document
UPDATES
about 1 year ago
fix cb url parameter issue
about 1 year ago
fix cb url parameter issue
almost 3 years ago
adapted to use credential store for space id, description updated
over 3 years ago
name updated
over 3 years ago
Name updated
created by @FlohGro / more on my Blog
crosslink Todoist task & Craft document
This action will create a cross-linked Task between Todoist and a Craft document.
A new Craft document will be created from the content of the current draft with the first line as title for the document.
After the document is created the action will create a new task in the inbox of your Todoist account with the title of the Craft document as task name. The task will contain a clickable link to open the corresponding Craft document
When the task was created the action will prepend a link to it into the created Craft document.
known “issue”: if you quickly open the link to the Todoist task after the action prepended the link to the task to the Craft document, your Todoist app may show an error telling you that the task could not be found. The reason for this is, that Todoist needs to sync the created task to your app first (the task is created via the REST API). After the task was synced, the error won’t occur again.
[Configuration]
If you don’t want to use the (any of my) action for different Craft spaces there is no configuration needed. When you first run any of my Craft actions it will ask you to store the space id of your Craft space. This is a one time action and you don’t need to do it for any other oof my Craft actions you install.
To use these actions with different spaces you need to duplicate the action for each space you want to use it. I recommend to e.g. add a suffix to the action name to describe the space for which you configure it.
The action uses Drafts possibility to store credentials to distinguish different spaces. When you duplicate the action for another space you have to change the name of the credential. Therefore you need edit this line const spaceIdCredentialName = "CraftDocumentSpace"
in the script step of the action and change the CraftDocumentSpace
to something different (e.g. describe the space in a suffix like „CraftDocumentSpacePersonal" or „CraftDocumentSpaceWork“. If you use several of my Craft actions you should use the same credential name in all of them.
[Usage]
Use this action to create a cross-linked task / document between your task manager and Craft. If you e.g. took some notes during a meeting or while reading a book / blog in Drafts which you need to review or complete later - just run this action. It will help you to quickly navigate between the task and the document without seeing distracting other content.
If you find this useful and want to support me you can
Steps
-
script
// cross linked craft note and todoist task // optional configuration of the spaceIdCredentialName - only necessary if you want to use the same action for different Craft Spaces const spaceIdCredentialName = "CraftDocumentSpace" let spaceID = getCraftSpaceIdToUse(); let title = draft.displayTitle let encodedTitle = encodeURIComponent(title) let content = draft.content content = encodeURIComponent(content) var proceed = true; const craftCreateBaseURL = "craftdocs://x-callback-url/createdocument?" const craftCreateBlockBaseURL = "craftdocs://createblock?" var cbCreateCraftNote = CallbackURL.create() cbCreateCraftNote.baseURL = craftCreateBaseURL cbCreateCraftNote.addParameter("spaceId", spaceID) cbCreateCraftNote.addParameter("title", title) cbCreateCraftNote.addParameter("content", content) cbCreateCraftNote.addParameter("folderId", "") cbCreateCraftNote.waitForResponse = true let craftCreateReturn = cbCreateCraftNote.open() if (craftCreateReturn == true) { console.log("Craft note successfully created") } else { proceed = false console.log("Craft note result:" + cb.status + " " + cb.callbackResponse) if (cb.status == "cancelled") { context.cancel() } else { context.fail() } } // craft note is created, now create the todoist task by using the REST API if (proceed) { // retrieve info from craftCreateResult let craftCreateResult = cbCreateCraftNote.callbackResponse var blockId = craftCreateResult.blockId var craftNoteLink = craftCreateResult.link let taskNoteStr = "Craft Note: " + craftNoteLink let taskTitle = "[" + title + "](" + craftNoteLink + ")" let todoist = Todoist.create(); var todoistAddResult = todoist.quickAdd(taskTitle); if(!todoistAddResult){ let message = "Failed to add Task to todoist: " + todoist.lastError; console.log(message) context.fail(message); app.displayErrorMessage(message); proceed = false } else { console.log("Successfully created todoist Task") } } // things task added now prepend the link to the previously created craft note if (proceed) { // retrieve info from todoistAddResult let taskID = todoistAddResult["id"] let showTaskUrl = "todoist://task?id=" + taskID let openTaskStr = "> Task in Todoist: [" + title + "](" + showTaskUrl + ")" let encodedBlockContent = encodeURIComponent(openTaskStr) var cbCreateCraftBlock = CallbackURL.create() cbCreateCraftBlock.baseURL = craftCreateBlockBaseURL cbCreateCraftBlock.addParameter("spaceId", spaceID) cbCreateCraftBlock.addParameter("parentBlockId", blockId) cbCreateCraftBlock.addParameter("index", "0") cbCreateCraftBlock.addParameter("content", encodedBlockContent) cbCreateCraftBlock.waitForResponse = false cbCreateCraftBlock.open() } function getCraftSpaceIdToUse() { let credential = Credential.create(spaceIdCredentialName, "Credential to store the spaceId of the space you want to use in Drafts.\ninsert your spaceId into the TextField below. \n\nNOTES: \n- this is a one time action, you don't need to do it everytime\n- Multiple spaces are currently not supported with this spaceId credential helper"); credential.addTextField("spaceId", "spaceId"); if (credential.authorize()) { return credential.getValue("spaceId"); } else { let errorStr = "failed storing / retrieving space Id with credential" app.displayErrorMessage(errorStr); context.fail(errorStr); console.log(errorStr); return false; } }
Options
-
After Success Default Notification Info Log Level Info