skip to Main Content

I am using this Telegram Bot API for NodeJS https://github.com/yagop/node-telegram-bot-api and there is a method “getUserProfilePhotos”, I used it and got error:

"Bad Request: there is no photo in the request"

Here is my code

var TelegramBot = require('node-telegram-bot-api');
var token = '********************************************';
var bot = new TelegramBot(token, {polling: true});

bot.on('message', function (msg) {
    var chatId = msg.chat.id;
    var userId = msg.from.id;

    bot.sendMessage(chatId,"There is something");   
    bot.sendPhoto(chatId,bot.getUserProfilePhotos(userId, 1, 1) ,{caption: "It's your photo!"});    

});

I have a Profile Photo in my telegram accaunt. I dont know what to do. Can someone help me? Sorry for my eng)

2

Answers


  1. try this, work correctly:

    bot.onText(//testuserphoto$/, function onMessage(msg) {
        var chatId = msg.chat.id;
        var userId = msg.from.id;
    
        bot.getUserProfilePhotos(userId, 0, 1).then(function(data){
          bot.sendPhoto(chatId,data.photos[0][0].file_id,{caption: "It's your photo!"});
        });
    
    });
    

    getUserProfilePhoto returns an UserProfilePhotos with photos attribute containing the list of user profile. Beside getUserProfilePhoto method want as second parameter photo id not photo object.

    Login or Signup to reply.
  2. Arrays Base Index Number is 0

    But you use 1 and 1! in this line:

    bot.sendPhoto(chatId,bot.getUserProfilePhotos(userId, 1, 1) ,{caption: "It's your photo!"});

    Correct it to :
    bot.sendPhoto(chatId,bot.getUserProfilePhotos(userId, 0, 0) ,{caption: "It's your photo!"});

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search