string Recycle(Update update, int?id, out string reply_markup) { string answer = ""; reply_markup = ""; TelegramRecycle rec = new TelegramRecycle(update, id); string[] _data = update.callback_query.data.Split(); switch (_data[1] ?? "") { case "покупка": rec.AddBuy(_data[2], _data[3]); answer = Shop(_data[2], _data[3], update, id, out reply_markup); break; default: break; } answer = "В корзине" + rec.Count + " шт"; InlineKeyboard keyboard = new InlineKeyboard(); keyboard.AddButton(new InlineKeyboardButton("Назад", "about")); AddMainButtons(keyboard); reply_markup = JsonConvert.SerializeObject(keyboard); return(answer); }
public async Task <IEnumerable <long> > SendMessage(long chatId, OutMessage message) { var result = new List <long>(message.Attachments.Count + 1); GroupAttachments(message.Attachments, out var photos, out var videos, out var others); var photoMediaGroup = photos.Select(TgConverter.ToTgPhoto); var videoMediaGroup = videos.Select(TgConverter.ToTgVideo); if (photos.Count > 0) { result.AddRange((await _api.SendMediaGroupAsync(photoMediaGroup, chatId).ConfigureAwait(false)) .Select(a => (long)a.MessageId)); } if (videos.Count > 0) { result.AddRange((await _api.SendMediaGroupAsync(videoMediaGroup, chatId).ConfigureAwait(false)) .Select(a => (long)a.MessageId)); } foreach (var attachment in others) { switch (attachment.Type) { case AttachmentType.Audio: var sentAudio = await _api.SendAudioAsync(chatId, TgConverter.ToTgMedia(attachment)) .ConfigureAwait(false); result.Add(sentAudio.MessageId); break; case AttachmentType.Voice: var sentVoice = await _api.SendVoiceAsync(chatId, TgConverter.ToTgMedia(attachment)) .ConfigureAwait(false); result.Add(sentVoice.MessageId); break; default: var sendDocument = await _api.SendDocumentAsync(chatId, TgConverter.ToTgMedia(attachment)) .ConfigureAwait(false); result.Add(sendDocument.MessageId); break; } } var keyboard = message.Keyboard switch { InlineKeyboard inlineKeyboard => TgConverter.ToTgKeyboard(inlineKeyboard), ReplyKeyboard replyKeyboard => TgConverter.ToTgKeyboard(replyKeyboard), _ => message.RemoveReplyKeyboard ? new ReplyKeyboardRemove() : null }; var sentMessage = await _api.SendTextMessageAsync(chatId, message.Text, replyMarkup : keyboard) .ConfigureAwait(false); result.Add(sentMessage.MessageId); return(result); }
public async Task <Response <Message> > SendAudioAsync(ChatId chatId, TelegramFile audio, string caption = "", int duration = 0, string performer = "", string title = "", bool disableNotification = false, int replyToMessageId = 0, InlineKeyboard replyMarkup = null) { var markup = ""; if (replyMarkup != null) { markup = replyMarkup.GetJson(); } var url = Address + Token + "/sendAudio"; return(await SendRequest <Response <Message> >(new Dictionary <string, object> { { "chat_id", chatId.Id }, { "voice", audio }, { "caption", caption }, { "performer", performer }, { "title", title }, { "duration", duration }, { "disable_notification", disableNotification }, { "reply_to_message_id", replyToMessageId }, { "reply_markup", markup }, }, url)); }
string MainMenu(Update update, int?id, out string reply_markup) { List <Category> list; string token = ""; int i = 0; using (botEntities3 bd = new botEntities3()) { list = bd.Category.Where(x => x.Token.Id == id).ToList(); token = ReceiveToken(update, id); } InlineKeyboard keyboard = new InlineKeyboard(); foreach (Category k in list) { keyboard.AddButton(new InlineKeyboardButton( k.NameCategory ), i++ / 2); } AddRecycle(keyboard, "", "", update, id); AddMainButtons(keyboard, update, id); reply_markup = JsonConvert.SerializeObject(keyboard); return("Все категории"); }
public async Task <Response <Message> > SendVideoAsync(ChatId chatId, TelegramFile video, int duration = 0, int width = 0, int height = 0, string caption = "", bool disableNotification = false, int replyToMessageId = 0, InlineKeyboard replyMarkup = null) { var markup = ""; if (replyMarkup != null) { markup = replyMarkup.GetJson(); } var url = Address + Token + "/sendVideo"; return(await SendRequest <Response <Message> >(new Dictionary <string, object> { { "chat_id", chatId.Id }, { "video", video }, { "duration", duration }, { "width", width }, { "height", height }, { "caption", caption }, { "disable_notification", disableNotification }, { "reply_to_message_id", replyToMessageId }, { "reply_markup", markup }, }, url)); }
public async Task <Response <Message> > SendVenueAsync(ChatId chatId, float latitude, float longitude, string title, string address, bool disableNotification = false, int replyToMessageId = 0, InlineKeyboard replyMarkup = null) { var markup = ""; if (replyMarkup != null) { markup = replyMarkup.GetJson(); } var url = Address + Token + "/sendVenue"; if (latitude < -90 || latitude > 90) { throw new ArgumentException("latitude must be between -90 and 90"); } if (longitude < -180 || longitude > 180) { throw new ArgumentException("longitude must be between -180 and 180"); } return(await SendRequest <Response <Message> >(new Dictionary <string, object> { { "chat_id", chatId.Id }, { "latitude", latitude }, { "longitude", longitude }, { "title", title }, { "address", address }, { "disable_notification", disableNotification }, { "reply_to_message_id", replyToMessageId }, { "reply_markup", markup }, }, url)); }
public async Task <IEnumerable <long> > SendMessage(long chatId, OutMessage message) { var attachments = new List <MediaAttachment>(message.Attachments.Count); foreach (var attachment in message.Attachments) { MediaAttachment vkAttachment = attachment.Type switch { AttachmentType.Audio => await UploadAudio(chatId, attachment).ConfigureAwait(false), AttachmentType.Voice => await UploadAudio(chatId, attachment).ConfigureAwait(false), AttachmentType.Photo => await UploadPhoto(chatId, attachment).ConfigureAwait(false), _ => await UploadDocument(chatId, attachment).ConfigureAwait(false) }; attachments.Add(vkAttachment); } var result = new List <long> { await _api.Messages.SendAsync(new MessagesSendParams { PeerId = chatId, RandomId = DateTime.Now.Millisecond, Message = message.Text, Keyboard = message.Keyboard switch { InlineKeyboard inlineKeyboard => VkConverter.ToVkKeyboard(inlineKeyboard), ReplyKeyboard replyKeyboard => VkConverter.ToVkKeyboard(replyKeyboard), _ => message.RemoveReplyKeyboard ? new MessageKeyboard { Buttons = new IEnumerable <MessageKeyboardButton> [0] } : null },
//void editMessageCaption(Update update,string answer,int ? id ,string reply_markup) // { // } string Recycle(Update update, int?id, out string reply_markup) { string answer = ""; reply_markup = ""; TelegramRecycle rec = new TelegramRecycle(update, id); string[] _data = update.callback_query.data.Split(); switch (_data[1] ?? "") { case "покупка": rec.AddBuy(_data[2], _data[3]); answer = Shop(_data[2], _data[3], update, id, out reply_markup); break; case "отобразить": answer = rec.ShowMyBuy(); InlineKeyboard keyboard = new InlineKeyboard(); List <InlineKeyboardButton> line = new List <InlineKeyboardButton>() { new InlineKeyboardButton("Оформить", "корзина оформить"), new InlineKeyboardButton("Изменить", "корзина изменить") }; keyboard.AddLine(line); keyboard.AddButton(new InlineKeyboardButton("⬅️ Назад", "about")); reply_markup = JsonConvert.SerializeObject(keyboard); break; case "изменить": answer = rec.ChangeMyBuy(out reply_markup); break; case "удалить": rec.DeleteElement(_data[2], _data[3]); answer = rec.ChangeMyBuy(out reply_markup); break; case "оформить": answer = "Выберете вариант:" + Environment.NewLine + Environment.NewLine + "Отправить телефон и мы с вами свяжемся n"; reply_markup = ReturnReplyToAdmin(); SendMessage(update.callback_query.from.id, answer, ReceiveToken(update, id), reply_markup); return("отмена"); default: break; } // answer = "В корзине" + rec.Count + " шт"; //InlineKeyboard keyboard = new InlineKeyboard(); //keyboard.AddButton(new InlineKeyboardButton("Назад", "about")); //AddMainButtons(keyboard); //reply_markup = JsonConvert.SerializeObject(keyboard); //Shop(_data[2], _data[3], update, id, out reply_markup); if (reply_markup == "") { MainMenu(update, id, out reply_markup); } return(answer); }
public void Inline_keyboard_serialization_must_be_equal_to_expected_with_keyboard_builder() { InlineKeyboard inlineKeyboard = InlineKeyboard.Builder().AddButton("simple button", "btnSmpTapped").AddPayment("payment", 5000, "GUID/refId", "give me that..").AddOpenUrl("bing", "https://bing.com").Build(); string result = Utils.Serialize(inlineKeyboard).Replace(" ", "").ToLower(); string expected = Utils.ReadFile(JsonsDirectory + "text\\inlineKeyboard.txt").Replace("\n", "").Replace("\r", "").Replace(" ", "").ToLower(); result.Should().Be(expected); }
string MainMenu(Update update, out string reply_markup) { InlineKeyboard keyboard = new InlineKeyboard(); AddMainButtons(keyboard, update); reply_markup = JsonConvert.SerializeObject(keyboard); return("Все категории"); }
void AddRecycle(InlineKeyboard keyboard, string nameCategory, string nameProduct) { List <InlineKeyboardButton> line = new List <InlineKeyboardButton>() { new InlineKeyboardButton("Корзина", "корзина"), new InlineKeyboardButton("Добавить в корзину", "корзина покупка " + nameCategory + " " + nameProduct) }; keyboard.AddLine(line); }
void AddMainButtons(InlineKeyboard keyboard) { List <InlineKeyboardButton> line = new List <InlineKeyboardButton>() { new InlineKeyboardButton("Есть вопрос", "?"), new InlineKeyboardButton("О нас", "about") }; keyboard.AddLine(line); }
void AddMainButtons(InlineKeyboard keyboard, Update update, int?id) { TelegramRecycle tel = new TelegramRecycle(update, id); List <InlineKeyboardButton> line = new List <InlineKeyboardButton>() { new InlineKeyboardButton("❓ Есть вопрос", "?"), new InlineKeyboardButton("📖 О нас", "about") }; keyboard.AddLine(line); }
void AddMainButtons(InlineKeyboard keyboard, Update update) { List <InlineKeyboardButton> line = new List <InlineKeyboardButton>() { new InlineKeyboardButton("Добавить магазин", "reg"), new InlineKeyboardButton("Восстановить пароль", "voc") }; keyboard.AddLine(line); keyboard.AddButton(new InlineKeyboardButton("Как пользоваться", "about")); }
string Shop(string category, string nameProduct, Update update, int?id, out string reply_markup) { //string category = shop.Split(' ')[0]; //string nameProduct = shop.Split(' ').Length < 2 ? "" : shop.Split(' ')[1]; string answer = "!"; reply_markup = ""; List <Category> cat = null; List <Product> p = null; // SendMessage(update.callback_query.from.id, category , ReceiveToken(update, id)); using (botEntities3 bd = new botEntities3()) { try { cat = bd.Category.Where(x => x.Token.Id == id).ToList(); p = cat.Where(x => x.NameCategory == category).First().Product.ToList(); if (nameProduct == "") { nameProduct = p[0].ProductName; } } catch { // SendMessage(update.callback_query.from.id, "БД УПало", ReceiveToken(update, id)); } } InlineKeyboard keyboard = new InlineKeyboard(); int i = 0; foreach (Product k in p) { if (nameProduct == k.ProductName) { continue; } keyboard.AddButton(new InlineKeyboardButton( k.ProductName, k.Category.NameCategory + " " + k.ProductName), i++ / 2); } AddRecycle(keyboard, category, nameProduct, update, id); Product chooseProduct = p.Where(x => x.ProductName == nameProduct).First(); if (chooseProduct.ProductPhoto == null) { chooseProduct.ProductPhoto = ""; } answer = "Стоимость товара " + chooseProduct.ProductPrice + "руб" + Environment.NewLine + "Описание" + " " + chooseProduct.ProductDescription + chooseProduct.ProductPhoto; keyboard.AddButton(new InlineKeyboardButton("⬅️ Назад", "about")); AddMainButtons(keyboard, update, id); reply_markup = JsonConvert.SerializeObject(keyboard); return(answer); }
public string ChangeMyBuy(out string reply_markup) { reply_markup = ""; List <Recycle> p; List <Product> m = new List <Product>(); string[] ar; using (botEntities3 bd = new botEntities3()) { p = bd.Recycle.Where(x => x.TokenId == TokenIds).Where(x => x.UserName == username).ToList(); ar = new string[p.Count]; for (int i = 0; i < p.Count; i++) { try { string namecat = p[i].NameCategory; string nameprod = p[i].NameProduct; Product k = bd.Product.Where(x => x.ProductName == nameprod).Where(x => x.Category.NameCategory == namecat).First(); ar[i] = k.Category.NameCategory; m.Add(k); } catch { } } } if (m.Count == 0) { return("Выберете пункт меню"); } InlineKeyboard keyboard = new InlineKeyboard(); int o = 0; for (int i = 0; i < p.Count; i++) { try { o++; keyboard.AddButton(new InlineKeyboardButton("Удалить " + m[i].ProductName + "(" + ar[i] + ")" + " цена " + m[i].ProductPrice + " 1 шт", "корзина удалить " + ar[i] + " " + m[i].ProductName)); } catch { } } this.Count = o; keyboard.AddButton(new InlineKeyboardButton("Оформить", "корзина оформить")); keyboard.AddButton(new InlineKeyboardButton("⬅️ Назад", "about")); reply_markup = JsonConvert.SerializeObject(keyboard); return("Изменение заказа"); }
void AddRecycle(InlineKeyboard keyboard, string nameCategory, string nameProduct, Update update, int?id) { TelegramRecycle tel = new TelegramRecycle(update, id); List <InlineKeyboardButton> line = new List <InlineKeyboardButton>() { new InlineKeyboardButton("♻️ Корзина (" + tel.Count + ")", "корзина отобразить"), }; if (nameProduct == "" || nameCategory == "") { keyboard.AddLine(line); return; } line.Add(new InlineKeyboardButton("Добавить в корзину", "корзина покупка " + nameCategory + " " + nameProduct)); keyboard.AddLine(line); }
public async Task <Response <Message> > EditMessageReplyMarkupAsync(long inlineMessageId, InlineKeyboard replyMarkup = null) { var markup = ""; if (replyMarkup != null) { markup = replyMarkup.GetJson(); } var methodUrl = Address + Token + "/editMessageReplyMarkup"; return(await SendRequest <Response <Message> >(new Dictionary <string, object> { { "inline_message_id", inlineMessageId }, { "reply_markup", markup }, }, methodUrl)); }
public async Task <Response <Message> > EditMessageCaptionTextAsync(string text, string inlineMessageId, InlineKeyboard replyMarkup = null, string parseMode = "", bool disableWebPagePreview = false) { var markup = ""; if (replyMarkup != null) { markup = replyMarkup.GetJson(); } var methodUrl = Address + Token + "/editMessageCaption"; return(await SendRequest <Response <Message> >(new Dictionary <string, object> { { "text", text }, { "inline_message_id", inlineMessageId }, { "reply_markup", replyMarkup }, { "parse_mode", parseMode }, { "disable_web_page_preview", disableWebPagePreview } }, methodUrl)); }
void IAction.execute() { //Craft inline keyboard inlineKeyboard = new InlineKeyboard( new InlineButton() { Text = "Yes", CallbackData = "yes_" + voteType + "_" + userAffected }, new InlineButton() { Text = "No", CallbackData = "no_" + voteType + "_" + userAffected } ); //Write message //TODO: get vote number from settings returnMessage = "Initiated " + voteType + " for " + userAffected + ". \n 5 Votes needed."; TelegramService.SendMessage(message.Chat.Id, returnMessage, inlineKeyboard); }
public async Task <Response <Message> > SendDocumentAsync(ChatId chatId, TelegramFile document, string caption = "", bool disableNotification = false, int replyToMessageId = 0, InlineKeyboard replyMarkup = null) { var markup = ""; if (replyMarkup != null) { markup = replyMarkup.GetJson(); } var url = Address + Token + "/sendDocument"; return(await SendRequest <Response <Message> >(new Dictionary <string, object> { { "chat_id", chatId.Id }, { "document", document }, { "caption", caption }, { "disable_notification", disableNotification }, { "reply_to_message_id", replyToMessageId }, { "reply_markup", markup }, }, url)); }
public async Task <Response <Message> > SendMessageAsync(ChatId chatId, string text, string parseMode = "", bool disableWebPagePreview = false, bool disableNotification = false, int replyToMessageId = 0, InlineKeyboard replyMarkup = null) { var markup = ""; if (replyMarkup != null) { markup = replyMarkup.GetJson(); } var url = Address + Token + "/sendMessage"; return(await SendRequest <Response <Message> >(new Dictionary <string, object> { { "chat_id", chatId.Id }, { "text", text }, { "parse_mode", parseMode }, { "disable_web_page_preview", disableWebPagePreview }, { "disable_notification", disableNotification }, { "reply_to_message_id", replyToMessageId }, { "reply_markup", markup }, }, url)); }
public async Task <Response <Message> > SendContactAsync(ChatId chatId, string phoneNumber, string firstName, string lastName, bool disableNotification = false, int replyToMessageId = 0, InlineKeyboard replyMarkup = null) { var markup = ""; if (replyMarkup != null) { markup = replyMarkup.GetJson(); } var url = Address + Token + "/sendContact"; return(await SendRequest <Response <Message> >(new Dictionary <string, object> { { "chat_id", chatId.Id }, { "phoneNumber", phoneNumber }, { "firstName", firstName }, { "lastName", lastName }, { "disable_notification", disableNotification }, { "reply_to_message_id", replyToMessageId }, { "reply_markup", markup }, }, url)); }
public async Task <Response <Message> > EditMessageCaptionAsync(string caption, ChatId chatId, long messageId, string parseMode = "", bool disableWebPagePreview = false, InlineKeyboard replyMarkup = null) { var markup = ""; if (replyMarkup != null) { markup = replyMarkup.GetJson(); } var methodUrl = Address + Token + "/editMessageCaption"; return(await SendRequest <Response <Message> >(new Dictionary <string, object> { { "caption", caption }, { "chat_id", chatId.Id }, { "message_id", messageId }, { "parse_mode", parseMode }, { "disable_web_page_preview", disableWebPagePreview }, { "reply_markup", markup } }, methodUrl)); }
//public static InlineKeyboardBuilder Create() //{ // return new InlineKeyboardBuilder(); //} public InlineKeyboardBuilder() { keyboard = new InlineKeyboard(); rowItems = new List <InlineKeyboardItem>(); }
string Shop(string category, string nameProduct, Update update, int?id, out string reply_markup) { //string category = shop.Split(' ')[0]; //string nameProduct = shop.Split(' ').Length < 2 ? "" : shop.Split(' ')[1]; string answer = "Привет"; reply_markup = ""; List <Category> cat = null; List <Product> p = null; // SendMessage(update.callback_query.from.id, category , ReceiveToken(update, id)); using (botEntities2 bd = new botEntities2()) { try { cat = bd.Category.Where(x => x.Token.Id == id).ToList(); p = cat.Where(x => x.NameCategory == category).First().Product.ToList(); if (nameProduct == "") { nameProduct = p[0].ProductName; } } catch { // SendMessage(update.callback_query.from.id, "БД УПало", ReceiveToken(update, id)); } } //try //{ // SendMessage(update.callback_query.from.id, p.Count.ToString(), ReceiveToken(update, id)); //} //catch //{ // SendMessage(update.callback_query.from.id, "равно 0", ReceiveToken(update, id)); //} //list = cat.Where(x => x.NameCategory == category).First(); //if (list == null) //{ // SendMessage(update.callback_query.from.id, "null", ReceiveToken(update, id)); //} //else SendMessage(update.callback_query.from.id, list.Product.Count.ToString(), ReceiveToken(update, id)); InlineKeyboard keyboard = new InlineKeyboard(); int i = 0; foreach (Product k in p) { if (nameProduct == k.ProductName) { continue; } keyboard.AddButton(new InlineKeyboardButton( k.ProductName, k.Category.NameCategory + " " + k.ProductName), i++ / 2); } AddRecycle(keyboard, category, nameProduct); Product chooseProduct = p.Where(x => x.ProductName == nameProduct).First(); answer += chooseProduct.ProductPrice + Environment.NewLine + " " + " " + chooseProduct.ProductDescription; keyboard.AddButton(new InlineKeyboardButton("Назад", "about")); AddMainButtons(keyboard); reply_markup = JsonConvert.SerializeObject(keyboard); return(answer); }