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

simple-trovo-api

v1.1.10

Published

An open-source package that allows easy to integrate your applications with Trovo API.

Downloads

86

Readme

Simple Trovo API

An open-source package that allows easy to integrate your applications with Trovo API. All requests matching to the docs. This package supports TypeScript.

Usage

Before using this package you must register your application in Trovo Developer Portal, wait several days and receive Client ID of your application. If you already have, you can use this package.

List of available modules:

categories, channel, channels, chat, chat.service, users

Implict Flow

Fetch personal access token

If you already have access token, you can skip this step.

You must to fetch your personal token with generated with specified scopes and specified redirect url in page with your application. OAuth Implict Flow stores your access token only 10 days.

const { TrovoAPI } = require("simple-trovo-api");

const Trovo = new TrovoAPI({
    client_id: "xxxxxxxxx",
    client_secret: "xxxxxxxx",
    redirect_uri: "http://localhost:1337/"
});

const scopes = [];
const url = Trovo.getAuthLink(scopes, "token");
console.log(url);

Create new instance with Implict Flow

Now you can use this package at full power. Here is example of usage (fetch information about yourself):

const { TrovoAPI } = require("simple-trovo-api");

(async () => {
    const Trovo = new TrovoAPI({
        client_id: "xxxxxxxxx",
        client_secret: "xxxxxxxx",
        redirect_uri: "http://localhost:1337/"
    });

    await Trovo.auth(access_token);
    const user = await Trovo.users.getUserInfo();
    console.log(user);
})();

Code Flow

OAuth code flow works a little harder, but you don't need to manually update your tokens in future. Access token and refresh token will be refresh automatically until refresh token is valid. One refresh token storing for only 30 days.

Authorization

const { TrovoAPI } = require("simple-trovo-api");

const Trovo = new TrovoAPI({
    client_id: "xxxxxxxxx",
    client_secret: "xxxxxxxx",
    redirect_uri: "http://localhost:1337/",
    credits: "credits.json"
});

const scopes = [];
const url = Trovo.getAuthLink(scopes, "code");
console.log(url);

/*
After you enter your login and password on Trovo login page, 
you must to exchange received code to access token and refresh token.
*/

await Trovo.exchange(code);

Create new instance with Code Flow

There is same example.

const { TrovoAPI } = require("simple-trovo-api");

(async () => {
    const Trovo = new TrovoAPI({
        client_id: "xxxxxxxxx",
        client_secret: "xxxxxxxx",
        redirect_uri: "http://localhost:1337/",
        credits: "credits.json"
    });

    await Trovo.auth();
    const user = await Trovo.users.getUserInfo();
    console.log(user);
})();

Chat

Trovo uses simple WebSocket connection to receive messages from your chat and simple-trovo-api realize some events to interact with. Before using chat service you must to refresh chat token on every connecting or reconnecting.

You can to specify config for chat service.

ChatServiceConfig

| Name | Required | Type | Description | | :--- | :---: | :---: | :--- | | user_id | false | number | ID of channel you want to connect. Script will fetch chat token of specified channel or your chat token by default if is not specified | | messages.fetchPastMessages | false | boolean | Receive all past messages on connection |

Example:

const TrovoChat = await Trovo.chat.connect(chatServiceConfig?);

TrovoChat.on(TrovoChat.events.READY, () => {
    console.log("Trovo chat has been connected");

    // Listen regular chat messages
    TrovoChat.messages.on(TrovoChat.messages.events.MESSAGE, message => {
        console.log(message);
    });

    // Emitting only if you specified messages.fetchPastMessages to true
    TrovoChat.messages.once(TrovoChat.messages.events.PAST_MESSAGES, messages => {
        console.log(`There is ${messages.length} of old messages`);
    });

    /*
        Listen special events
        Special event examples: follow, unfollow, spells
    */

    TrovoChat.messages.on(TrovoChat.messages.events.SPELLS, message => {
        const user = message.nick_name;
        const spell = message.content.gift;
        const count = message.content.num;
        const cost = message.content.gift_value;
        const value = message.content.value_type;

        console.log(`${user} uses ${count}x${spell} for ${cost} ${value}!`);
    });

    TrovoChat.messages.on(TrovoChat.messages.events.FOLLOW, follow => {
        console.log(`Thank you for following, ${follow.nick_name}!`);
    });
});

TrovoChat.on(TrovoChat.events.DISCONNECTED, reason => {
    console.error("Trovo chat has been disconnected", reason);
});

Chat service has an listeners for special events in chat. There is a list of events.

spells, super_cap, colorful, spell, bullet_screen, subscription, system, follow, welcome, gift_sub_random, gift_sub, activity, raid, custom_spell, stream, unfollow