TelegramError: 400: Bad Request: IMAGE_PROCESS_FAILED

62 views Asked by At

I am developing a registration bot with Telegraf.js, but I tried to add recaptcha verification to this bot, but I had a problem, here are my codes

//index.js bot
const { Telegraf, Markup } = require('telegraf');
const bot = new Telegraf('6445333997:AAHRcZDc9PTMC5Z8_M_qdKsGXlfcQ8aXGZc');
const recaptcha = require('recaptcha-validator');
const baglan = require('./baglan');
const bcrypt = require('bcrypt')
const { createHash } = require('crypto');
const axios = require('axios');

const RECAPTCHA_SITE_KEY = 'KEY';
const RECAPTCHA_SECRET_KEY = 'KEY';


bot.command('start', async (ctx) => {
    await ctx.reply('$W1074 Kayıt Sistemine Hoşgeldiniz Nasıl Yardımcı Olabiliriz?');
})

bot.command('hesapolustur', async (ctx) => {
    
    const messageText = ctx.message.text;
   const args = messageText.split(' ').slice(1);
   let params = {};
   const validParams = ['-kullanıcı', '-sifre'];
   
   var kullanım = "\n/hesapolustur -kullanıcı * -sifre *";
   
   if (args.length === 0) {
    await ctx.reply(`Hesap Olusturmak İçin Lütfen \n Şu Parametreleri Kullanın \n ${kullanım}`);
    return;
    }
    

    let hasInvalidparam = false;
   for (let i = 0; i < args.length; i += 2) {
    params[args[i]] = args[i + 1];

    const param = args[i];
    const value = args[i + 1];

    if (!validParams.includes(param)) {
        hasInvalidParam = true;
        break;
    }



    params[param] = value;
    }
   

   for (const param in params) {
    if (!validParams.includes(param)) {
        const errorMessage = `Yanlış Parametre Biçimi `;
        await ctx.reply(errorMessage);
        return; 
    }
    }
   


   console.log(params);
 

   const username = params['-kullanıcı'];
   const password = params['-sifre'];



    
   const captchaKey = ctx.from.id.toString();



 
    const captchaImage = `https://www.google.com/recaptcha/api/siteverify?secret=${RECAPTCHA_SECRET_KEY}&response=${captchaKey}`;

    await ctx.replyWithPhoto({ url: captchaImage }, Markup.inlineKeyboard([
        Markup.button.callback('Complete Verification', `captcha:${captchaKey}`)
    ]));
});

bot.action(/captcha:(.*)/, async (ctx) => {
    const captchaKey = ctx.match[1];

    
    const response = await axios.post('https://www.google.com/recaptcha/api/siteverify', {
        secret: RECAPTCHA_SECRET_KEY,
        response: captchaKey
    });

    if (response.data.success) {
        
        await ctx.reply('Verification successful! Proceed with your action.');
    } else {
       
        await ctx.reply('Verification failed! Please try again.');
    }
});


console.log('bot başlatıldı');

bot.launch();


and of course the api output is here

{
  "success": false,
  "error-codes": [
    "invalid-input-response"
  ]
}

Error output

Unhandled error while processing {
  update_id: 702428123,
  message: {
    message_id: 83,
    from: {
      id: 5466310592,
      is_bot: false,
      first_name: '$',
      username: 'bashhmars',
      language_code: 'en'
    },
    chat: {
      id: 5466310592,
      first_name: '$',
      username: 'bashhmars',
      type: 'private'
    },
    date: 1707488536,
    text: '/hesapolustur -kullanıcı sss21 -sifre hds0606',
    entities: [ [Object] ]
  }
}
/home/mars/tbkayıtbot/node_modules/telegraf/lib/core/network/client.js:302
            throw new error_1.default(data, { method, payload });
                  ^

TelegramError: 400: Bad Request: IMAGE_PROCESS_FAILED
    at Telegram.callApi (/home/mars/tbkayıtbot/node_modules/telegraf/lib/core/network/client.js:302:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async /home/mars/tbkayıtbot/index.js:76:5
    at async execute (/home/mars/tbkayıtbot/node_modules/telegraf/lib/composer.js:501:17)
    at async /home/mars/tbkayıtbot/node_modules/telegraf/lib/composer.js:502:21
    at async execute (/home/mars/tbkayıtbot/node_modules/telegraf/lib/composer.js:501:17)
    at async /home/mars/tbkayıtbot/node_modules/telegraf/lib/composer.js:502:21
    at async execute (/home/mars/tbkayıtbot/node_modules/telegraf/lib/composer.js:501:17)
    at async /home/mars/tbkayıtbot/node_modules/telegraf/lib/composer.js:502:21
    at async execute (/home/mars/tbkayıtbot/node_modules/telegraf/lib/composer.js:501:17) {
  response: {
    ok: false,
    error_code: 400,
    description: 'Bad Request: IMAGE_PROCESS_FAILED'
  },
  on: {
    method: 'sendPhoto',
    payload: {
      chat_id: 5466310592,
      photo: {
        url: 'https://www.google.com/recaptcha/api/siteverify?secret=6Ld5PW0pAAAAACFxG_ZnicZaJu5fGW6CVU6p5rGr&response=5466310592'
      },
      message_thread_id: undefined,
      reply_markup: { inline_keyboard: [ [ [Object] ] ] }
    }
  }
}

Node.js v20.10.0
[nodemon] app crashed - waiting for file changes before starting...


I created an API via Google, it shows my API keys are correct but incorrect, how should I solve it?

Thanks :)

0

There are 0 answers