Action
 Post to Mastodon (Script)
Post to Mastodon (Script)
                  
        Posted by agiletortoise,
    Last update
    almost 3 years ago
    Example action demonstrating using the Mastodon API via script to post a public status update.
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
- 
    defineTemplateTagname mastodon-host template your.mastodon 
- 
    defineTemplateTagname 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 endpoing let path = "/api/v1/statuses" let data = { "status": content, "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.