using System.Threading.Tasks;
using Telegram.Bot.Types.Enums;
using Telegram.Bot.Types.InlineQueryResults;
using Telegram.Bot.Types.ReplyMarkups;
namespace Telegram.Bot.Examples.Echo
public static class Program
private static readonly TelegramBotClient Bot = new TelegramBotClient("773629992:AAHnBO1-XZ3D24NGtkWeCIqqPX97Pyj-KXo");
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.OnInlineQuery += BotOnInlineQueryReceived;
Bot.OnInlineResultChosen += BotOnChosenInlineResultReceived;
Bot.OnReceiveError += BotOnReceiveError;
Bot.StartReceiving(Array.Empty<UpdateType>());
Console.WriteLine("Start listening for @{me.Username}");
private static async void BotOnMessageReceived(object sender, MessageEventArgs messageEventArgs)
var message = messageEventArgs.Message;
if (message == null || message.Type != MessageType.Text) return;
switch (message.Text.Split(' ').First())
await Bot.SendChatActionAsync(message.Chat.Id, ChatAction.Typing);
var inlineKeyboard = new InlineKeyboardMarkup(new[]
InlineKeyboardButton.WithCallbackData("1.1"),
InlineKeyboardButton.WithCallbackData("1.2"),
InlineKeyboardButton.WithCallbackData("2.1"),
InlineKeyboardButton.WithCallbackData("2.2"),
await Bot.SendTextMessageAsync(
replyMarkup: inlineKeyboard);
ReplyKeyboardMarkup ReplyKeyboard = new[]
await Bot.SendTextMessageAsync(
replyMarkup: ReplyKeyboard);
await Bot.SendChatActionAsync(message.Chat.Id, ChatAction.UploadPhoto);
const string file = @"Files/tux.png";
var fileName = file.Split(Path.DirectorySeparatorChar).Last();
using (var fileStream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read))
await Bot.SendPhotoAsync(
var RequestReplyKeyboard = new ReplyKeyboardMarkup(new[]
KeyboardButton.WithRequestLocation("Location"),
KeyboardButton.WithRequestContact("Contact"),
await Bot.SendTextMessageAsync(
replyMarkup: RequestReplyKeyboard);
/inline - send inline keyboard
/keyboard - send custom keyboard
/request - request location or contact";
await Bot.SendTextMessageAsync(
replyMarkup: new ReplyKeyboardRemove());
private static async void BotOnCallbackQueryReceived(object sender, CallbackQueryEventArgs callbackQueryEventArgs)
var callbackQuery = callbackQueryEventArgs.CallbackQuery;
await Bot.AnswerCallbackQueryAsync(
"Received {callbackQuery.Data}");
await Bot.SendTextMessageAsync(
callbackQuery.Message.Chat.Id,
"Received {callbackQuery.Data}");
private static async void BotOnInlineQueryReceived(object sender, InlineQueryEventArgs inlineQueryEventArgs)
Console.WriteLine("Received inline query from: {inlineQueryEventArgs.InlineQuery.From.Id}");
InlineQueryResultBase[] results = {
new InlineQueryResultLocation(
InputMessageContent = new InputLocationMessageContent(
new InlineQueryResultLocation(
InputMessageContent = new InputLocationMessageContent(
await Bot.AnswerInlineQueryAsync(
inlineQueryEventArgs.InlineQuery.Id,
private static void BotOnChosenInlineResultReceived(object sender, ChosenInlineResultEventArgs chosenInlineResultEventArgs)
Console.WriteLine("Received inline result: {chosenInlineResultEventArgs.ChosenInlineResult.ResultId}");
private static void BotOnReceiveError(object sender, ReceiveErrorEventArgs receiveErrorEventArgs)
Console.WriteLine("Received error: {0} — {1}",
receiveErrorEventArgs.ApiRequestException.ErrorCode,
receiveErrorEventArgs.ApiRequestException.Message);