Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# Cannot create InlineKeyboardButton

I am creating a telegram bot, but I am unable to create any InlineKeyboardButton objects.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Telegram.Bot.Types.InlineKeyboardButtons;

namespace BuildAutomation.Controllers
{
    public class Test
    {
       public TestMethod()
    {
        var none = new InlineKeyboardButton("No", "build|no");
        var yes = "Yes";
        var betaControl = new InlineKeyboardButton(yes, "build|betacontrol");
        var betaNode = new InlineKeyboardButton(yes, "build|betanode");
        var betaBoth = new InlineKeyboardButton(yes, "build|betaboth");

        InlineKeyboardMarkup menu;

        menu = new InlineKeyboardMarkup(new[] { betaBoth, none });
    }
    }
}

I keep getting the error 'Cannot create an instance of the abstract class or interface 'InlineKeyboardButton'. I realize that InlineKeyboardButton is an abstract class, but i see many examples creating an object of InlineKeyboardButton.

Did I miss something?

example 1

example 2

example 3

like image 551
BecoZ Avatar asked Mar 13 '26 06:03

BecoZ


1 Answers

Instantiation of InlineKeyboardButton directly was correct in previous versions. There is a new commit for about one month ago which indicates that InlineKeyboardButton is made abstract from then on. You must use derived classes instead. InlineKeyboardUrlButton, InlineKeyboardPayButton and etc. are all derived from InlineKeyboardButton. It seems that the examples' repository is not updated yet.

Check this link for more details about the mentioned commit: https://github.com/TelegramBots/telegram.bot/commit/ddaa8b74e3ab5eab632dbe2e8916c2fe87b114a3

like image 141
aminexplo Avatar answered Mar 15 '26 20:03

aminexplo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!