/// <inheritdoc/> public string SendText(string chatId, string text) { using (var cancellationTokenSource = this.CtsFactory()) { return(this.ProxyCall(this.botClient.SendTextMessageAsync( chatId: this.CreateChatId(chatId), text: CharacterTransformation.TransformSpecialCharacters(text), disableNotification: this.DisableNotifications, disableWebPagePreview: this.DisableWebPagePreview, parseMode: this.ParseMode, cancellationToken: cancellationTokenSource.Token))); } }
/// <inheritdoc/> public string StartSendText(string chatId, string text) { var cancellationTokenSource = this.CtsFactory(); return(this.FireAndForgetProxyCall(this.botClient.SendTextMessageAsync( chatId: this.CreateChatId(chatId), text: CharacterTransformation.TransformSpecialCharacters(text), disableNotification: this.DisableNotifications, disableWebPagePreview: this.DisableWebPagePreview, parseMode: this.ParseMode, cancellationToken: cancellationTokenSource.Token) .DisposeAfterThreadCompletionAsync(new IDisposable[] { cancellationTokenSource, }))); }
public void EmojisAreReplaced(string actual, string expected) { actual = CharacterTransformation.DecodeEncodedNonAsciiCharacters(actual); Assert.Equal(expected, actual); }
private MimeMessage CreateMessage( string sender, IEnumerable <string> recipients, string subject, string textBody, string htmlBody, IEnumerable <string> attachments = null) { var message = new MimeMessage(); message.From.Add(StringToMailboxAddress(sender)); foreach (var recipient in recipients) { if (recipient.ToLower().StartsWith("to:")) { message.To.Add(StringToMailboxAddress(recipient.Substring(3))); } else if (recipient.ToLower().StartsWith("cc:")) { message.Cc.Add(StringToMailboxAddress(recipient.Substring(3))); } else if (recipient.ToLower().StartsWith("bcc:")) { message.Bcc.Add(StringToMailboxAddress(recipient.Substring(4))); } else { throw new ArgumentException($"'{recipient}' has no valid prefix (to:, cc:, ...)."); } } if (!message.To.Any()) { throw new ArgumentException($"You must provide at least one 'to' recipient."); } message.Subject = subject; var builder = new BodyBuilder(); if (!string.IsNullOrWhiteSpace(textBody)) { builder.TextBody = CharacterTransformation.TransformSpecialCharacters(textBody); } if (!string.IsNullOrWhiteSpace(htmlBody)) { builder.HtmlBody = CharacterTransformation.TransformSpecialCharacters(htmlBody); } if (attachments != null) { foreach (var attachment in attachments) { builder.Attachments.Add(attachment); } } // Now we just need to set the message body and we're done message.Body = builder.ToMessageBody(); return(message); }