Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-telegram-bot-api

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-telegram-bot-api - npm Package Compare versions

Comparing version 0.2.0 to 0.3.0

yagop/node-telegram-bot-api/.npmignore

19

output.md

@@ -7,5 +7,5 @@

NodeJS class for Telegram Bot API.
Support for WebHooks and long polling.
Emits `message` when message arrives.
Both request method to obtain messages are implemented. To use standard polling, set `polling: true`
on `options`. Notice that [webHook](https://core.telegram.org/bots/api#setwebhook) will need a valid (not self signed) SSL certificate.
Emmits `message` when a message arrives.

@@ -17,3 +17,3 @@ See: https://core.telegram.org/bots/api

* **String** *token* Bot Token
* **Object** *[options]*
* **Object** *[options]*
* **Boolean|Object** *[options.polling=false]* Set true to enable polling

@@ -31,3 +31,3 @@ * **String|Number** *[options.polling.timeout=4]* Polling time

* **Promise**
* **Promise**

@@ -72,3 +72,3 @@ ## setWebHook(url)

* **Promise**
* **Promise**

@@ -87,3 +87,3 @@ ## forwardMessage(chatId, fromChatId, messageId)

* **Promise**
* **Promise**

@@ -104,3 +104,3 @@ ## sendPhoto(chatId, photo, [options])

* **Promise**
* **Promise**

@@ -121,4 +121,5 @@ ## sendAudio(chatId, audio, [options])

* **Promise**
* **Promise**
<!-- End src/telegram.js -->
{
"name": "node-telegram-bot-api",
"version": "0.2.0",
"version": "0.3.0",
"description": "Telegram Bot API",

@@ -17,4 +17,4 @@ "main": "index.js",

"scripts": {
"test": "mocha test/index.js",
"test-cov": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
"test": "./node_modules/.bin/mocha test/index.js",
"test-cov": "./node_modules/.bin/istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
},

@@ -21,0 +21,0 @@ "author": "Yago Pérez <yagoperezs@gmail.com>",

@@ -1,100 +0,137 @@

[![Build Status](https://travis-ci.org/yagop/telegram-bot-api.svg?branch=master)](https://travis-ci.org/yagop/telegram-bot-api) [![Coverage Status](https://coveralls.io/repos/yagop/telegram-bot-api/badge.svg?branch=develop)](https://coveralls.io/r/yagop/telegram-bot-api?branch=develop)
[![Build Status](https://travis-ci.org/yagop/node-telegram-bot-api.svg?branch=master)](https://travis-ci.org/yagop/node-telegram-bot-api) [![Coverage Status](https://coveralls.io/repos/yagop/node-telegram-bot-api/badge.svg?branch=master)](https://coveralls.io/r/yagop/node-telegram-bot-api?branch=master)
Node.js module to interact with official [Telegram Bot API](https://core.telegram.org/bots/api). A bot token is needed, to obtain one, talk to [@botfather](telegram.me/BotFather) and create a new bot.
```sh
npm install node-telegram-bot-api
```
```js
var TelegramBot = require('node-telegram-bot-api');
var token = 'YOUR_TELEGRAM_BOT_TOKEN';
// Setup polling way
var bot = new TelegramBot(token, {polling: true});
bot.on('message', function (msg) {
var chatId = msg.chat.id;
// photo can be: a file path, a stream or a Telegram file_id
var photo = 'bot.gif';
bot.sendPhoto(chatId, photo, {caption: "I'm a bot!"});
});
```
There are some other examples on [examples](https://github.com/yagop/node-telegram-bot-api/tree/master/examples).
* * *
## Class: TelegramBot
NodeJS class for Telegram Bot API.
## TelegramBot
Support for WebHooks and long polling. Emits `message` when message arrives.
Both request method to obtain messages are implemented. To use standard polling, set `polling: true`
on `options`. Notice that [webHook](https://core.telegram.org/bots/api#setwebhook) will need a valid (not self signed) SSL certificate.
Emmits `message` when a message arrives.
### TelegramBot.getMe()
See: https://core.telegram.org/bots/api
### Params:
* **String** *token* Bot Token
* **Object** *[options]*
* **Boolean|Object** *[options.polling=false]* Set true to enable polling
* **String|Number** *[options.polling.timeout=4]* Polling time
* **Boolean|Object** *[options.webHook=false]* Set true to enable WebHook
* **String** *[options.webHook.key]* PEM private key to webHook server
* **String** *[options.webHook.cert]* PEM certificate key to webHook server
## getMe()
Returns basic information about the bot in form of a `User` object.
**Returns**: `Promise`
### Return:
### TelegramBot.setWebHook(url)
* **Promise**
## setWebHook(url)
Specify a url to receive incoming updates via an outgoing webHook.
**Parameters**
### Params:
**url**: `String`, URL
* **String** *url* URL
## getUpdates([timeout], [limit], [offset])
### TelegramBot.getUpdates(timeout, limit, offset)
Use this method to receive incoming updates using long polling
**Parameters**
See: https://core.telegram.org/bots/api#getupdates
**timeout**: `Number | String`, Timeout in seconds for long polling.
### Params:
**limit**: `Number | String`, Limits the number of updates to be retrieved.
* **Number|String** *[timeout]* Timeout in seconds for long polling.
* **Number|String** *[limit]* Limits the number of updates to be retrieved.
* **Number|String** *[offset]* Identifier of the first update to be returned.
**offset**: `Number | String`, Identifier of the first update to be returned.
### Return:
**Returns**: `Promise`, Updates
* **Promise** Updates
### TelegramBot.sendMessage(chatId, text, options)
## sendMessage(chatId, text, [options])
Send text message.
**Parameters**
See: https://core.telegram.org/bots/api#sendmessage
**chatId**: `Number | String`, Unique identifier for the message recipient
### Params:
**text**: `Sting`, Text of the message to be sent
* **Number|String** *chatId* Unique identifier for the message recipient
* **Sting** *text* Text of the message to be sent
* **Object** *[options]* Additional Telegram query options
**options**: `Object`, Additional Telegram query options
### Return:
**Returns**: `Promise`
* **Promise**
### TelegramBot.forwardMessage(chatId, fromChatId, messageId)
## forwardMessage(chatId, fromChatId, messageId)
Forward messages of any kind.
**Parameters**
### Params:
**chatId**: `Number | String`, Unique identifier for the message recipient
* **Number|String** *chatId* Unique identifier for the message recipient
* **Number|String** *fromChatId* Unique identifier for the chat where the original message was sent
* **Number|String** *messageId* Unique message identifier
**fromChatId**: `Number | String`, Unique identifier for the chat where the
original message was sent
### Return:
**messageId**: `Number | String`, Unique message identifier
* **Promise**
**Returns**: `Promise`
## sendPhoto(chatId, photo, [options])
### TelegramBot.sendPhoto(chatId, photo, options)
Send photo
**Parameters**
See: https://core.telegram.org/bots/api#sendphoto
**chatId**: `Number | String`, Unique identifier for the message recipient
### Params:
**photo**: `String | stream.Stream`, A file path or a Stream. Can
also be a `file_id` previously uploaded
* **Number|String** *chatId* Unique identifier for the message recipient
* **String|stream.Stream** *photo* A file path or a Stream. Can also be a `file_id` previously uploaded
* **Object** *[options]* Additional Telegram query options
**options**: `Object`, Additional Telegram query options
### Return:
**Returns**: `Promise`
* **Promise**
### TelegramBot.sendAudio(chatId, audio, options)
## sendAudio(chatId, audio, [options])
Send audio
**Parameters**
See: https://core.telegram.org/bots/api#sendaudio
**chatId**: `Number | String`, Unique identifier for the message recipient
### Params:
**audio**: `String | stream.Stream`, A file path or a Stream. Can
also be a `file_id` previously uploaded.
* **Number|String** *chatId* Unique identifier for the message recipient
* **String|stream.Stream** *audio* A file path or a Stream. Can also be a `file_id` previously uploaded.
* **Object** *[options]* Additional Telegram query options
**options**: `Object`, Additional Telegram query options
### Return:
**Returns**: `Promise`
* * *
* **Promise**

@@ -16,4 +16,5 @@ var EventEmitter = require('events').EventEmitter;

/**
* NodeJS class for Telegram Bot API. Support for WebHooks and long polling. Emits `message` when
* message arrives.
* Both request method to obtain messages are implemented. To use standard polling, set `polling: true`
* on `options`. Notice that [webHook](https://core.telegram.org/bots/api#setwebhook) will need a valid (not self signed) SSL certificate.
* Emmits `message` when a message arrives.
*

@@ -47,3 +48,4 @@ * @class TelegramBot

var cert = options.webHook.cert;
this._configureWebHook(port, key, cert);
var host = options.webHook.host;
this._configureWebHook(port, host, key, cert);
}

@@ -54,3 +56,3 @@ };

TelegramBot.prototype._configureWebHook = function (port, key, cert) {
TelegramBot.prototype._configureWebHook = function (port, host, key, cert) {
var protocol = 'HTTP';

@@ -74,3 +76,3 @@ var self = this;

this._webServer.listen(port, function () {
this._webServer.listen(port, host, function () {
console.log(protocol+" WebHook listening on:", port);

@@ -82,3 +84,3 @@ });

var self = this;
if (req.url == '/bot' && req.method == 'POST') {
if (req.url === '/bot' && req.method === 'POST') {
var fullBody = '';

@@ -131,3 +133,3 @@ req.on('data', function (chunk) {

.then(function (resp) {
if (resp[0].statusCode != 200) {
if (resp[0].statusCode !== 200) {
throw new Error(resp[0].statusCode+' '+resp[0].body);

@@ -160,3 +162,3 @@ }

var qs = {url: url};
return this._request(path, {method: 'POST', qs: qs})
return this._request(path, {qs: qs})
.then(function (resp) {

@@ -163,0 +165,0 @@ if (!resp) {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc