Telegram.Bot icon indicating copy to clipboard operation
Telegram.Bot copied to clipboard

Telegram Bot API 9.0.0-beta2 Inline button exception

Open hanc2006 opened this issue 10 years ago • 4 comments

Hi, i trying the new beta relase for interact with inline buttons but I have some problems:

var iButton = new InlineKeyboardButton();
                            iButton.Text = "ok";
                            var iButtons = new InlineKeyboardButton[][] 
                            { new InlineKeyboardButton[] { iButton }};

                            var keyboardMarkup = new InlineKeyboardMarkup()
                            {
                                InlineKeyboard = iButtons 
                            };
                            var t = await Bot.SendTextMessage(update.Message.Chat.Id,
                           "response", replyMarkup: keyboardMarkup);

Exception: {"[Error : 400 : Bad Request: Can't parse inline keyboard button: Text buttons are unallowed in the inline keyboard]"}

If I don't submit the text I have this exception: {"[Error : 400 : Bad Request: Can't parse inline keyboard button: Can't find field "text"]"}

hanc2006 avatar Apr 29 '16 23:04 hanc2006

Hi,

you need to specify CallbackData, Url, or SwitchInlineQuery. Didn't interpreted the docs correct.

I'll upload a new beta, with some shorthands

MrRoundRobin avatar Apr 30 '16 11:04 MrRoundRobin

Now you can create single now Keyboards:

var keyboard = new InlineKeyboardMarkup(new InlineKeyboardButton[]
    {
        "A",
        "B"
    }
);

or multi row keyboards

var keyboard = new InlineKeyboardMarkup(new []
{
    new InlineKeyboardButton[]
    {
        "A",
        "B"
    },
    new InlineKeyboardButton[]
    {
        "C",
        "D"
    } 
}
);

or with URLs

var keyboard = new InlineKeyboardMarkup(new []
{
    new InlineKeyboardButton[]
    {
        "A",
        "B"
    },
    new InlineKeyboardButton[]
    {
        new InlineKeyboardButton
        {
            Text = "C",
            Url = "https://www.nuget.org/packages/Telegram.Bot/"
        }, 
        "D"
    } 
}
);

MrRoundRobin avatar Apr 30 '16 11:04 MrRoundRobin

Hello Sir,

new InlineKeyboardButton { Text = "C", Url = "https://www.nuget.org/packages/Telegram.Bot/" }

This gives error "InlineKeyboardButton" does not contains constructor that takes 0 arguments... I want two url buttons in a row...

omegalogs4 avatar Jul 11 '17 11:07 omegalogs4

@omegalogs4


new InlineKeyboardButton ("C") 
{
    Url = "https://www.nuget.org/packages/Telegram.Bot/"
}

MrRoundRobin avatar Jul 11 '17 11:07 MrRoundRobin