Skip to content

Instantly share code, notes, and snippets.

@macdonst
Created February 5, 2023 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macdonst/cee3006a511f31414d14a268ae35c817 to your computer and use it in GitHub Desktop.
Save macdonst/cee3006a511f31414d14a268ae35c817 to your computer and use it in GitHub Desktop.
Post a message to Mastodon
import Meg from 'megalodon'
const { default: generator } = Meg
// switch to your mastodon server
const BASE_URL = 'https://mastodon.online/'
const access_token = process.env.MASTODON_TOKEN
export async function handler (event) {
const {title, link, description} = JSON.parse(event.Records[0].Sns.Message)
const toot = `${title}
${description}
${link}
`
const client = generator('mastodon', BASE_URL, access_token)
console.log(toot)
const res = await client.postStatus(toot)
console.log(res.data)
return
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment