Skip to content

Instantly share code, notes, and snippets.

@keyboardcrunch
Last active February 5, 2024 11:30
Show Gist options
  • Save keyboardcrunch/c11b394c80d06ac8674db761fdcfc8e0 to your computer and use it in GitHub Desktop.
Save keyboardcrunch/c11b394c80d06ac8674db761fdcfc8e0 to your computer and use it in GitHub Desktop.
MastoJs with Deno

Posting to Mastodon with MastoJs and Deno

This is a quick start for simply posting to Mastodon using the NPM module MastoJs (v6.0.1) with the lastest Deno (v1.35.3). There's nothing really to this, you can mostly copy the MastoJs docs but skypack was the only CDN I could get working for the import.

Steps:

  • Create an application under your Mastodon account settings and copy the access token.
  • Create your deno.json with the import for mastojs
  • Create your app like the post.ts, make sure to update the server and access token.
  • Run with deno run -A post.ts
{
"imports": {
"masto": "https://cdn.skypack.dev/masto@6.1.0?dts"
}
}
import { createRestAPIClientmastodon, type mastodon } from "masto";
const masto = createRestAPIClient({
url: "YOUR MASTODON SERVER",
accessToken: "YOUR ACCESS TOKEN",
});
const s: mastodon.v1.Status = await masto.v1.statuses.create({
status: "Hello from #mastojs running with Deno!",
visibility: "private",
});
console.log(s);
// execution hangs after post for about a minute, not sure why yet...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment