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.23.3 to 0.24.0

196

lib/telegram.js

@@ -91,3 +91,18 @@ 'use strict';

}
/**
* Stops polling after the last polling request resolves
*
* @return {Promise} promise Promise, of last polling request
*/
}, {
key: 'stopPolling',
value: function stopPolling() {
if (this._polling) {
return this._polling.stopPolling();
}
return Promise.resolve();
}
}, {
key: 'processUpdate',

@@ -99,2 +114,3 @@ value: function processUpdate(update) {

var message = update.message;
var editedMessage = update.edited_message;
var inlineQuery = update.inline_query;

@@ -138,2 +154,11 @@ var chosenInlineResult = update.chosen_inline_result;

}
} else if (editedMessage) {
debug('Process Update edited_message %j', editedMessage);
this.emit('edited_message', editedMessage);
if (editedMessage.text) {
this.emit('edited_message_text', editedMessage);
}
if (editedMessage.caption) {
this.emit('edited_message_caption', editedMessage);
}
} else if (inlineQuery) {

@@ -162,2 +187,11 @@ debug('Process Update inline_query %j', inlineQuery);

}
}, {
key: '_fixReplyMarkup',
value: function _fixReplyMarkup(obj) {
var replyMarkup = obj.reply_markup;
if (replyMarkup && typeof replyMarkup !== 'string') {
// reply_markup must be passed as JSON stringified to Telegram
obj.reply_markup = JSON.stringify(replyMarkup);
}
}

@@ -178,8 +212,7 @@ // request-promise

if (options.form) {
var replyMarkup = options.form.reply_markup;
if (replyMarkup && typeof replyMarkup !== 'string') {
// reply_markup must be passed as JSON stringified to Telegram
options.form.reply_markup = JSON.stringify(replyMarkup);
}
this._fixReplyMarkup(options.form);
}
if (options.qs) {
this._fixReplyMarkup(options.qs);
}
options.url = this._buildURL(_path);

@@ -355,3 +388,3 @@ options.simple = false;

if (data instanceof stream.Stream) {
fileName = URL.parse(path.basename(data.path)).pathname;
fileName = URL.parse(path.basename(data.path.toString())).pathname;
formData = {};

@@ -676,3 +709,3 @@ formData[type] = {

* @return {Promise}
* @see https://core.telegram.org/bots/api#editmessagetext
* @see https://core.telegram.org/bots/api#editmessagecaption
*/

@@ -758,2 +791,29 @@

/**
* Send venue.
* Use this method to send information about a venue.
*
* @param {Number|String} chatId Unique identifier for the message recipient
* @param {Float} latitude Latitude of location
* @param {Float} longitude Longitude of location
* @param {String} title Name of the venue
* @param {String} address Address of the venue
* @param {Object} [options] Additional Telegram query options
* @return {Promise}
* @see https://core.telegram.org/bots/api#sendvenue
*/
}, {
key: 'sendVenue',
value: function sendVenue(chatId, latitude, longitude, title, address) {
var form = arguments.length <= 5 || arguments[5] === undefined ? {} : arguments[5];
form.chat_id = chatId;
form.latitude = latitude;
form.longitude = longitude;
form.title = title;
form.address = address;
return this._request('sendVenue', { form: form });
}
/**
* Get file.

@@ -856,2 +916,124 @@ * Use this method to get basic info about a file and prepare it for downloading.

}
/**
* Use this method to get up to date information about the chat
* (current name of the user for one-on-one conversations, current
* username of a user, group or channel, etc.).
* @param {Number|String} chatId Unique identifier for the target chat or username of the target supergroup or channel
* @return {Promise}
* @see https://core.telegram.org/bots/api#getchat
*/
}, {
key: 'getChat',
value: function getChat(chatId) {
var form = {
chat_id: chatId
};
return this._request('getChat', { form: form });
}
/**
* Returns the administrators in a chat in form of an Array of `ChatMember` objects.
* @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup
* @return {Promise}
* @see https://core.telegram.org/bots/api#getchatadministrators
*/
}, {
key: 'getChatAdministrators',
value: function getChatAdministrators(chatId) {
var form = {
chat_id: chatId
};
return this._request('getChatAdministrators', { form: form });
}
/**
* Use this method to get the number of members in a chat.
* @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup
* @return {Promise}
* @see https://core.telegram.org/bots/api#getchatmemberscount
*/
}, {
key: 'getChatMembersCount',
value: function getChatMembersCount(chatId) {
var form = {
chat_id: chatId
};
return this._request('getChatMembersCount', { form: form });
}
/**
* Use this method to get information about a member of a chat.
* @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup
* @param {String} userId Unique identifier of the target user
* @return {Promise}
* @see https://core.telegram.org/bots/api#getchatmember
*/
}, {
key: 'getChatMember',
value: function getChatMember(chatId, userId) {
var form = {
chat_id: chatId,
user_id: userId
};
return this._request('getChatMember', { form: form });
}
/**
* Leave a group, supergroup or channel.
* @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername)
* @return {Promise}
* @see https://core.telegram.org/bots/api#leavechat
*/
}, {
key: 'leaveChat',
value: function leaveChat(chatId) {
var form = {
chat_id: chatId
};
return this._request('leaveChat', { form: form });
}
/**
* Use this method to send a game.
* @param {Number|String} chatId Unique identifier for the message recipient
* @param {String} gameShortName name of the game to be sent.
* @param {Object} [options] Additional Telegram query options
* @return {Promise}
* @see https://core.telegram.org/bots/api#sendgame
*/
}, {
key: 'sendGame',
value: function sendGame(chatId, gameShortName) {
var form = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
form.chat_id = chatId;
form.game_short_name = gameShortName;
return this._request('sendGame', { form: form });
}
/**
* Use this method to set the score of the specified user in a game.
* @param {String} userId Unique identifier of the target user
* @param {Number} score New score value.
* @param {Object} [options] Additional Telegram query options
* @return {Promise}
* @see https://core.telegram.org/bots/api#setgamescore
*/
}, {
key: 'setGameScore',
value: function setGameScore(userId, score) {
var form = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
form.user_id = userId;
form.score = score;
return this._request('setGameScore', { form: form });
}
}]);

