Action

Add to Diary on Dynalist

Posted by sorashima, Last update over 4 years ago

Set the first line as the title and the rest as a note. Convert drafts tags to Dynalist tags and add them to note. Today’s date is also added to the note as a Dynalist date tag. Then add it to the Dynalist Inbox.

need Dynalist secret token.

When this action is executed for the first time, the token registration screen is displayed. In the second and subsequent executions, the token registered for the first time is read.
To delete the token, tap the “Forget” button of Dynalist in Credentials on Drafts setting screen.

2020-02-29

Changed the behavior to keep draft in the inbox when an error occurs due to a problem with the Dynalist server.

2020-02-07

Improved handling of communication error between Drafts and Dynalist server.

Steps

  • script

    var credential = Credential.create("Secret Token of Dynalist", "Dynalist");
    credential.addPasswordField("token", "Secret Token");
    credential.authorize();
    
    let tagLine = draft.tags.map(t => '#' + t).join(' ');
    let dlDateLine = '!(' + strftime(new Date(), '%F') + ')';
    
    var http = HTTP.create();
    var response = http.request({
      "url": "https://dynalist.io/api/v1/inbox/add",
      "encoding": "json",
      "method": "POST",
      "data": {
        "token": credential.getValue("token"),
        "index": "-1",
        "content": draft.processTemplate('[[title]]'),
        "note": draft.processTemplate('[[body]]') + '\n\n' + tagLine + '\n' + dlDateLine,
        "color": "1"
      }
    });
    
    
    if (response.success) {
      var rText = JSON.parse(response.responseText);
    
      if (rText._code == 'Ok') {
    //    alert(rText._code);
    //    app.displaySuccessMessage(`Posted to Dynalist successfully.`);
        app.displaySuccessMessage(rText._code);
    //    alert(rText.id);   
    //    app.setClipboard(rText.node_id);
      } else {
        alert(rText._code + '\n' + rText._msg);
        //app.displayErrorMessage(rText._msg);
        context.fail(rText._msg); 
      }
    
    } else {
    
      console.log(response.statusCode);
      console.log(response.error);
      alert(response.statusCode + '\n' + response.error);
      //app.displayErrorMessage(response.error);
      context.fail(response.error); 
    
    }

Options

  • After Success Archive , Tags: diary
    Notification Error
    Log Level Error
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.