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

tg-bot

v1.4.0

Published

Telegram bot api

Downloads

1

Readme

Telegram Bot API module for NodeJS

The Bot API is an HTTP-based interface created for developers keen on building bots for Telegram. Read more about the bots at the introduction for developers page.

Installation

Installation via npm:

$ npm install tg-bot --save

Initialization

var Bot = require('tg-bot');
var bot = new Bot();

Setting token

For calling API you need special token wich you can receive using BotFather. Read more about how to receive token.

You can set token in three different ways. At the initialization:

var Bot = require('tg-bot');
var bot = new Bot({token: "115552161:AAGBbCX-y9O2tBdMXs6GOpeDrGrXpbiqlCs"});

Using special method:

bot.setToken("115552161:AAGBbCX-y9O2tBdMXs6GOpeDrGrXpbiqlCs");

At the API call:

var token = "115552161:AAGBbCX-y9O2tBdMXs6GOpeDrGrXpbiqlCs";
bot.sendMessage({token: token, chat_id: 1234, text: "Hello world!"}, function(err, reply){
	
});

Calling API

See the full list of API at the Telegram Bot API page.

You can use two methods for calling API. Using object's methods:

bot.getMe(function(err, my_data){
	
});

bot.sendMessage({chat_id: 1234, text: "Hello world!"}, function(err, reply){
	
});

Or using direct API calls:

bot.apiCall("getMe", function(err, my_data){
	
});

Parsing commands

Module automatic detect commands in updates and parsing params of command. If we will send message like this:

/ticketadd some values -i info "some long tex"

We will receive next update object with additional field command:

{
	"update_id": 123456,
		"message":{
		"message_id": 123456,
		"from":{},
		"chat":{},
		"date":1435701586,
		"text":"/activate some params -i info \"some long tex\" --flag --state=activated",
		"command":{
			"name":"activate",
			"params":{
				"_":[
					"some",
					"params",
					"some long tex"
				],
				"i":"info",
				"flag":true,
				"state":"activated"
			}
		}
	}
}

Uploading files

You can send files in four different ways. Using file_id:

var file_id = "AgADAgADrKcxG6Ev4wbe4YsNsXRAbEG9WSoABJyhV2Lvy8uetB4AAgI";
bot.sendPhoto({chat_id: 123456, photo: file_id}, function(err, data){

})

Using file URL:

var file_url = "http://d.ibtimes.co.uk/en/full/1372072/doge.jpg";
bot.sendPhoto({chat_id: 123456, photo: file_url}, function(err, data){

})

Using file path:

var file_path = "/Users/websnipter/Downloads/my_doc.doc";
bot.sendDocument({chat_id: 123456, document: file_path}, function(err, data){

})

Using readStream:

var file_path = "/Users/websnipter/Downloads/video.mp4";
var read_stream = fs.createReadStream(file_path)
bot.sendVideo({chat_id: 123456, video: read_stream}, function(err, data){

})

This methods working for all methods that require upload:

  • sendPhoto
  • sendAudio
  • sendDocument
  • sendSticker
  • sendVideo

Aditional methods

Waiting for new updates. This method the same as getUpdates. But it will be wait for not empty response. If you will set offset param to last update_id value increased by one, this method will be waiting for new income updates.

bot.waitForUpdates({offset: 937477095}, function(err, new_updates){
	
});

Useful links

Contacts

Jaroslav Khorishchenko

[email protected]