Action

Mastodon Reply

Posted by Maxim Syomochkin, Last update about 1 year ago

UPDATES

about 1 year ago

  • Added visibility level validation
show all updates...

about 1 year ago

  • Added visibility level validation

about 1 year ago

  • Added “visibility” as a template tag. If this tag is not set, the default value of “public” is used.

about 1 year ago

  • description update

about 1 year ago

  • Fix name

about 1 year ago

  • update icon

about 1 year ago

  • Fix toot visibility level

Mastodon Reply allows you to reply to a toot directly from within the Draft app!

Just save the URL of the original toot in the first line of your draft (title), write your reply to it in the main body of the draft, run this action, and voilà - you have replied to the toot.

When you “Share” a toot from most clients to the Drafts share extension, it just sends the URL to the toot. You can then hit “Open” to jump to it that in Drafts and start a reply with the URL filled in the first line.

IMPORTANT: Before using this action, edit the first to “Define Template Tag” steps to enter the Mastodon instance host and credential identifier to use. If «visibility» is not set will be used default value «public».

https://mak-sim.ru

Steps

  • defineTemplateTag

    name
    mastodon-host
    template
  • defineTemplateTag

    name
    credential-id
    template
  • defineTemplateTag

    name
    visibility
    template
  • script

    let host = draft.processTemplate("[[mastodon-host]]");
    let credentialID = draft.processTemplate("[[credential-id]]");
    
    if (host.length == 0 || host == "your.mastodon") {
    	alert(`Mastodon host must be configured to run this action.
    
    Edit action and set your Mastodon host name (like "mastodon.social") as the template value in the first "Define Template Tag" action step.
    `)
    	context.cancel()
    }
    
    let visibility = draft.processTemplate("[[visibility]]");
    if (visibility === "") {
    	visibility = "public";
    }
    
    const levels = ["public", "private", "unlisted", "direct"];
    
    
    if (!levels.includes(visibility)) {
    	alert(`Visibility level must be one of the following: ${levels.join(", ")}!`);
    	context.cancel()
    }
    
  • script

    const mastodon = Mastodon.create(host, credentialID);
    
    const searchPath = "/api/v2/search";
    const statusPath = "/api/v1/statuses";
    
    const statusURL = draft.title;
    
    const tootLines = draft.lines;
    tootLines.shift();
    const toot = tootLines.join("\n");
    
    const response = mastodon.request({
      "path": searchPath,
      "method": "GET",
      "parameters": {
    	"q": statusURL,
    	"type": "statuses",
    	"resolve": true
      }
    });
    
    if (response.success) {
    	const statusID = response.responseData.statuses[0].id;
    	replay(statusID);
    }
    else {
      console.log(response.error);
      context.fail();
    }
    
    function replay(id) {
    	const responseReplay = mastodon.request({
    		"path": statusPath,
    		"method": "POST",
    		"parameters": {
    			"status": toot,
    			"in_reply_to_id": id,
    			"visibility": visibility
    	  }
    	});
    }
    
    
    script.complete();

Options

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