Action

Process Meeting Notes

Posted by @nahumck, Last update almost 6 years ago - Unlisted

Process meeting notes to send prefixed items to Things or Todoist. Lines must contain “TThings: “ or “TTodoist: “.

Recommended action: https://actions.getdrafts.com/a/1EI

Steps

  • script

    // Process Meeting Notes
    
    // Function for removing ("TThings:" || "TTodoist:")
    function taskrep(s) {
      var f       = ('TThings: '||'TTodoist: ')
        , r       = ''
        , re      = new RegExp(f, 'g')
        , matches = s.match(re);
      if (matches) {
        return s.replace(re,r);
      }
    }
    
    // Scan for ("TThings:" || "TTodoist:")
    var d = draft.content;
    var lines = d.split("\n");
    var n = '';
    
    for (var line of lines) {
    	if (line.includes("TThings:")) {
    		var todo = TJSTodo.create();
    		todo.title = line;
    		todo.tags = ["Singles"];
    		var container = TJSContainer.create([todo]);
    		// Use CallbackURL object to open URL in Things.
    		var cb = CallbackURL.create();
    		cb.baseURL = container.url;
    		var success = cb.open();
    		if (success) {
    			console.log("Task created in Things");
    		}
    		else {
    			context.fail();
    		}
    		line = taskrep(line);
    		n += line + "\n";
    	}
    	if (line.includes("TTodoist:")) {
    		// 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,
    		  }
    		});
    		line = taskrep(line);
    		n += line + "\n";
    	}
    	else {
    		n += line + "\n";
    	}
    }
    draft.content = n;
    draft.update();
    // create Dropbox object
    var db = Dropbox.create();
    // setup variables
    var path = "/test/"+draft.title+".txt";
    var content = draft.content;
    // write to file on Dropbox
    var success = db.write(path, content, "add", true);

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.