Action

Add to Diary on Dynalist (2 colors)

Posted by sorashima, Last update over 4 years ago
  1. Set the first line of the draft as the title and the rest as note for the node.
  2. Convert drafts tags to Dynalist tags and add them to note.
  3. If you choose red for the title color, today’s date will also be added to the note as a Dynalist date tag.
  4. Then add it to the Dynalist Inbox.

You need to enter the Dynalist Secret Token the first time you launch this action.

The first time you launch this action, the Dynalist Secret Token registration dialog is displayed.
Enter the token there and it will be saved in “Credetials”.
The token saved in “Credetials” will be used to send data to Dynalist for the next invocation of this action.

To delete the token, tap the “Forget” button in the Dynalist field in Drafts Settings > Credetials.

The original version I made earlier is here.

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 p = Prompt.create();
    p.title = 'Which style do you use?'
    p.addButton('Red with date-tag', 1);
    p.addButton('Blue without date-tag', 5);
    
    if (!p.show()) {
    
      context.cancel();
      
    } else {
    
      let dlDateLine = (p.buttonPressed == 1) ? `!(${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": p.buttonPressed
        }
      });
    
    
      if (response.success) {
        var rText = JSON.parse(response.responseText);
    
        if (rText._code == 'Ok') {
          app.displaySuccessMessage(rText._code);
        } else {
          alert(rText._code + '\n' + rText._msg);
          context.fail(rText._msg); 
        }
    
      } else {
    
        console.log(response.statusCode);
        console.log(response.error);
        alert(response.statusCode + '\n' + 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.