node-telegram-bot-api
Advanced tools
Comparing version 0.11.1 to 0.12.1
@@ -0,9 +1,13 @@ | ||
// An example for OpenShift platform. | ||
var TelegramBot = require('node-telegram-bot-api'); | ||
var token = 'YOUR_TELEGRAM_BOT_TOKEN'; | ||
// See https://developers.openshift.com/en/node-js-environment-variables.html | ||
var port = process.env.OPENSHIFT_NODEJS_PORT; | ||
var host = process.env.OPENSHIFT_NODEJS_IP; | ||
var domain = process.env.OPENSHIFT_APP_DNS; | ||
var bot = new TelegramBot(token, {webHook: {port: port, host: host}}); | ||
bot.setWebHook('myapp-yagop.rhcloud.com:443/bot'+token); | ||
// OpenShift enroutes :443 request to OPENSHIFT_NODEJS_PORT | ||
bot.setWebHook(domain+':443/bot'+token); | ||
bot.on('message', function (msg) { | ||
@@ -10,0 +14,0 @@ var chatId = msg.chat.id; |
@@ -8,3 +8,3 @@ var TelegramBot = require('../src/telegram'); | ||
var token = 'YOUR_TELEGRAM_BOT_TOKEN'; | ||
var token = process.env.TELEGRAM_BOT_TOKEN || 'YOUR_TELEGRAM_BOT_TOKEN'; | ||
@@ -15,3 +15,3 @@ var bot = new TelegramBot(token, options); | ||
}); | ||
bot.on('message', function (msg) { | ||
bot.on('text', function (msg) { | ||
var chatId = msg.chat.id; | ||
@@ -18,0 +18,0 @@ if (msg.text == '/photo') { |
{ | ||
"name": "node-telegram-bot-api", | ||
"version": "0.11.1", | ||
"version": "0.12.1", | ||
"description": "Telegram Bot API", | ||
@@ -45,20 +45,20 @@ "main": "index.js", | ||
{ | ||
"name": "Ilias Ismanalijev", | ||
"email": "hello@illyism.com", | ||
"url": "https://github.com/Illyism", | ||
"contributions": 7, | ||
"additions": 140, | ||
"deletions": 10, | ||
"hireable": true | ||
}, | ||
{ | ||
"name": "Yago", | ||
"email": "yago@yago.me", | ||
"url": "https://github.com/yagop", | ||
"contributions": 82, | ||
"additions": 1572, | ||
"deletions": 415, | ||
"contributions": 89, | ||
"additions": 1598, | ||
"deletions": 435, | ||
"hireable": true | ||
}, | ||
{ | ||
"name": "Sebastian Troć", | ||
"email": "sebastian.troc@gucman.pl", | ||
"url": "https://github.com/SebastianTroc", | ||
"contributions": 1, | ||
"additions": 1, | ||
"deletions": 1, | ||
"hireable": false | ||
}, | ||
{ | ||
"name": "Riddler", | ||
@@ -73,11 +73,11 @@ "email": "", | ||
{ | ||
"name": "Sebastian Troć", | ||
"email": "sebastian.troc@gucman.pl", | ||
"url": "https://github.com/SebastianTroc", | ||
"contributions": 1, | ||
"additions": 1, | ||
"deletions": 1, | ||
"hireable": false | ||
"name": "Ilias Ismanalijev", | ||
"email": "hello@illyism.com", | ||
"url": "https://github.com/Illyism", | ||
"contributions": 7, | ||
"additions": 140, | ||
"deletions": 10, | ||
"hireable": true | ||
} | ||
] | ||
} |
@@ -15,7 +15,7 @@ [![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) | ||
var bot = new TelegramBot(token, {polling: true}); | ||
bot.on('message', function (msg) { | ||
bot.on('text', 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!"}); | ||
var photo = 'cats.png'; | ||
bot.sendPhoto(chatId, photo, {caption: 'Lovely kittens'}); | ||
}); | ||
@@ -26,2 +26,4 @@ ``` | ||
### Events | ||
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`, `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. | ||
* * * | ||
@@ -36,3 +38,3 @@ | ||
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. | ||
Emits `message` when a message arrives. | ||
@@ -45,5 +47,6 @@ See: https://core.telegram.org/bots/api | ||
* **Object** *[options]* | ||
* **Boolean|Object** *[options.polling=false]* Set true to enable polling | ||
* **Boolean|Object** *[options.polling=false]* Set true to enable polling or set options | ||
* **String|Number** *[options.polling.timeout=4]* Polling time | ||
* **Boolean|Object** *[options.webHook=false]* Set true to enable WebHook | ||
* **String|Number** *[options.polling.interval=2000]* Interval between requests in miliseconds | ||
* **Boolean|Object** *[options.webHook=false]* Set true to enable WebHook or set options | ||
* **String** *[options.webHook.key]* PEM private key to webHook server | ||
@@ -56,2 +59,4 @@ * **String** *[options.webHook.cert]* PEM certificate key to webHook server | ||
See: https://core.telegram.org/bots/api#getme | ||
### Return: | ||
@@ -96,3 +101,3 @@ | ||
* **Number|String** *chatId* Unique identifier for the message recipient | ||
* **Sting** *text* Text of the message to be sent | ||
* **String** *text* Text of the message to be sent | ||
* **Object** *[options]* Additional Telegram query options | ||
@@ -184,3 +189,3 @@ | ||
Send video files, Telegram clients support mp4 videos (other formats may be sent whith `sendDocument`) | ||
Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document). | ||
@@ -187,0 +192,0 @@ See: https://core.telegram.org/bots/api#sendvideo |
@@ -19,3 +19,3 @@ var TelegramBotWebHook = require('./telegramWebHook'); | ||
* 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. | ||
* Emits `message` when a message arrives. | ||
* | ||
@@ -37,2 +37,7 @@ * @class TelegramBot | ||
this.token = token; | ||
this.messageTypes = [ | ||
'text', 'audio', 'document', 'photo', 'sticker', 'video', 'contact', | ||
'location', 'new_chat_participant', 'left_chat_participant', 'new_chat_title', | ||
'new_chat_photo', 'delete_chat_photo', 'group_chat_created' | ||
]; // Telegram message events | ||
@@ -53,6 +58,14 @@ var processUpdate = this._processUpdate.bind(this); | ||
TelegramBot.prototype._processUpdate = function (update) { | ||
debug('Process Update', update); | ||
debug('Process Update message', update.message); | ||
if (update.message) { | ||
this.emit('message', update.message); | ||
debug('Process Update %j', update); | ||
var message = update.message; | ||
debug('Process Update message %j', message); | ||
if (message) { | ||
this.emit('message', message); | ||
var processMessageType = function (messageType) { | ||
if (message[messageType]) { | ||
debug('Emtting %s: %j', messageType, message); | ||
this.emit(messageType, message); | ||
} | ||
}; | ||
this.messageTypes.forEach(processMessageType.bind(this)); | ||
} | ||
@@ -275,3 +288,3 @@ }; | ||
/** | ||
* Send video files, Telegram clients support mp4 videos (other formats may be sent whith `sendDocument`) | ||
* Use this method to send video files, Telegram clients support mp4 videos (other formats may be sent as Document). | ||
* @param {Number|String} chatId Unique identifier for the message recipient | ||
@@ -278,0 +291,0 @@ * @param {String|stream.Stream} A file path or a Stream. Can |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
540472
876
252
10