如何在asp.net电报bot中添加内联按钮? [英] How to add Inline button in asp.net telegram bot?

查看:89
本文介绍了如何在asp.net电报bot中添加内联按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何添加内联按钮,导致此代码示例不起作用?

How can I add inline buttons, cause this code example doesn't work?

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

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

推荐答案

您需要做的就是先定义嵌入式键盘,然后在向用户发送任何类型的消息时使用它.要定义嵌入式键盘,您应该在Program类中使用下面的代码:

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:

private 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, Or Edit message, For example if your message is a Text Message you could use this code:

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

我已将此代码与 Telegram.Bot API版本13.0.0-beta-01结合使用,并且效果很好.但是,如果您想使用该API的最新版本,那么Inline Keyboards的代码就有些不同,但与此非常相似.

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.

这篇关于如何在asp.net电报bot中添加内联按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