我正在使用此link (.NET Client for Telegram Bot API)。
这是我的电报bot c#代码(一个控制台应用程序):
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Telegram.Bot;
using Telegram.Bot.Args;
using Telegram.Bot.Types.Enums;
using Telegram.Bot.Types.InlineQueryResults;
using Telegram.Bot.Types.ReplyMarkups;
namespace Dogecoin_Bot
{
public static class Program
{
private static readonly TelegramBotClient Bot = new TelegramBotClient("My api key");
public static void Main(string[] args)
{
var me = Bot.GetMeAsync().Result;
Console.Title = me.Username;
Bot.OnMessage += BotOnMessageReceived;
Bot.OnMessageEdited += BotOnMessageReceived;
Bot.OnCallbackQuery += BotOnCallbackQueryReceived;
Bot.OnReceiveError += BotOnReceiveError;
Bot.StartReceiving(Array.Empty<UpdateType>());
Console.WriteLine($"Start listening for @{me.Username}");
Console.ReadLine();
Bot.StopReceiving();
}
private static async void BotOnMessageReceived(object sender, MessageEventArgs messageEventArgs)
{
var message = messageEventArgs.Message;
if (message == null || message.Type != MessageType.Text) return;
switch (message.Text)
{
case "":
{
break;
}
default:
{
await Bot.SendChatActionAsync(message.Chat.Id, ChatAction.Typing);
var inlineKeyboard = new InlineKeyboardMarkup(new[]
{
new []
{
InlineKeyboardButton.WithCallbackData("Support"),
}
});
await Bot.SendTextMessageAsync(
message.Chat.Id,
"Main Menu",
replyMarkup: inlineKeyboard);
break;
}
}
}
private static async void BotOnCallbackQueryReceived(object sender, CallbackQueryEventArgs callbackQueryEventArgs)
{
var callbackQuery = callbackQueryEventArgs.CallbackQuery;
await Bot.SendTextMessageAsync(
callbackQuery.Message.Chat.Id,
$"Received {callbackQuery.Data}");
}
private static void BotOnReceiveError(object sender, ReceiveErrorEventArgs receiveErrorEventArgs)
{
Console.WriteLine("Received error: {0} — {1}",
receiveErrorEventArgs.ApiRequestException.ErrorCode,
receiveErrorEventArgs.ApiRequestException.Message);
}
}
}
我的支持电报ID为:@Admin_My_Bot_Name
我想在用户单击支持botton时打开它。
我该怎么办?
或者,我如何向用户发送网址并在点击支持按钮时将其打开?
答案 0 :(得分:0)
您可以向按钮添加网址,例如:
var keyboard = new InlineKeyboardMarkup(
InlineKeyboardButton.WithUrl("Talk to me in private", "https://t.me/username"));
await Bot.SendTextMessageAsync(message.Chat, "Smth", replyMarkup: keyboard);