简体   繁体   中英

C# Telegram Bot API - How send a link & open it on client

I am using this link (.NET Client for Telegram Bot API) .
Here is my telegram bot c# codes (a console application) :

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);
        }
    }
}

My support telegram id is : @Admin_My_Bot_Name
I want open it when user click on support botton.
How can i do that?
Or how can i send a url to the user & open it when click on support button?

You can add a url to a button, like:

var keyboard = new InlineKeyboardMarkup(
    InlineKeyboardButton.WithUrl("Talk to me in private", "https://t.me/username"));

await Bot.SendTextMessageAsync(message.Chat, "Smth", replyMarkup: keyboard);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM