public async void Idea(TelegramBotClient Bot, MessageEventArgs e) { List <DataOfIdea> csv = new List <DataOfIdea>(); csv = DataOfIdea.ReadFile("ideas.csv"); await Bot.SendTextMessageAsync(e.Message.From.Id, "Привет, если ты нажал сюда, то хотел бы что-нибудь связать. Напиши что?"); /*var inlineKeyboard3 = new InlineKeyboardMarkup * (new[] { * InlineKeyboardButton.WithCallbackData("Платья"), * InlineKeyboardButton.WithCallbackData("Свитера") * }); * await Bot.SendTextMessageAsync(e.Message.From.Id, "Выбери, какие идеи тебя интересуют", replyMarkup: inlineKeyboard3);*/ }
public static List <DataOfIdea> ReadFile(string filename) { List <DataOfIdea> res = new List <DataOfIdea>(); using (StreamReader sr = new StreamReader(filename)) { string line; while ((line = sr.ReadLine()) != null) { DataOfIdea idea = new DataOfIdea(); idea.Piece_idea(line); res.Add(idea); } } return(res); }
private async static void Bot_OnMessageReceived(object sender, MessageEventArgs e) { var message = e.Message; if (message == null || message.Type != MessageType.TextMessage) { await Bot.SendTextMessageAsync(e.Message.Chat.Id, "Извини, но я могу воспринимать только текст"); } string name = $"{message.From.FirstName}{message.From.LastName}"; Console.WriteLine($"{name} отправил(a) сообщение '{message.Text}' "); switch (message.Text) { case "/start": keyboard.Start(Bot, e); break; case "/inline": keyboard.Inline(Bot, e); break; case "/keyboard": keyboard.Keyboard_k(Bot, e); break; case "/ideas": last_message = keyboard.Idea(Bot, e); break; case "/calculator": last_message_data = keyboard.Calculator(Bot, e); break; default: ////Bot.SendTextMessageAsync(e.Message.From.Id, "Прости, я не понимаю тебя").Wait(); //var response = apiAi.TextRequest(message.Text); //string answer = response.Result.Fulfillment.Speech; //if (answer == "") // answer = "Прости, я не понимаю тебя"; //await Bot.SendTextMessageAsync(e.Message.From.Id, answer); break; } for (int i = 0; i < bla2.Count(); i++) { if ((last_message_data + 1 == e.Message.MessageId) && (e.Message.Text.ToLower() == bla2[i].Model.ToLower())) { select_model = bla2[i].Model; result = Convert.ToInt32(bla2[i].KOmodel); mod = bla2[i].Model + "," + bla2[i].Size + "," + bla2[i].Yarn; msg++; } } if (msg == 1) { msg_size = Bot.SendTextMessageAsync(e.Message.Chat.Id, "Укажите размер (XXS/XS/S/M/L/XL/XXL)").Result.MessageId; msg++; } else if (msg == 2) { for (int i = 0; i < bla2.Count(); i++) { if ((msg_size + 1 == e.Message.MessageId) && (e.Message.Text.ToLower() == bla2[i].Size.ToLower())) { select_size = bla2[i].Size; result *= Convert.ToInt32(bla2[i].KOsize); msg++; } } } if (msg == 3) { msg_yarn = Bot.SendTextMessageAsync(e.Message.Chat.Id, "Укажи метраж нити (40-60 / 60-90 / 90-120 / 120-180 / 180-200 / 200-250 / 250-300 / 300-350 )").Result.MessageId; msg = 0; } else if (msg == 0) { for (int i = 0; i < bla2.Count(); i++) { if ((msg_yarn + 1 == e.Message.MessageId) && (e.Message.Text.ToLower() == bla2[i].Yarn.ToLower())) { select_yarn = bla2[i].Yarn; result *= Convert.ToInt32(bla2[i].KOyarn); Console.WriteLine(result); } } } if (select_yarn != null) { string res = result.ToString() + " грамм пряжи необходимо для твоего изделия!"; msg = 3; Bot.SendTextMessageAsync(e.Message.Chat.Id, res).Wait(); } //////// blaCount = bla.Count() - 1; for (int i = 0; i <= product.Count() - 1; i++) { if ((last_message + 1 == e.Message.MessageId) && (e.Message.Text.ToLower() == product[i].product.ToLower())) { select_product = product[i].product; } } if (blaCount != 0) { if (select_product == bla[count_idea].Product.ToLower()) { Bot.SendTextMessageAsync(e.Message.Chat.Id, bla[count_idea].Name + "\n" + bla[0].Description).Wait(); var FileUrl = string.Format(@"images//{0}", bla[count_idea].Photo); var stream = new FileStream(FileUrl, FileMode.Open); var fileToSend = new FileToSend(bla[count_idea].Photo, stream); await Bot.SendPhotoAsync(e.Message.Chat.Id, fileToSend); count_idea++; } for (int i = 0; i <= product.Count() - 1; i++) { if ((last_message + 1 == e.Message.MessageId) && (e.Message.Text.ToLower() == product[i].product.ToLower())) { select_product = product[i].product; } } if ((blaCount != 0) & (count_idea == 0)) { for (int i = 0; i <= blaCount; i++) { if (select_product == bla[i].Product.ToLower()) { DataOfIdea tmp = new DataOfIdea(); tmp.ID = bla[i].ID; tmp.Name = bla[i].Name; tmp.Product = bla[i].Product; tmp.Photo = bla[i].Photo; tmp.Description = bla[i].Description; data.Add(tmp); } } if (count_idea == 5) { Bot.SendTextMessageAsync(e.Message.Chat.Id, "К сожалению, в данной категории больше нет идей! Для того, чтобы найти что-то другое нужно выбрать /ideas").Wait(); select_product = ""; data.Clear(); count_idea = 0; } else if (data.Count() != 0) { Bot.SendTextMessageAsync(e.Message.Chat.Id, data[count_idea].Name + "\n" + data[count_idea].Description).Wait(); var FileUrl = string.Format(@"images//{0}", data[count_idea].Photo); var stream = new FileStream(FileUrl, FileMode.Open); var fileToSend = new FileToSend(data[count_idea].Photo, stream); await Bot.SendPhotoAsync(e.Message.Chat.Id, fileToSend); count_idea++; } } } }
private async static void Bot_OnMessageReceived(object sender, MessageEventArgs e) { var message = e.Message; if (message == null || message.Type != MessageType.TextMessage) { await Bot.SendTextMessageAsync(e.Message.Chat.Id, "Извини, но я могу воспринимать только текст"); } string name = $"{message.From.FirstName}{message.From.LastName}"; Console.WriteLine($"{name} отправил(a) сообщение '{message.Text}' "); switch (message.Text) { case "/start": keyboard.Start(Bot, e); break; case "/inline": keyboard.Inline(Bot, e); break; case "/keyboard": keyboard.Keyboard_k(Bot, e); break; case "/help": keyboard.Help(Bot, e); break; case "/ideas": last_message = keyboard.Idea(Bot, e); break; case "/calculator": keyboard.Calculator(Bot, e); break; default: //Bot.SendTextMessageAsync(e.Message.From.Id, "Прости, я не понимаю тебя").Wait(); //var response = apiAi.TextRequest(message.Text); //string answer = response.Result.Fulfillment.Speech; //if (answer == "") // answer = "Прости, я не понимаю тебя"; //await Bot.SendTextMessageAsync(e.Message.From.Id, answer); break; } blaCount = bla.Count() - 1; for (int i = 0; i <= product.Count() - 1; i++) { if ((last_message + 1 == e.Message.MessageId) && (e.Message.Text.ToLower() == product[i].product.ToLower())) { select_product = product[i].product; } } if ((blaCount != 0) & (count_idea == 0)) { for (int i = 0; i <= blaCount; i++) { if (select_product == bla[i].Product.ToLower()) { DataOfIdea tmp = new DataOfIdea(); tmp.ID = bla[i].ID; tmp.Name = bla[i].Name; tmp.Product = bla[i].Product; tmp.Photo = bla[i].Photo; tmp.Description = bla[i].Description; data.Add(tmp); } } } if (count_idea == 5) { Bot.SendTextMessageAsync(e.Message.Chat.Id, "К сожалению, в данной категории больше нет идей! Для того, чтобы найти что-то другое нужно выбрать /ideas").Wait(); select_product = ""; data.Clear(); count_idea = 0; } else if (data.Count() != 0) { Bot.SendTextMessageAsync(e.Message.Chat.Id, data[count_idea].Name + "\n" + data[count_idea].Description).Wait(); var FileUrl = string.Format(@"images//{0}", data[count_idea].Photo); var stream = new FileStream(FileUrl, FileMode.Open); var fileToSend = new FileToSend(data[count_idea].Photo, stream); await Bot.SendPhotoAsync(e.Message.Chat.Id, fileToSend); count_idea++; } }