Action
Markdown to Pleroma
UPDATES
over 1 year ago
Move credential-id from template tags to credential
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 dabr.ca
-
defineTemplateTag
name extra-tag
template toot
-
script
// grab host-id from tags let host = draft.processTemplate("[[mastodon-host]]") // 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() } // credentials const credential = Credential.create('Markdown to Pleroma', "Send Markdown to Pleroma"); credential.addPasswordField('credentialID', "Your ID in the fediverse server"); credential.authorize(); const credentialID = credential.getValue('credentialID'); // validate values if (! credentialID) { alert(`Credential ID must be configured to run this action.`) context.cancel() }
-
script
// create Mastodon instance let m = Mastodon.create(host, credentialID) // setup content to use let content = draft.content let extraTag = draft.processTemplate("[[extra-tag]]") // 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"]}`) draft.addTag(extraTag) draft.update() }
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.