Node Telegram Bot API return 错误请求:请求中没有照片

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

有人用 Nodejs 写了一个 Telegram 机器人。要向用户发送图像,我使用以下命令:

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);
        });

显示此错误:

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

你能帮帮我吗?

应该是:

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

可能照片的 url 有误,换一张 url 试试,例如: https://upload.wikimedia.org/wikipedia/en/thumb/8/80/Wikipedia-logo-v2.svg/1122px-Wikipedia-logo-v2.svg.png

已解决:

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

如果您想从 url 发送文件:

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