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

telebotframework

v0.11.2

Published

A framework for easy creation of bots for Telegram

Downloads

4

Readme

ABANDONED

If you wish to take over the project, or the name, contact me

telebotframework

A framework for easy creation of bots for Telegram The framework relies on ES2015 to work, so older versions of node are not supported.

How to create a bot

Creating a bot is very simple. The following code initializes a bot

var TelegramBot = require("telebotframework").TelegramBot;

var SomeBot = new TelegramBot("the bot's very secret token");

The bot is now ready to do anything you tell it to do. Let's first tell it to listen for updates automatically:

SomeBot.startLongpolling();

The bot will now automatically fetch whatever is sent to it, by internally using the getUpdates method of teleapiwrapper. You can access the messages by binding to events on the bot:

SomeBot.on("text", message => {
  console.log("I got some text!! The text I got was '" + message.text + "'");
});
SomeBot.on("command", message => {
  console.log("I got a command!! The command was '" + message.command + "' and the arguments to the command were '" + message.argstring + "'");
});
SomeBot.on("file", message => {
  console.log("I got a file!! Saving it to 'Somefile.file'");
  message.saveFile("Somefile.file");
});

There are many more events. See the docs for more.

Answering to messages is also simple:

SomeBot.on("text", message => {
  message.answer("I got your message!");
});

This will send the text "I got your message!" to the chat the message originated from. You want to reply to a message? Easy!

SomeBot.on("text", message => {
  message.reply("I replied to your message!");
});

These methods return promises, which you can hook onto with .then and .catch to get notified when the messages are delivered or failed to deliver.

More advanced use

The original message object received from getUpdates or setWebhook in the API is available on each message object received through the events. Look at the rawMessage property of the messages.

Your bot has a property API. This is an instance of teleapiwrappers BotAPI. If you need more advanced capabilities than the methods in this framework can provide, like sending a reply keyboard with your message, or sending a file, you can invoke the methods of teleapiwrapper directly through this property.

Also, if you prefer to use webhooks or some other method of getting the update instead of going through the bot's built-in longpolling, there is a method for you. Your bot has the method processUpdates, which takes an array of raw Update objects

The documentation

Everything in the framework is documented with JSDoc. The documentation is available in node_modules/telebotframework/docs/index.html. Use it well. They are also readable on https://doc.suppen.no/telebotframework

Changelog

  • 0.11.1: Updated the documentation
  • 0.11.0: Gave message objects an "id" property, and deprecated "sender" in favor of "from". "sender" still works
  • 0.10.3: Fixed a bug where a promise was not returned when a file was saved