mirror of
https://github.com/yagop/node-telegram-bot-api
synced 2025-08-29 13:27:44 +00:00
sendVideo method
This commit is contained in:
parent
18e5f4fbac
commit
264b554540
@ -335,6 +335,27 @@ TelegramBot.prototype.sendSticker = function (chatId, sticker, options) {
|
||||
return this._request('sendSticker', opts);
|
||||
};
|
||||
|
||||
/**
|
||||
* Send video files, Telegram clients support mp4 videos (other formats may be sent whith `sendDocument`)
|
||||
* @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#sendvideo
|
||||
*/
|
||||
TelegramBot.prototype.sendVideo = function (chatId, video, options) {
|
||||
var opts = {
|
||||
qs: options || {}
|
||||
};
|
||||
opts.qs.chat_id = chatId;
|
||||
var content = this._formatSendData('video', video);
|
||||
opts.formData = content[0];
|
||||
opts.qs.video = content[1];
|
||||
return this._request('sendVideo', opts);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Send chat action.
|
||||
* `typing` for text messages,
|
||||
|
@ -282,4 +282,44 @@ describe('Telegram', function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#sendVideo', function () {
|
||||
var videoId;
|
||||
it('should send a video from file', function (done) {
|
||||
var bot = new Telegram(TOKEN);
|
||||
var video = __dirname+'/video.mp4';
|
||||
bot.sendVideo(USERID, video).then(function (resp) {
|
||||
resp.should.be.an.instanceOf(Object);
|
||||
videoId = resp.video.file_id;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should send a video from id', function (done) {
|
||||
var bot = new Telegram(TOKEN);
|
||||
// Send the same photo as before
|
||||
bot.sendVideo(USERID, videoId).then(function (resp) {
|
||||
resp.should.be.an.instanceOf(Object);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should send a video from fs.readStream', function (done) {
|
||||
var bot = new Telegram(TOKEN);
|
||||
var video = fs.createReadStream(__dirname+'/video.mp4');
|
||||
bot.sendVideo(USERID, video).then(function (resp) {
|
||||
resp.should.be.an.instanceOf(Object);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should send a video from request Stream', function (done) {
|
||||
var bot = new Telegram(TOKEN);
|
||||
var sticker = request('http://techslides.com/demos/sample-videos/small.mp4');
|
||||
bot.sendVideo(USERID, sticker).then(function (resp) {
|
||||
resp.should.be.an.instanceOf(Object);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
BIN
test/video.mp4
Normal file
BIN
test/video.mp4
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user