Node-telegram-bot-api: How to send photo?

Created on 15 Jul 2016  路  2Comments  路  Source: yagop/node-telegram-bot-api

I'm using this code for sending photo as stream for the user But it doesn't send the photo:

var request = require('request');
        request.get(res.Poster, function (error, response, body) {
            if (!error && response.statusCode == 200) {
                bot.sendPhoto(msg.chat.id, response, { caption: res.Title });
            }
});

Any idea?

Most helpful comment

Hi, you are not using streams exactly. request return a stream if you do not provide a callback, so the correct way is:

var request = require('request');

var pic_stream = request.get(res.Poster).on('error', function(err) { console.log(err); });

bot.sendPhoto(msg.chat.id, pic_stream, { caption: res.Title }); 

Hope it helps

All 2 comments

Hi, you are not using streams exactly. request return a stream if you do not provide a callback, so the correct way is:

var request = require('request');

var pic_stream = request.get(res.Poster).on('error', function(err) { console.log(err); });

bot.sendPhoto(msg.chat.id, pic_stream, { caption: res.Title }); 

Hope it helps

Thanks to @aabreuglez for providing the solution to this issue.

Was this page helpful?
0 / 5 - 0 ratings