private void tsmiPublicate_ClickAsync(object sender, EventArgs e) { VkPublicationDTO publication = (VkPublicationDTO)dgvPosts.SelectedRows[0].Tag; TelegramPublicationDTO telegramPost = PublicationCreator.CreateTelegramPublication(publication); if (telegramPost == null) { MessageBox.Show("Ошибка публикации."); return; } else if (telegramPost.Error.Length > 0) { MessageBox.Show(telegramPost.Error); return; } else if (telegramPost.CanPublicate == false) { MessageBox.Show("Публикация отклонена. Не соответствует фильтру."); return; } bool ExistsImage = false; if (telegramPost.PhotoUrl != null && telegramPost.PhotoUrl != string.Empty) { ExistsImage = true; } TelegramAPI.SendPublicationAsync(telegramPost, ExistsImage); }
public static bool SendPublicationAsync(TelegramPublicationDTO telegramPublicationDTO, bool UseImage = false) { try { ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; // Да, телега только такой протокол поддерживает TelegramBotClient botClient = new TelegramBotClient(Configs.TelegramToken); var me = botClient.GetMeAsync().Result; ChatId chatId = new ChatId(Configs.TelegramChannel); Task <Telegram.Bot.Types.Message> message = null; if (UseImage == false) { message = botClient.SendTextMessageAsync(chatId, telegramPublicationDTO.Text, Telegram.Bot.Types.Enums.ParseMode.Default, true, true); } else { message = botClient.SendPhotoAsync(chatId, telegramPublicationDTO.PhotoUrl, telegramPublicationDTO.Text, Telegram.Bot.Types.Enums.ParseMode.Default, true); } if (message.Exception != null) { //MessageBox.Show(message.Exception.Message); return(false); } if (message.Result == null) { //MessageBox.Show("Результат вернул NULL"); return(false); } return(true); } catch (Exception ex) { return(false); } }
private void Bot_OnPublicationCanceled(TelegramPublicationDTO telegramPublicationDTO) { AddRow(telegramPublicationDTO.VkPublication, false); }
private void Bot_OnPublicationSended(TelegramPublicationDTO telegramPublicationDTO) { AddRow(telegramPublicationDTO.VkPublication, true); }