static void Main() { Console.WriteLine("Start!"); var bot = new BotClient("<your bot token>"); // Long POlling var updates = bot.GetUpdates(); while (true) { if (updates.Length > 0) { foreach (var update in updates) { if (update.Type == UpdateType.Message) { var message = update.Message; //bot.SendChatAction(message.Chat.Id, ChatAction.Typing); bot.SendMessage(message.Chat.Id, "Hello World!"); } } updates = bot.GetUpdates(offset: updates.Max(u => u.UpdateId) + 1); } else { updates = bot.GetUpdates(); } } }
static void Main() { Console.WriteLine("Start!"); var bot = new BotClient("<your bot token>"); bot.SetMyCommands(new BotCommand("callback", "new callback")); // Long Polling var updates = bot.GetUpdates(); while (true) { if (updates.Length > 0) { foreach (var update in updates) { switch (update.Type) { case UpdateType.Message: var message = update.Message; if (message.Text.Contains("/callback")) { var replyMarkup = new InlineKeyboardMarkup { InlineKeyboard = new InlineKeyboardButton[][] { new InlineKeyboardButton[] { InlineKeyboardButton.SetCallbackData("Callback", "callback_data") } } }; bot.SendMessage(message.Chat.Id, "Message with callback data", replyMarkup: replyMarkup); } break; case UpdateType.CallbackQuery: var query = update.CallbackQuery; bot.AnswerCallbackQuery(query.Id, "HELLO"); bot.EditMessageText(new EditMessageTextArgs { ChatId = query.Message.Chat.Id, MessageId = query.Message.MessageId, Text = $"Click!\n\n{query.Data}" }); break; } } updates = updates = bot.GetUpdates(offset: updates.Max(u => u.UpdateId) + 1); } else { updates = bot.GetUpdates(); } } }
static void Main() { Console.WriteLine("Start!"); var bot = new BotClient("<your bot token>"); bot.SetMyCommands(new BotCommand("reply", "ReplyMarkup"), new BotCommand("del", "Delete")); // Long Polling var updates = bot.GetUpdates(); while (true) { if (updates.Length > 0) { foreach (var update in updates) { switch (update.Type) { case UpdateType.Message: if (update.Message.Text.Contains("/reply")) { var keyboard = new ReplyKeyboardMarkup { Keyboard = new KeyboardButton[][] { new KeyboardButton[] { new KeyboardButton("Button 1"), //column 1 row 1 new KeyboardButton("Button 2") //column 1 row 2 }, // column 1 new KeyboardButton[] { new KeyboardButton("Button 3") //col 2 row 1 } // column 2 }, ResizeKeyboard = true };; bot.SendMessage(update.Message.Chat.Id, "new keyboard", replyMarkup: keyboard); } if (update.Message.Text.Contains("/del")) { bot.SendMessage(update.Message.Chat.Id, "remove reply keyboard", replyMarkup: new ReplyKeyboardRemove()); } break; } } updates = bot.GetUpdates(offset: updates.Max(u => u.UpdateId) + 1); } else { updates = bot.GetUpdates(); } } }
public List <BaseUpdate> Updates([Required][FromQuery(Name = "UpdateType")] UpdateTypeEnum updateTypeEnum, [Required] long updateOffset) { if (Enum.IsDefined(typeof(UpdateTypeEnum), updateTypeEnum)) { return(_botClient.GetUpdates(updateTypeEnum, updateOffset).ToList()); } return(new List <BaseUpdate>()); }
static void Main() { Console.WriteLine("Start!"); var bot = new BotClient("<BOT TOKEN>"); bot.SetMyCommands(new BotCommand("quiz", "New quiz")); // Long Polling var updates = bot.GetUpdates(); while (true) { if (updates.Length > 0) { foreach (var update in updates) { switch (update.Type) { case UpdateType.Message: if (update.Message.Text.Contains("/quiz")) { bot.SendPoll( new SendPollArgs( update.Message.Chat.Id, "¿5 + 5?", new string[] { "56", "7", "10", "-4" }) { Type = "quiz", CorrectOptionId = 2 }); } break; } } updates = bot.GetUpdates(offset: updates.Max(u => u.UpdateId) + 1); } else { updates = bot.GetUpdates(); } } }