Action

Mastodon Reply

Posted by Maxim Syomochkin, Last update almost 2 years ago

UPDATES

almost 2 years ago

  • Added visibility level validation
show all updates...

almost 2 years ago

  • Added visibility level validation

almost 2 years ago

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

almost 2 years ago

  • description update

almost 2 years ago

  • Fix name

almost 2 years ago

  • update icon

almost 2 years 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.