Coder Social home page Coder Social logo

ujeong1 / masto.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from neet/masto.js

0.0 0.0 0.0 10.27 MB

๐Ÿ˜ Universal Mastodon API client for JavaScript

Home Page: https://neet.github.io/masto.js/

License: MIT License

JavaScript 0.50% TypeScript 99.36% Nix 0.13%

masto.js's Introduction

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

masto.js's People

Contributors

neet avatar dependabot-preview[bot] avatar dependabot[bot] avatar semantic-release-bot avatar sxzz avatar jacksonsamuel42 avatar webfansplz avatar dahlia avatar supersonichub1 avatar ayoayco avatar shinigami92 avatar lostfictions avatar johnythecarrot avatar shuuji3 avatar simon-he95 avatar 343max avatar danielroe avatar assaf avatar chdorner avatar fadookie avatar jasonbyrne avatar josephkreydt avatar hakatashi avatar kytta avatar thewalruzz avatar darnfish avatar kkoyung avatar teabroker avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.