How to add Inline button in asp net telegram bot?

好久不见. 提交于 2019-12-14 02:27:47

问题


how can I add inline buttons, cause this code examle doesn't work?

var keyboard = new InlineKeyboardMarkup
            (
                new InlineKeyboardButton[][]
                {
                    // First row
                    new InlineKeyboardButton[] {
                        // First column
                        InlineKeyboardButton("one","callback1"),

                        // Second column
                        InlineKeyboardButton("two","callback2"),
                    },
                }
            );

回答1:


All you need to do is defining the Inline Keyboard first and then use it when you send any kind of message to the user. To define an inline keyboard you should use the code below right inside your Program class:

static InlineKeyboardMarkup myInlineKeyboard;

Then inside your main function, you have to use a code like below:

myInlineKeyboard = new InlineKeyboardMarkup()
{
 InlineKeyboard = new InlineKeyboardButton[][]    
 {
  new InlineKeyboardButton[]                //first row
  {
   new InlineKeyboardButton("option1","CallbackQuery1"),     //first column
   new InlineKeyboardButton("option2","CallbackQuery2")     //second column
  }
 };

Finally in order to see your inline keyboard you should use it when you send a message. For example if your message is a Text Message you could use this code:

await Bot.SendTextMessageAsync(ChatID, "Your_Text", replyMarkup: myInlineKeyboard);

I have used this code with Telegram.Bot API Version 13.0.0-beta-01 and it works very well. But if you want to use the recent version of this API the code for Inline Keyboards is a bit different but very similar to this.



来源:https://stackoverflow.com/questions/51614532/how-to-add-inline-button-in-asp-net-telegram-bot

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!