• Stars
    star
    705
  • Rank 62,617 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 6 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🐘 Universal Mastodon API client for JavaScript

Universal Mastodon API client for JavaScript

npm

Q&A | Examples | Read the Docs | Releases

Features

  • 🌎 Universal: Works in Node.js, browsers, and Deno
  • πŸ“¦ Lightweight: Less runtime codes, 7kB+ minified and gzipped
  • πŸ“š TypeScript: Written in TypeScript, and provides type definitions
  • πŸ§ͺ Tested: 99% test coverage using a real Mastodon server
  • πŸ€“ Maintained: Actively maintained by a Fediverse lover since 2018

Migration Guides

Who's using Masto.js?

Quick Start

In this quick start, we'll look at how to create a simple Mastodon bot that publishes a post using Masto.js.

First, you must install Node.js and npm in your environment. Follow the npm official guide for the setup, and proceed to the next step when it's ready. Alternatively, you can use yarn, pnpm or other package managers to install Masto.js, but this guide below uses npm.

The minimal required version of dependencies is as follows

  • Node.js: >= 18.x
  • npm: >= 9.x
  • TypeScript (optional peer dependency): >= 5.0.0

If you could successfully install Node.js and npm, create your first Masto.js project with the following command. Assume you're using a POSIX-compatible operating system.

Create a directory and initialise your project.

mkdir my-bot
cd my-bot
npm init es6 --yes

And install Masto.js using npm

npm install masto

Now you successfully initialised your project for developing a Mastodon bot. Next, you need to create an application to obtain an access token required to access your account.

Go to your settings page, open Development, and click the New Application button to earn your personal access token.

Create New App

You need to fill out Application name, but the website and redirect URI are fine to be the default for now. What you need to select for Scopes is depending on your bot's ability, but you can access most of the functionality by granting read and write. See OAuth Scopes documentation for further information.

If you could create an application, save Your access token securely. This string is required to access your account through Masto.js.

Then you're almost there! Create a file named index.js inside your project directory and add the following code. This is an example which will post a status from your account.

import { createRestAPIClient } from "masto";

const masto = createRestAPIClient({
  url: process.env.URL,
  accessToken: process.env.TOKEN,
});

const status = await masto.v1.statuses.create({
  status: "Hello from #mastojs!",
  visibility: "public",
});

console.log(status.url);

Finally, run the program with the following command. Replace {URL} with your instance's URL such as https://mastodon.social, and {TOKEN} to your access token that you obtained in the previous section.

URL={URL} TOKEN={TOKEN} node ./index.js

Other available features are described in the documentation. You may also want to refer /examples directory on this repository.

Contribution

See CONTRIBUTING.md

License

Masto.js is distributed under the MIT license

More Repositories

1

vschedule

⌚Unofficial redesign of itsukara.link, a scheduler for Nijisanji
TypeScript
63
star
2

next-composition

Next.js utility for reusing getServerSideProps and getStaticProps logics
TypeScript
38
star
3

vscode-qiita

πŸ” Smart Qiita integration for Visual Studio Code
TypeScript
32
star
4

accessible-react-101

♿️ React & Next.js example how to meet WCAG 2.1 in the real world apps
TypeScript
30
star
5

opelete

πŸ’« Browser extension that autocompletes Google search operator
TypeScript
24
star
6

use-iterator

React hooks collection for for-await-of and JavaScript's Iteration Protocols.
TypeScript
11
star
7

neet.love

πŸ’– My portfolio, built on top of GatsbyJS
TypeScript
8
star
8

mirrortter

🐘 Forward awesome toots to Twitter from the fediverse
TypeScript
8
star
9

react-as-prop

Type-safe `as` prop utility for flexible and semantic UI components of React
TypeScript
7
star
10

neet

Profile page for @neet
7
star
11

big-sur-icons-replacer

JavaScript
5
star
12

palenight-kitty

Port of Material Palenight theme for Kitty
4
star
13

i18next-cli-language-detector

🌎 i18next third-party language detector for CLI
TypeScript
3
star
14

zenn.dev

Zenn articles
Nix
2
star
15

deno-masto

[WIP] An experimental Deno implementation of Masto.js
TypeScript
2
star
16

puppeteer-ipc

Lightweight wrapper for mutual communication on Puppeteer, inspired by Electron
TypeScript
2
star
17

hanzily

(WIP) webextension transforms shinji/kyuji characters
TypeScript
2
star
18

paskur

A personal URL redirection service
Rust
1
star
19

qiita-js-2

Modern Qiita v2 API client for Node/Browser
TypeScript
1
star
20

hash-avatar

Created with CodeSandbox
TypeScript
1
star