public static InlineKeyboardMarkup MenuGeneralGet(long chatId) { TelegramBot.Get().SendChatActionAsync(chatId, ChatAction.Typing); InlineKeyboardMarkup keyboard = new InlineKeyboardMarkup(new[] { new[] // second row { new InlineKeyboardButton(MenuPhonesText.ButtomSearchPhones), // new InlineKeyboardButton(MenuPhonesText.ButtomGetPhones), } /* * , * * new[] // first row * { * new InlineKeyboardButton("Посмотреть оплату"), * new InlineKeyboardButton("Посмотреть анкету"), * }, */ }); string Text = ""; TelegramBot.Get().SendTextMessageAsync(chatId, Text, false, true, 0, keyboard, ParseMode.Markdown); // TelegramBot.Get().SendTextMessageAsync(chatId, "", replyMarkup: keyboard); return(keyboard); }
/// <summary> /// Поиск телефонов /// </summary> /// public static ReplyKeyboardMarkup MenuGeneralGetMarkup(long chatId) { ReplyKeyboardMarkup keyboardMarkup = new ReplyKeyboardMarkup(new[] { new[] { new KeyboardButton("Сотрудники"), new KeyboardButton("Арендаторы") } , new[] { new KeyboardButton("Дни рождения"), new KeyboardButton("ТЗ") } }); TelegramBot.Get().SendChatActionAsync(chatId, ChatAction.Typing); string Text = "Проверка"; TelegramBot.Get().SendTextMessageAsync(chatId, Text, replyMarkup: keyboardMarkup); return(keyboardMarkup); }
public async Task <OkResult> Post(Update update) { var message = update.Message; // Console.WriteLine("Received Message from {0}", message.Chat.Id); if (message.Type == MessageType.TextMessage) { // Echo each Message await TelegramBot.Get().SendTextMessageAsync(message.Chat.Id, message.Text); await Task.Run(() => new TelegramPost().Message(message, _context)); } else if (message.Type == MessageType.PhotoMessage) { // Download Photo var file = await TelegramBot.Get().GetFileAsync(message.Photo.LastOrDefault()?.FileId); var filename = file.FileId + "." + file.FilePath.Split('.').Last(); using (var saveImageStream = System.IO.File.Open(filename, FileMode.Create)) { await file.FileStream.CopyToAsync(saveImageStream); } await TelegramBot.Get().SendTextMessageAsync(message.Chat.Id, "Thx for the Pics"); } return(Ok()); }
// POST api/values public async Task <OkResult> Post1([FromBody] Update update) { // _context.StateModel.Add(new StateModel {ChatId= chatId , TextButon= buttomText }); // _context.StateModel.Add(new StateModel { ChatId = 2333322, TextButon = "ljlkjlkjlkj" }); // var test = _context.Company.ToList(); // _context.SaveChanges(); try { var message = update.Message; // long chatId = update.Message.Chat.Id; if (message != null) { if (message.Type == MessageType.TextMessage) { // await TelegramBot.Get().SendTextMessageAsync(Config.TestChatId, "Вы написали: " + message.Text); await Task.Run(() => new TelegramPost().Message(message, _context)); return(Ok()); } } var buttomText = update.CallbackQuery.Data; // await TelegramBot.Get().SendTextMessageAsync(Config.TestChatId, "Вы нажали: " + buttom); await Task.Run(() => new TelegramPost().ChosenInlineResult(update.CallbackQuery, _context)); return(Ok()); } catch (Exception ex) { await TelegramBot.Get().SendTextMessageAsync(ConfigTelegram.TestChatId, "Ошибка: " + ex.Message); } // var text = value.CallbackQuery.Data; // await Task.Run(() => new Vadim_info().MessageAsync(value)); // await Task.Run(() => new Vadim_info().Message(value)); // await TelegramBot.Get().SendTextMessageAsync(Config.TestChatId, ""); // await TelegramBot.Get().SendTextMessageAsync(Config.TestChatId, value.CallbackQuery.Data.ToString()); // var me = Bot.GetMeAsync().Result; return(Ok()); }
public async void ImportPhone() { string addr = @"http://vadim.info/Content/Downloads/jgjhgayqo67yqre.json"; TelegramPost telegramPost = new TelegramPost(); var client = new HttpClient(); client.BaseAddress = new Uri(addr); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await client.GetAsync(addr); // ToTelegram("Authorization: " + ZadarmaApiConfig.key + ":" + fullQueryStr); if (response.IsSuccessStatusCode) { List <RootobjectPhoneItems> phones = await response.Content.ReadAsAsync <List <RootobjectPhoneItems> >(); RootobjectPhoneItems tempPhoneModel; // telegramPost.MessagePostDirectBot(chatId, searhRezult.Count().ToString()); try { foreach (RootobjectPhoneItems phone in phones) { tempPhoneModel = new RootobjectPhoneItems { // Id = phone.Id, FirstName = phone.FirstName, LastName = phone.LastName, Organization = phone.Organization, PhoneStationary = phone.PhoneStationary, PhoneHandheld = phone.PhoneHandheld, PhoneMobile = phone.PhoneMobile, email = phone.email, Service = phone.Service, Birthday = phone.Birthday, MiddleName = phone.MiddleName }; _context.RootobjectPhoneItems.Add(tempPhoneModel); _context.Dispose(); // context.SaveChanges(); telegramPost.MessagePostDirectBot(ConfigTelegram.TestChatId, "Готово"); } } catch (Exception ex) { await TelegramBot.Get().SendTextMessageAsync(ConfigTelegram.TestChatId, "Ошибка: " + ex.Message); } // telegramPost.MessageEditDirectBot(chatId, messageId, text); // telegramPost.MessagePostDirectBot(chatId, text); } }
public async Task GetPhone(long chatId, int messageId, string search) { string searchString = search.ToLower(); string addr = @"http://vadim.info/Content/Downloads/jgjhgayqo67yqre.json"; TelegramPost telegramPost = new TelegramPost(); using (var client = new HttpClient()) { CultureInfo cultureInfo = new CultureInfo("ru-RU"); // CultureInfo culture = new CultureInfo("ru-RU"); client.BaseAddress = new Uri(addr); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); // client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("month=8")); // telegramPost.MessageDirectBot("Authorization: "); // HTTP GET HttpResponseMessage response = await client.GetAsync(addr); // ToTelegram("Authorization: " + ZadarmaApiConfig.key + ":" + fullQueryStr); if (response.IsSuccessStatusCode) { try { List <RootobjectPhoneItems> phones = await response.Content.ReadAsAsync <List <RootobjectPhoneItems> >(); string text = ""; IEnumerable <RootobjectPhoneItems> searhRezult = phones .Where(e => e.LastName.ToLower().Contains(searchString) || e.FirstName.ToLower().Contains(searchString) || e.MiddleName.ToLower().Contains(searchString) || e.Service.ToLower().Contains(searchString) || e.Organization.ToLower().Contains(searchString) ).OrderBy(e => e.LastName); telegramPost.MessagePostDirectBot(chatId, "Найдено: " + searhRezult.Count().ToString()); Thread.Sleep(50); foreach (RootobjectPhoneItems phone in searhRezult) { text = string.Format( "<b>{0} {1}</b> \r\n" + "{7}\r\n" + "\r\n" + "{2}" // + "\r\n" + "{3}" + "{4}" + "{5}" + "{6}" + "\r\n" + "{8} \r\n" // + "---------------------------------------- \r\n" // + phone.email + "\r\n" , phone.FirstName, phone.LastName, !(string.IsNullOrEmpty(phone.Organization))? "Компания: " + phone.Organization + "\r\n" : phone.Organization, !(string.IsNullOrEmpty(phone.PhoneStationary)) ? "\U0000260E Стационарный телефон: " + phone.PhoneStationary + " \r\n" : phone.PhoneStationary, phone.PhoneHandheld != null ? "\U0001F4DE Переносная трубка: " + phone.PhoneHandheld + " \r\n" : null, !(string.IsNullOrEmpty(phone.PhoneMobile)) ? "\U0001F4F1 +7" + phone.PhoneMobile + " \r\n" : phone.PhoneMobile, !(string.IsNullOrEmpty(phone.email))? "\U00002709 " + phone.email : phone.email, phone.Service, !(string.IsNullOrEmpty(phone.Birthday)) ? "День рождения: " + (DateTime.Parse(phone.Birthday, cultureInfo)).ToString("d MMMM", cultureInfo) : phone.Birthday ); Thread.Sleep(50); telegramPost.MessagePostDirectBot(chatId, text); } // telegramPost.MessageEditDirectBot(chatId, messageId, text); // telegramPost.MessagePostDirectBot(chatId, text); } catch (Exception ex) { await TelegramBot.Get().SendTextMessageAsync(ConfigTelegram.TestChatId, "Ошибка: " + ex.Message); } } } }