Socket
Socket
Sign inDemoInstall

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.4.0 to 0.5.0

examples/openShiftWebHook.js

4

examples/httpsWebHook.js

@@ -11,3 +11,3 @@ var TelegramBot = require('../src/telegram');

var bot = new TelegramBot('BOTTOKEN', options);
bot.setWebHook('IP:PORT');
var bot = new TelegramBot('BOT_TOKEN', options);
bot.setWebHook('IP:PORT/botBOT_TOKEN');

@@ -33,7 +33,9 @@

Specify a url to receive incoming updates via an outgoing webHook.
Specify an url to receive incoming updates via an outgoing webHook.
See: https://core.telegram.org/bots/api#setwebhook
### Params:
* **String** *url* URL
* **String** *url* URL where Telegram will make HTTP Post. Leave empty to delete webHook.

@@ -118,3 +120,38 @@ ## getUpdates([timeout], [limit], [offset])

## sendDocument(chatId, A, [options])
Send Document
See: https://core.telegram.org/bots/api#sendDocument
### Params:
* **Number|String** *chatId* Unique identifier for the message recipient
* **String|stream.Stream** *A* file path or a Stream. Can also be a `file_id` previously uploaded.
* **Object** *[options]* Additional Telegram query options
### Return:
* **Promise**
## sendChatAction(chatId, action)
Send chat action.
`typing` for text messages,
`upload_photo` for photos, `record_video` or `upload_video` for videos,
`record_audio` or `upload_audio` for audio files, `upload_document` for general files,
`find_location` for location data.
See: https://core.telegram.org/bots/api#sendchataction
### Params:
* **Number|String** *chatId* Unique identifier for the message recipient
* **String** *action* Type of action to broadcast.
### Return:
* **Promise**
<!-- End src/telegram.js -->
{
"name": "node-telegram-bot-api",
"version": "0.4.0",
"version": "0.5.0",
"description": "Telegram Bot API",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -55,7 +55,9 @@ [![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)

Specify a url to receive incoming updates via an outgoing webHook.
Specify an url to receive incoming updates via an outgoing webHook.
See: https://core.telegram.org/bots/api#setwebhook
### Params:
* **String** *url* URL
* **String** *url* URL where Telegram will make HTTP Post. Leave empty to delete webHook.

@@ -139,1 +141,36 @@ ## getUpdates([timeout], [limit], [offset])

* **Promise**
## sendDocument(chatId, A, [options])
Send Document
See: https://core.telegram.org/bots/api#sendDocument
### Params:
* **Number|String** *chatId* Unique identifier for the message recipient
* **String|stream.Stream** *A* file path or a Stream. Can also be a `file_id` previously uploaded.
* **Object** *[options]* Additional Telegram query options
### Return:
* **Promise**
## sendChatAction(chatId, action)
Send chat action.
`typing` for text messages,
`upload_photo` for photos, `record_video` or `upload_video` for videos,
`record_audio` or `upload_audio` for audio files, `upload_document` for general files,
`find_location` for location data.
See: https://core.telegram.org/bots/api#sendchataction
### Params:
* **Number|String** *chatId* Unique identifier for the message recipient
* **String** *action* Type of action to broadcast.
### Return:
* **Promise**

@@ -145,2 +145,3 @@ var EventEmitter = require('events').EventEmitter;

* @return {Promise}
* @see
*/

@@ -153,4 +154,6 @@ TelegramBot.prototype.getMe = function () {

/**
* Specify a url to receive incoming updates via an outgoing webHook.
* @param {String} url URL
* Specify an url to receive incoming updates via an outgoing webHook.
* @param {String} url URL where Telegram will make HTTP Post. Leave empty to
* delete webHook.
* @see https://core.telegram.org/bots/api#setwebhook
*/

@@ -165,2 +168,3 @@ TelegramBot.prototype.setWebHook = function (url) {

}
return resp;
});

@@ -297,2 +301,42 @@ };

