grammyjs / grammY

The Telegram Bot Framework.
https://grammy.dev
MIT License
2.17k stars 110 forks source link

Error BUTTON_TYPE_INVALID when i use inlineKeyboard contain a webapp #535

Closed rust1122 closed 6 months ago

rust1122 commented 6 months ago

i want send a message that inlineboard contain a webapp, grammy get wrong

my code is:

// bot init ... 
const inlineKeyboard = new InlineKeyboard().add(
  InlineKeyboard.webApp('web', 'https://127.0.0.1:5173/')
) 
this.bot.api.sendMessage('chat_id', 'inlineKeyboard', {
  reply_markup: inlineKeyboard
}) // error

when i run code, console said:

return new GrammyError(`Call to '${method}' failed!`, err, method, 
payload);
           ^
GrammyError: Call to 'sendMessage' failed! (400: Bad Request: BUTTON_TYPE_INVALID)

i found there is a api in https://deno.land/x/grammy@v1.21.1/mod.ts?s=InlineKeyboard&p=webApp, how i solve this

KnorpelSenf commented 6 months ago

I cannot reproduce this. The following code works perfectly fine for me:

const bot = new Bot("<token>");
bot.on("message", async (ctx) => {
    await ctx.reply("okay", {
        reply_markup: new InlineKeyboard().add(
            InlineKeyboard.webApp("web", "https://127.0.0.1:5173/"),
        ),
    });
});
bot.start();

You must be doing something else wrong.

rust1122 commented 6 months ago

I cannot reproduce this. The following code works perfectly fine for me:

const bot = new Bot("<token>");
bot.on("message", async (ctx) => {
    await ctx.reply("okay", {
        reply_markup: new InlineKeyboard().add(
            InlineKeyboard.webApp("web", "https://127.0.0.1:5173/"),
        ),
    });
});
bot.start();

You must be doing something else wrong.

yeah i did recive the right menu in this repaly way. but when i try send menu proactive,not in a ctx, like bot.api.sendMessage , it cant work well

rust1122 commented 6 months ago

today when i run code, i found an other error in line GrammyError: Call to 'sendMessage' failed! (400: Bad Request: group chat was upgraded to a supergroup chat), my code is

bot.start();
const inlineKeyboard = new InlineKeyboard().add(
   InlineKeyboard.webApp('web', 'https://127.0.0.1:5173/')
 )
bot.api.sendMessage('id', 'send a menu', {
   reply_markup: inlineKeyboard
 })
KnorpelSenf commented 6 months ago

not in a ctx, like bot.api.sendMessage , it cant work well

It works the exact same way. You probably just try to send the menu to a chat where mini apps are not supported.

today when i run code, i found an other error in line GrammyError: Call to 'sendMessage' failed! (400: Bad Request: group chat was upgraded to a supergroup chat), my code is

bot.start();
const inlineKeyboard = new InlineKeyboard().add(
   InlineKeyboard.webApp('web', 'https://127.0.0.1:5173/')
 )
bot.api.sendMessage('id', 'send a menu', {
   reply_markup: inlineKeyboard
 })

You cannot send messages to that chat anymore. You need to send it to the corresponding supergroup.

rust1122 commented 6 months ago

send the menu to a chat where mini apps are not supported.

sorry but how judge min apps are not supported in a group, i send it to a group chat which are built by myself, and i take the bot in and set it all adminitor rights, but it still faill, there is the debugger info

composer.js:56:9 {
    method: 'sendMessage',
    payload: {
      chat_id: -1002062964288,
      text: 'okay',
      reply_markup: [InlineKeyboard]
    },
    ok: false,
    error_code: 400,
    description: 'Bad Request: BUTTON_TYPE_INVALID',
    parameters: {}
  },
  ctx: Context {
    update: { update_id: 301699273, message: [Object] },
    api: Api { raw: {}, config: [Object] },
    me: {
      id: 6880774341,
      is_bot: true,
      first_name: 'WebTest',
      username: 'WebTestbot',
      can_join_groups: true,
      can_read_all_group_messages: false,
      supports_inline_queries: false
    }
  },
  name: 'BotError'
}

i guss the error is about tg config and setting but i dont kown how config it :(

KnorpelSenf commented 6 months ago

Did you read https://core.telegram.org/bots/api#inlinekeyboardbutton yet? You are not able to send web apps in group chats, ever.

rust1122 commented 6 months ago

Did you read https://core.telegram.org/bots/api#inlinekeyboardbutton yet? You are not able to send web apps in group chats, ever.

sorry i miss this part, i will check the detail in this doc. thx a lot for helping

KnorpelSenf commented 6 months ago

This seems solved, feel free to reopen otherwise