B. Azizan
B. Azizan

Reputation: 93

Node Telegram Bot API return Bad Request: there is no photo in the request

I was wrote a Telegram bot with Nodejs. To send an image to the user I am using the following commands :

bot.sendPhoto({
            chat_id: msg.chat.id,
            caption: 'Test caption',
            files: {
                photo: '../change-db-shop-url.png'
            }
        }, function (err, msg) {
            console.log(err);
            console.log(msg);
        });

This error displayed :

Unhandled rejection Error: 400 {"ok":false,"error_code":400,"description":"Bad Request: there is no photo in the request"}

Can you help me?

Upvotes: 2

Views: 11144

Answers (4)

Vitaly Domnikov
Vitaly Domnikov

Reputation: 326

If you want to send files from urls:

https://github.com/telegraf/telegraf/blob/develop/api.md#file

Upvotes: 0

B. Azizan
B. Azizan

Reputation: 93

Resolved :

var photo = __dirname+'/../Android.png';
bot.sendPhoto(msg.chat.id, photo, {caption: "I'm a bot!"});

Upvotes: 1

ilbonte
ilbonte

Reputation: 151

Probably the photo's url is wrong, Try with another url e.g. : https://upload.wikimedia.org/wikipedia/en/thumb/8/80/Wikipedia-logo-v2.svg/1122px-Wikipedia-logo-v2.svg.png

Upvotes: 0

michelem
michelem

Reputation: 14590

It should be:

bot.sendPhoto({
  chatId: msg.chat.id,
  caption: 'Test caption',
  photo: '../change-db-shop-url.png'
}, function(err, msg) {
  console.log(err);
  console.log(msg);
});

https://github.com/yagop/node-telegram-bot-api#TelegramBot+sendPhoto

Upvotes: 2

Related Questions