Telegram Bot API: Server down when use getUserProfilePhotos()

Context

I am using telegraf.js for more than 3 bots which run very well in plenty of groups. Currently one of the bots needs to request for Display Picture of the user who does not have a display picture.

It works very well as expected but unfortunately the bot throws an error and the server goes down

Current Code

// Request for display picture
const requestDP = async  (ctx, next) => {
  const { from, chat } = ctx.message;
  const { can_delete_messages:canDelete } = await deletePermision(ctx);

  let totalDPs = 1;
  totalDPs = await ctx.telegram.getUserProfilePhotos(ctx.message.from.id)
  .then((result) => result.total_count)
  .catch((err) => {
    console.log(err);
  });

  if (totalDPs != 0) return next();

  if ((chat.id === -1001341734527 || chat.id === -1001083711103 ) && canDelete) {
    await ctx.deleteMessage().then((response) => response, ({ response }) => response.ok);

    await ctx.replyWithMarkdown(`[${from.first_name||''} ${from.last_name||''}](tg://user?id=${from.id}), ??????? ?????? ?????????????? ??????? ?????? ??????? ?????????`)
    .then(({ message_id }) => setTimeout(() => ctx.deleteMessage(message_id), 5 * 60 * 1000))
    .catch((err) => console.log("Error in prevencontacts: " + err));
  }
}

module.exports = requestDP;

Failure Information (for bugs)

let totalDPs = 1;
totalDPs = await ctx.telegram.getUserProfilePhotos(ctx.message.from.id)
.then((result) => result.total_count)
.catch((err) => {
  console.log(err);
});

The functions seem to be working well. But unfortunately sometimes they get an error the and server goes down. Error message ????

Error: 400: Bad Request: request for new profile photos has already been sent

It is really hard to refresh the server occasionally :-(
Is there any solution to manage this error ?

Answers:

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.