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

telebunny

v0.10.0

Published

Lightweight zero-dependency Node.js module for Telegram Bot API

Downloads

21

Readme

Lightweight zero-dependency Node.js module for Telegram Bot API.

Bot API Version Node Version NPM Package Version

https://t.me/FBFunnyBunnyFB

📥 Installation

npm i telebunny

🐇 Usage (Polling)

import { TeleBunny } from "telebunny";

// Replace <TOKEN> with your bot token
const BOT_TOKEN = "<TOKEN>";
// Use "polling" option for fetching new updates using polling method
const TelegramBot = new TeleBunny(BOT_TOKEN, { polling: true });

// Use listeners to get data from Telegram users
// Update type parameter can be found on official Telegram Bot API
TelegramBot.on('message', msg => {
    // Send response message to chat
    TelegramBot.sendMessage(msg.chat.id, "Got message update");
});

// You can also use "got" method as the alias for "on" listeners
TelegramBot.got('edited_message', msg => {
    // TeleBunny class instance supports two different option masks
    // You can pass options to method in such a way:
    // ~ pass all options in first argument as object
    // OR
    // ~ pass options according to API required fields
    TelegramBot.sendMessage(msg.chat.id, "Got edited_message update", {
        allow_sending_without_reply: true,
        reply_to_message_id: msg.message_id
    });
    // Uncomment to test alternative method
    /*
    TelegramBot.sendMessage({
        chat_id: msg.chat.id,
        text: "Got edited_message update (raw options)",
        allow_sending_without_reply: true,
        reply_to_message_id: msg.message_id
    });
    */
})

🐇 Usage (Webhook)

// Production server code example
// You can use any library/framework for handling HTTP/HTTPS requests
import { TeleBunny } from "telebunny";
import { createServer } from "http";

// Replace <TOKEN> with your bot token
const BOT_TOKEN = "<TOKEN>";
// Replace <WEBHOOK> with your url
const WEBHOOK_URL = "<WEBHOOK>"+BOT_TOKEN;
// You don't need to set "polling" option when using webhook
const TelegramBot = new TeleBunny(BOT_TOKEN);

// Set webhook
TelegramBot.setWebhook(WEBHOOK_URL);

// Add listener for inline requests
TelegramBot.on("inline_query", msg => {
    const query = msg.query || "npm telebunny";
    TelegramBot.answerInlineQuery({
        inline_query_id: msg.id,
        button: {
            text: "Search \""+query+"\" in Google",
            web_app: {
                url: "https://www.google.com/search?q="+encodeURIComponent(query)
            }
        }
    });
});

// Create HTTP server
createServer((req, res) => {
    // Process only POST requests for webhook route
    if(req.method !== "POST" || req.url !== "/"+BOT_TOKEN) return;
    const chunks:any = [];
    req.on('data', (chunk) => chunks.push(chunk));
    req.on('end', () => {
        const data = Buffer.concat(chunks);
        // To process incoming messages use processUpdate() method
        // "data" variable must be Buffer or object type
        TelegramBot.processUpdate(data);
    });
    res.writeHead(200);
    res.end();
}).listen(process.env.PORT || 3000);

🔑 License

The MIT License (MIT)

Copyright © 2023 Funny Bunny