Action

Markdown to Pleroma

Posted by reorx, Last update about 1 month ago

Example action demonstrating using the Pleroma API via script to post the draft as markdown format.

IMPORTANT: Before using this action, edit the first to “Define Template Tag” steps to enter the Mastodon instance host and credential identifier to use.

For more examples, see our Mastodon Integration Guide

Steps

  • defineTemplateTag

    name
    mastodon-host
    template
  • defineTemplateTag

    name
    credential-id
    template
  • script

    // grab host-id from tags
    let host = draft.processTemplate("[[mastodon-host]]")
    let credentialID = draft.processTemplate("[[credential-id]]")
    
    // validate values
    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()
    }
    
  • script

    // create Mastodon instance
    let m = Mastodon.create(host, credentialID)
    
    // setup content to use
    let content = draft.content
    
    // post to the /statuses endpoint
    let path = "/api/v1/statuses"
    let data = {
    	"status": content,
    	"source": "Drafts",
    	"content_type": "text/markdown",
    	"visibility": "public"
    }
    let response = m.request({
      "path": path,
      "method": "POST",
      "data": data
    })
    
    if (!response.success) {
    	console.log(`Post Failed: ${response.statusCode}, ${response.error}`)
    	context.fail()
    }
    else {
    	console.log(`Posted to Mastodon: ${response.responseData["url"]}`)
    }

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.