befre
befre

Reputation: 79

Telegram Bot API method (getUserProfilePhotos)

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)

Upvotes: 2

Views: 4995

Answers (2)

PurTahan
PurTahan

Reputation: 1003

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

Upvotes: 1

Luca Motta
Luca Motta

Reputation: 331

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.

Upvotes: 2

Related Questions