/**
* Send Document
* @param {Number|String} chatId Unique identifier for the message recipient
* @param {String|stream.Stream} A file path or a Stream. Can
* also be a `file_id` previously uploaded.
* @param {Object} [options] Additional Telegram query options
* @return {Promise}
* @see https://core.telegram.org/bots/api#sendDocument
*/
TelegramBot.prototype.sendDocument = function (chatId, doc, options) {
var opts = {
qs: options || {}
};
opts.qs.chat_id = chatId;
var content = this._formatSendData('document', doc);
opts.formData = content[0];
opts.qs.document = content[1];
return this._request('sendDocument', opts);
};
/**
* Send chat action.
* `typing` for text messages,
* `upload_photo` for photos, `record_video` or `upload_video` for videos,
* `record_audio` or `upload_audio` for audio files, `upload_document` for general files,
* `find_location` for location data.
*
* @param {Number|String} chatId Unique identifier for the message recipient
* @param {String} action Type of action to broadcast.
* @return {Promise}
* @see https://core.telegram.org/bots/api#sendchataction
*/
TelegramBot.prototype.sendChatAction = function (chatId, action) {
var query = {
chat_id: chatId,
action: action
};
return this._request('sendChatAction', {qs: query});
};
module.exports = TelegramBot;

@@ -1,2 +0,2 @@

var Telegram = require('../src/telegram');
var Telegram = require('../index');
var request = require('request');

@@ -6,2 +6,3 @@ var should = require('should');

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
var TOKEN = process.env.TEST_TELEGRAM_TOKEN;

@@ -16,2 +17,20 @@ if (!TOKEN) {

describe('#setWebHook', function () {
it('should set a webHook', function (done) {
var bot = new Telegram(TOKEN);
bot.setWebHook('216.58.210.174').then(function (resp) {
resp.should.be.exactly(true);
done();
});
});
it('should delete the webHook', function (done) {
var bot = new Telegram(TOKEN);
bot.setWebHook('').then(function (resp) {
resp.should.be.exactly(true);
done();
});
});
});
describe('#emit', function () {

@@ -35,9 +54,9 @@ it('should emit a `message` on polling', function (done) {

it('should emit a `message` on WebHook', function (done) {
it('should emit a `message` on HTTP WebHook', function (done) {
var bot = new Telegram(TOKEN, {webHook: true});
bot.on('message', function (msg) {
msg.should.be.an.instanceOf(Object);
bot._webServer.close();
done();
});
var url = 'http://localhost:8443/bot';
var url = 'http://localhost:8443/bot'+TOKEN;
request({

@@ -53,2 +72,28 @@ url: url,

});
it('should emit a `message` on HTTPS WebHook', function (done) {
var opts = {
webHook: {
port: 8443,
key: __dirname+'/../examples/key.pem',
cert: __dirname+'/../examples/crt.pem'
}
};
var bot = new Telegram(TOKEN, opts);
bot.on('message', function (msg) {
bot._webServer.close();
done();
});
var url = 'https://localhost:8443/bot'+TOKEN;
request({
url: url,
method: 'POST',
json: true,
headers: {
"content-type": "application/json",
},
rejectUnhauthorized: false,
body: {update_id: 0, message: {text: 'test'}}
});
});
});

@@ -141,2 +186,13 @@

describe('#sendChatAction', function () {
it('should send a chat action', function (done) {
var bot = new Telegram(TOKEN);
var action = "typing";
bot.sendChatAction(USERID, action).then(function (resp) {
resp.should.be.exactly(true);
done();
});
});
});
describe('#sendAudio', function () {

@@ -153,2 +209,45 @@ it('should send an OGG audio', function (done) {

});
describe('#sendDocument', function () {
var documentId;
it('should send a document from file', function (done) {
var bot = new Telegram(TOKEN);
var document = __dirname+'/bot.gif';
bot.sendDocument(USERID, document).then(function (resp) {
resp.should.be.an.instanceOf(Object);
documentId = resp.document.file_id;
done();
});
});
it('should send a document from id', function (done) {
var bot = new Telegram(TOKEN);
// Send the same photo as before
var document = documentId;
bot.sendDocument(USERID, document).then(function (resp) {
resp.should.be.an.instanceOf(Object);
done();
});
});
it('should send a document from fs.readStream', function (done) {
var bot = new Telegram(TOKEN);
var document = fs.createReadStream(__dirname+'/bot.gif');
bot.sendDocument(USERID, document).then(function (resp) {
resp.should.be.an.instanceOf(Object);
done();
});
});
it('should send a document from request Stream', function (done) {
var bot = new Telegram(TOKEN);
var document = request('https://telegram.org/img/t_logo.png');
bot.sendDocument(USERID, document).then(function (resp) {
resp.should.be.an.instanceOf(Object);
done();
});
});
});

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