Action

crosslink Todoist task & Craft document

Posted by @FlohGro, Last update 5 months ago

UPDATES

5 months ago

name updated

show all updates...

5 months ago

name updated

5 months ago

Name updated

crosslink to Craft and Todoist

  • this action will create a new Craft Document from the content of the current draft
  • the first line of the draft will be used as title of the Craft Document
  • after creating the Craft Document, the action will add a new taks to the inbox of your Todoist account. the title of the draft will be the name of the task with a click-/tapable link to the craft document
  • after the task in todoist is created, the action will prepend a link to the todoist task into the previously 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

  • to make this action work, you need to configure the spaceId.
  • You can get it by copying the deepplink of a document in this space. Paste the link into a new draft and extract the combination like “2159f404-e3ed-4d8a-fbe1-6c36499c8f3” after spaceId= in the link.
  • replace “unconfigured” with this id in the spaceID variable of the script (attention: only replace the unconfigured in line 5!).

if you find this useful you can Buy Me A Coffee

Steps

  • script

    // cross linked craft note and todoist task
    
    // insert your preferred space ID for a document here. You can get it by copying the deepplink of a document in this space. Paste the link into a new draft and extract the combination like "2159f404-e3ed-4d8a-fbe1-6c361399c8f3" after spaceId= in the link. replace "unconfigured" with this id in the spaceID variable.
    
    const spaceID = "unconfigured"
    
    if(spaceID == "unconfigured"){
    
    let errorMsg = "the spaceID variable was not configured in the script"
    alert(errorMsg)
    context.fail(errorMsg)
    
    } else {
    
    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()
    }
    }

Options

  • After Success Default
    Notification Info
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.