3

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

BecoZ
  • 109
  • 2
  • 10

3 Answers3

3

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

aminexplo
  • 360
  • 1
  • 13
2

Use InlineKeyboardCallbackButton Example, InlineKeyboardCallbackButton("Yes", "CallBackData") instead of InlineKeyboardButton("Yes", "CallbackData")

0

You couldn't create a new instance of abstraction class. So use sample bellow

 var KeyboardButons = new InlineKeyboardButton[][]
                {
                  new InlineKeyboardButton[]
                  {
                     InlineKeyboardButton.WithCallbackData("سفارش", callbackQueryData) ,
                     InlineKeyboardButton.WithCallbackData("بازگشت", "return")
                  }
                };

                var replyMarkup = new InlineKeyboardMarkup()
                {

                    InlineKeyboard = KeyboardButons
                };