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.24.0 to 0.25.0

CONTRIBUTING.md

120

lib/telegram.js

@@ -55,2 +55,5 @@ 'use strict';

* @param {String} [options.webHook.cert] PEM certificate (public) to webHook server.
* @param {Boolean} [options.onlyFirstMatch=false] Set to true to stop after first match. Otherwise, all regexps are executed
* @param {Object} [options.request] Options which will be added for all requests to telegram api.
* See https://github.com/request/request#requestoptions-callback for more information.
* @see https://core.telegram.org/bots/api

@@ -62,7 +65,7 @@ */

function TelegramBot(token) {
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
_classCallCheck(this, TelegramBot);
var _this = _possibleConstructorReturn(this, Object.getPrototypeOf(TelegramBot).call(this));
var _this = _possibleConstructorReturn(this, (TelegramBot.__proto__ || Object.getPrototypeOf(TelegramBot)).call(this));

@@ -116,2 +119,4 @@ _this.options = options;

var editedMessage = update.edited_message;
var channelPost = update.channel_post;
var editedChannelPost = update.edited_channel_post;
var inlineQuery = update.inline_query;

@@ -133,8 +138,10 @@ var chosenInlineResult = update.chosen_inline_result;

debug('Text message');
this.textRegexpCallbacks.forEach(function (reg) {
debug('Matching %s whith', message.text, reg.regexp);
this.textRegexpCallbacks.some(function (reg) {
debug('Matching %s with %s', message.text, reg.regexp);
var result = reg.regexp.exec(message.text);
if (result) {
debug('Matches', reg.regexp);
debug('Matches %s', reg.regexp);
reg.callback(message, result);
// returning truthy value exits .some
return _this2.options.onlyFirstMatch;
}

@@ -165,2 +172,14 @@ });

}
} else if (channelPost) {
debug('Process Update channel_post %j', channelPost);
this.emit('channel_post', channelPost);
} else if (editedChannelPost) {
debug('Process Update edited_channel_post %j', editedChannelPost);
this.emit('edited_channel_post', editedChannelPost);
if (editedChannelPost.text) {
this.emit('edited_channel_post_text', editedChannelPost);
}
if (editedChannelPost.caption) {
this.emit('edited_channel_post_caption', editedChannelPost);
}
} else if (inlineQuery) {

@@ -206,3 +225,3 @@ debug('Process Update inline_query %j', inlineQuery);

var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

@@ -213,2 +232,6 @@ if (!this.token) {

if (this.options.request) {
Object.assign(options, this.options.request);
}
if (options.form) {

@@ -223,2 +246,3 @@ this._fixReplyMarkup(options.form);

options.resolveWithFullResponse = true;
options.forever = true;
debug('HTTP request: %j', options);

@@ -285,9 +309,7 @@ return request(options).then(function (resp) {

if (cert) {
var _formatSendData2 = this._formatSendData('certificate', cert);
var _formatSendData2 = this._formatSendData('certificate', cert),
_formatSendData3 = _slicedToArray(_formatSendData2, 2),
formData = _formatSendData3[0],
certificate = _formatSendData3[1];
var _formatSendData3 = _slicedToArray(_formatSendData2, 2);
var formData = _formatSendData3[0];
var certificate = _formatSendData3[1];
opts.formData = formData;

@@ -339,3 +361,3 @@ opts.qs.certificate = certificate;

value: function sendMessage(chatId, text) {
var form = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
var form = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

@@ -359,3 +381,3 @@ form.chat_id = chatId;

value: function answerInlineQuery(inlineQueryId, results) {
var form = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
var form = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

@@ -445,3 +467,3 @@ form.inline_query_id = inlineQueryId;

value: function sendPhoto(chatId, photo) {
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

@@ -471,3 +493,3 @@ var opts = {

value: function sendAudio(chatId, audio) {
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

@@ -498,4 +520,4 @@ var opts = {

value: function sendDocument(chatId, doc) {
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
var fileOpts = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3];
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
var fileOpts = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};

@@ -528,3 +550,3 @@ var opts = {

value: function sendSticker(chatId, sticker) {
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

@@ -554,3 +576,3 @@ var opts = {

value: function sendVideo(chatId, video) {
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

@@ -580,3 +602,3 @@ var opts = {

value: function sendVoice(chatId, voice) {
var options = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

@@ -678,3 +700,3 @@ var opts = {

value: function answerCallbackQuery(callbackQueryId, text, showAlert) {
var form = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3];
var form = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};

@@ -704,3 +726,3 @@ form.callback_query_id = callbackQueryId;

value: function editMessageText(text) {
var form = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var form = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

@@ -728,3 +750,3 @@ form.text = text;

value: function editMessageCaption(caption) {
var form = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var form = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

@@ -752,3 +774,3 @@ form.caption = caption;

value: function editMessageReplyMarkup(replyMarkup) {
var form = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var form = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

@@ -796,3 +818,3 @@ form.reply_markup = replyMarkup;

value: function sendLocation(chatId, latitude, longitude) {
var form = arguments.length <= 3 || arguments[3] === undefined ? {} : arguments[3];
var form = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};

@@ -822,3 +844,3 @@ form.chat_id = chatId;

value: function sendVenue(chatId, latitude, longitude, title, address) {
var form = arguments.length <= 5 || arguments[5] === undefined ? {} : arguments[5];
var form = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : {};

@@ -834,2 +856,25 @@ form.chat_id = chatId;

/**
* Send contact.
* Use this method to send phone contacts.
*
* @param {Number|String} chatId Unique identifier for the message recipient
* @param {String} phoneNumber Contact's phone number
* @param {String} firstName Contact's first name
* @param {Object} [options] Additional Telegram query options
* @return {Promise}
* @see https://core.telegram.org/bots/api#sendcontact
*/
}, {
key: 'sendContact',
value: function sendContact(chatId, phoneNumber, firstName) {
var form = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
form.chat_id = chatId;
form.phone_number = phoneNumber;
form.first_name = firstName;
return this._request('sendContact', { form: form });
}
/**
* Get file.

@@ -1029,3 +1074,3 @@ * Use this method to get basic info about a file and prepare it for downloading.

value: function sendGame(chatId, gameShortName) {
var form = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
var form = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

@@ -1049,3 +1094,3 @@ form.chat_id = chatId;

value: function setGameScore(userId, score) {
var form = arguments.length <= 2 || arguments[2] === undefined ? {} : arguments[2];
var form = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

@@ -1056,2 +1101,19 @@ form.user_id = userId;

}
/**
* Use this method to get data for high score table.
* @param {String} userId Unique identifier of the target user
* @param {Object} [options] Additional Telegram query options
* @return {Promise}
* @see https://core.telegram.org/bots/api#getgamehighscores
*/
}, {
key: 'getGameHighScores',
value: function getGameHighScores(userId) {
var form = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
form.user_id = userId;
return this._request('getGameHighScores', { form: form });
}
}]);

@@ -1058,0 +1120,0 @@

@@ -15,3 +15,3 @@ 'use strict';

function TelegramBotPolling(token) {
var options = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1];
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
var callback = arguments[2];

@@ -18,0 +18,0 @@

@@ -33,3 +33,3 @@ 'use strict';

this._requestListener = function (req, res) {
debug('WebHook request URL:', req.url);
debug('WebHook request URL: %s', req.url);
debug('WebHook request headers: %j', req.headers);

@@ -36,0 +36,0 @@

{
"name": "node-telegram-bot-api",
"version": "0.24.0",
"version": "0.25.0",
"description": "Telegram Bot API",

@@ -34,3 +34,3 @@ "main": "./lib/telegram.js",

"request": "^2.69.0",
"request-promise": "^2.0.1"
"request-promise": "^4.1.1"
},

@@ -37,0 +37,0 @@ "devDependencies": {

@@ -12,19 +12,28 @@ [![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)

// replace the value below with the Telegram token you receive from @BotFather
var token = 'YOUR_TELEGRAM_BOT_TOKEN';
// Setup polling way
var bot = new TelegramBot(token, {polling: true});
// Matches /echo [whatever]
// Create a bot that uses 'polling' to fetch new updates
var bot = new TelegramBot(token, { polling: true });
// Matches "/echo [whatever]"
bot.onText(/\/echo (.+)/, function (msg, match) {
var fromId = msg.from.id;
var resp = match[1];
bot.sendMessage(fromId, resp);
// 'msg' is the received Message from Telegram
// 'match' is the result of executing the regexp above on the text content
// of the message
var chatId = msg.chat.id;
var resp = match[1]; // the captured "whatever"
// send back the matched "whatever" to the chat
bot.sendMessage(chatId, resp);
});
// Any kind of message
// Listen for any kind of message. There are different kinds of
// messages.
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 = 'cats.png';
bot.sendPhoto(chatId, photo, {caption: 'Lovely kittens'});
// send a message to the chat acknowledging receipt of their message
bot.sendMessage(chatId, "Received your message");
});

@@ -38,4 +47,6 @@ ```

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 `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 `channel_post` on a new incoming channel post of any kind.
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.
TelegramBot emits `edited_channel_post` when a channel post is edited, and also `edited_channel_post_text` or `edited_channel_post_caption` depending on which type of channel post was edited.
* * *

@@ -88,2 +99,3 @@

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

@@ -101,2 +113,3 @@ * [.getFileLink(fileId)](#TelegramBot+getFileLink) ⇒ <code>Promise</code>

* [.setGameScore(userId, score, [options])](#TelegramBot+setGameScore) ⇒ <code>Promise</code>
* [.getGameHighScores(userId, [options])](#TelegramBot+getGameHighScores) ⇒ <code>Promise</code>

@@ -121,2 +134,4 @@ <a name="new_TelegramBot_new"></a>

| [options.webHook.cert] | <code>String</code> | | PEM certificate (public) to webHook server. |
| [options.onlyFirstMatch] | <code>Boolean</code> | <code>false</code> | Set to true to stop after first match. Otherwise, all regexps are executed |
| [options.request] | <code>Object</code> | | Options which will be added for all requests to telegram api. See https://github.com/request/request#requestoptions-callback for more information. |

@@ -462,2 +477,18 @@ <a name="TelegramBot+stopPolling"></a>

<a name="TelegramBot+sendContact"></a>
### telegramBot.sendContact(chatId, phoneNumber, firstName, [options]) ⇒ <code>Promise</code>
Send contact.
Use this method to send phone contacts.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#sendcontact
| Param | Type | Description |
| --- | --- | --- |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the message recipient |
| phoneNumber | <code>String</code> | Contact's phone number |
| firstName | <code>String</code> | Contact's first name |
| [options] | <code>Object</code> | Additional Telegram query options |
<a name="TelegramBot+getFile"></a>

@@ -546,3 +577,3 @@

| --- | --- | --- |
| 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) |
| chatId | <code>Number</code> &#124; <code>String</code> | Unique identifier for the target chat or username of the target supergroup or channel |

@@ -626,2 +657,15 @@ <a name="TelegramBot+getChatAdministrators"></a>

<a name="TelegramBot+getGameHighScores"></a>
### telegramBot.getGameHighScores(userId, [options]) ⇒ <code>Promise</code>
Use this method to get data for high score table.
**Kind**: instance method of <code>[TelegramBot](#TelegramBot)</code>
**See**: https://core.telegram.org/bots/api#getgamehighscores
| Param | Type | Description |
| --- | --- | --- |
| userId | <code>String</code> | Unique identifier of the target user |
| [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