@@ -858,0 +1040,0 @@

@@ -42,2 +42,9 @@ 'use strict';

_createClass(TelegramBotPolling, [{
key: 'stopPolling',
value: function stopPolling() {
this.abort = true;
// wait until the last request is fulfilled
return this.lastRequest;
}
}, {
key: '_polling',

@@ -44,0 +51,0 @@ value: function _polling() {

15

package.json
{
"name": "node-telegram-bot-api",
"version": "0.23.3",
"version": "0.24.0",
"description": "Telegram Bot API",

@@ -17,7 +17,7 @@ "main": "./lib/telegram.js",

"scripts": {
"prepublish": "./node_modules/.bin/babel -d ./lib src",
"test": "./node_modules/.bin/mocha test/index.js --timeout 10000",
"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",
"gen-doc": "./node_modules/.bin/jsdoc2md --src src/telegram.js -t README.hbs > README.md",
"eslint": "./node_modules/.bin/eslint ./src"
"prepublish": "babel -d ./lib src",
"test": "istanbul cover ./node_modules/mocha/bin/_mocha -- -R spec --timeout 10000",
"prepublish:test": "npm run prepublish && npm run test",
"gen-doc": "jsdoc2md --src src/telegram.js -t README.hbs > README.md",
"eslint": "eslint ./src"
},

@@ -50,3 +50,2 @@ "author": "Yago Pérez <yagoperezs@gmail.com>",

"contributor": "^0.1.25",
"coveralls": "^2.11.8",
"eslint": "^2.11.1",

@@ -56,3 +55,3 @@ "eslint-config-airbnb": "^6.1.0",

"is": "^3.1.0",
"istanbul": "^0.4.2",
"istanbul": "^1.1.0-alpha.1",
"jsdoc-to-markdown": "^1.3.3",

@@ -59,0 +58,0 @@ "mocha": "^2.4.5",

@@ -36,3 +36,5 @@ [![Build Status](https://travis-ci.org/yagop/node-telegram-bot-api.svg?branch=master)](https://travis-ci.org/yagop/node-telegram-bot-api) [![Build status](https://ci.appveyor.com/api/projects/status/ujko6bsum3g5msjh/branch/master?svg=true)](https://ci.appveyor.com/project/yagop/node-telegram-bot-api/branch/master) [![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) [![bitHound Score](https://www.bithound.io/github/yagop/node-telegram-bot-api/badges/score.svg)](https://www.bithound.io/github/yagop/node-telegram-bot-api) [![https://telegram.me/node_telegram_bot_api](https://img.shields.io/badge/💬 Telegram-node__telegram__bot__api-blue.svg)](https://telegram.me/node_telegram_bot_api) [![https://telegram.me/Yago_Perez](https://img.shields.io/badge/💬 Telegram-Yago__Perez-blue.svg)](https://telegram.me/Yago_Perez)

Every time TelegramBot receives a message, it emits a `message`. Depending on which [message](https://core.telegram.org/bots/api#message) was received, emits an event from this ones: `text`, `audio`, `document`, `photo`, `sticker`, `video`, `voice`, `contact`, `location`, `new_chat_participant`, `left_chat_participant`, `new_chat_title`, `new_chat_photo`, `delete_chat_photo`, `group_chat_created`. Its much better to listen a specific event rather than a `message` in order to stay safe from the content.
TelegramBot emits `callback_query` when receives a [Callback Query](https://core.telegram.org/bots/api#callbackquery).
TelegramBot emits `inline_query` when receives an [Inline Query](https://core.telegram.org/bots/api#inlinequery) and `chosen_inline_result` when receives a [ChosenInlineResult](https://core.telegram.org/bots/api#choseninlineresult). Bot must be enabled on [inline mode](https://core.telegram.org/bots/api#inline-mode)
TelegramBot emits `edited_message` when a message is edited, and also `edited_message_text` or `edited_message_caption` depending on which type of message was edited.
* * *

@@ -62,2 +64,3 @@

* [new TelegramBot(token, [options])](#new_TelegramBot_new)
* [.stopPolling()](#TelegramBot+stopPolling) ⇒ <code>Promise</code>
* [.getMe()](#TelegramBot+getMe) ⇒ <code>Promise</code>

@@ -84,2 +87,3 @@ * [.setWebHook(url, [cert])](#TelegramBot+setWebHook)

* [.sendLocation(chatId, latitude, longitude, [options])](#TelegramBot+sendLocation) ⇒ <code>Promise</code>
* [.sendVenue(chatId, latitude, longitude, title, address, [options])](#TelegramBot+sendVenue) ⇒ <code>Promise</code>
* [.getFile(fileId)](#TelegramBot+getFile) ⇒ <code>Promise</code>

@@ -90,2 +94,9 @@ * [.getFileLink(fileId)](#TelegramBot+getFileLink) ⇒ <code>Promise</code>

* [.onReplyToMessage(chatId, messageId, callback)](#TelegramBot+onReplyToMessage)
* [.getChat(chatId)](#TelegramBot+getChat) ⇒ <code>Promise</code>
* [.getChatAdministrators(chatId)](#TelegramBot+getChatAdministrators) ⇒ <code>Promise</code>
* [.getChatMembersCount(chatId)](#TelegramBot+getChatMembersCount) ⇒ <code>Promise</code>
* [.getChatMember(chatId, userId)](#TelegramBot+getChatMember) ⇒ <code>Promise</code>
* [.leaveChat(chatId)](#TelegramBot+leaveChat) ⇒ <code>Promise</code>
* [.sendGame(chatId, gameShortName, [options])](#TelegramBot+sendGame) ⇒ <code>Promise</code>
* [.setGameScore(userId, score, [options])](#TelegramBot+setGameScore) ⇒ <code>Promise</code>

@@ -111,2 +122,9 @@ <a name="new_TelegramBot_new"></a>

<a name="TelegramBot+stopPolling"></a>
### telegramBot.stopPolling() ⇒ <code>Promise</code>
Stops polling after the last polling request resolves
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**Returns**: <code>Promise</code> - promise Promise, of last polling request
<a name="TelegramBot+getMe"></a>

@@ -370,3 +388,3 @@

**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#editmessagetext
**See**: https://core.telegram.org/bots/api#editmessagecaption

@@ -427,2 +445,20 @@ | Param | Type | Description |

<a name="TelegramBot+sendVenue"></a>
### telegramBot.sendVenue(chatId, latitude, longitude, title, address, [options]) ⇒ <code>Promise</code>
Send venue.
Use this method to send information about a venue.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#sendvenue
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the message recipient |
| latitude | <code>Float</code> | Latitude of location |
| longitude | <code>Float</code> | Longitude of location |
| title | <code>String</code> | Name of the venue |
| address | <code>String</code> | Address of the venue |
| [options] | <code>Object</code> | Additional Telegram query options |
<a name="TelegramBot+getFile"></a>

@@ -499,2 +535,93 @@

<a name="TelegramBot+getChat"></a>
### telegramBot.getChat(chatId) ⇒ <code>Promise</code>
Use this method to get up to date information about the chat
(current name of the user for one-on-one conversations, current
username of a user, group or channel, etc.).
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#getchat
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the target chat or username of the target supergroup or channel (in the format @channelusername) |
<a name="TelegramBot+getChatAdministrators"></a>
### telegramBot.getChatAdministrators(chatId) ⇒ <code>Promise</code>
Returns the administrators in a chat in form of an Array of `ChatMember` objects.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#getchatadministrators
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the target group or username of the target supergroup |
<a name="TelegramBot+getChatMembersCount"></a>
### telegramBot.getChatMembersCount(chatId) ⇒ <code>Promise</code>
Use this method to get the number of members in a chat.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#getchatmemberscount
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the target group or username of the target supergroup |
<a name="TelegramBot+getChatMember"></a>
### telegramBot.getChatMember(chatId, userId) ⇒ <code>Promise</code>
Use this method to get information about a member of a chat.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#getchatmember
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the target group or username of the target supergroup |
| userId | <code>String</code> | Unique identifier of the target user |
<a name="TelegramBot+leaveChat"></a>
### telegramBot.leaveChat(chatId) ⇒ <code>Promise</code>
Leave a group, supergroup or channel.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#leavechat
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername) |
<a name="TelegramBot+sendGame"></a>
### telegramBot.sendGame(chatId, gameShortName, [options]) ⇒ <code>Promise</code>
Use this method to send a game.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#sendgame
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the message recipient |
| gameShortName | <code>String</code> | name of the game to be sent. |
| [options] | <code>Object</code> | Additional Telegram query options |
<a name="TelegramBot+setGameScore"></a>
### telegramBot.setGameScore(userId, score, [options]) ⇒ <code>Promise</code>
Use this method to set the score of the specified user in a game.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#setgamescore
| Param | Type | Description |
| --- | --- | --- |
| userId | <code>String</code> | Unique identifier of the target user |
| score | <code>Number</code> | New score value. |
| [options] | <code>Object</code> | Additional Telegram query options |
* * *

Sorry, the diff of this file is not supported yet

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