npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mastobot

v0.1.0-2

Published

Mastodon client library with an eye toward bot development

Downloads

2

Readme

MastoBot

NodeJS Mastodon client library with an eye to making bot development fun & easy.

This is an early-stage project, but there is documentation!

You can follow development, submit issues, and contribute at GitLab

Installation

npm i mastobot

Basic Usage


const { MastoBot } = require('mastobot');

const api_url    = 'https://botsin.space/';
const api_token  = 'your API Token goes here';

const mb = new MastoBot(api_url, {
  api_token,
});

// The MastoBotHttp class offers helpers for HTTP requests.
// Wrappers for relevant HTTP methods are complete and fully usable:
// get, post, put, patch, delete
// They all expect the same parameters:
//   url      {string}    Path to the API endpoint, including the v1/ or v2/ prefix
//   data     {Object}    Properties will first populate :params in the path, remaining
//                        properties will be sent in the query string (GET) or request body
//   options  {Object}    Additional options, like headers. Rarely used.
mb.get('v1/accounts/verify_credentials')
.then(response => {
  console.log('Credentials are good!', response.data.acct);
})
.catch(apiError => {
  console.error('Credentials are bad:',
    apiError.statusCode,
    apiError.statusText,
    apiError.data.error);
});

mb.patch('v1/accounts/update_credentials', {
  'source[language]': 'en',
  'bot': true,
}).then(response => {
  console.log('Updated credentials successfully!', response.data);
}).catch(apiError => {
  console.error('Patch failed:',
    apiError.statusCode,
    apiError.statusText,
    apiError.data);
});


// The MastoBotAPI class builds on MastoBotHttp and offers fancier wrappers
// for API endpoints. At present, the most commonly used endpoints are
// covered. More will come.
mb.postStatus('Wow, MastoBot is really fun and easy!', {
  visibility: 'public',
})
.then(response => {
  console.log('Posted status successfully!', response.data.url);
})
.catch(apiError => {
  console.error('Post failed:',
    apiError.statusCode,
    apiError.statusText,
    apiError.data);
});


// NYI: The full MastoBot class presents all of the above, as well as
// a "smart" callback API for certain API calls:
mb.processNotifications({
  onMention: notification => mentionCallback(notification),
  onFollow: notification => followCallback(notification),
  onFavourite: notification => favouriteCallback(notification),
})
.then(response => {
  // response is an array of callback return values/Promises
  console.log('Processed notifications successfully!', response.length);
})
.catch(apiError => {
  console.error('Processing notification(s) failed:',
    apiError,
});