Skip to content

Commit

Permalink
Escape everything when all parse modes fail
Browse files Browse the repository at this point in the history
  • Loading branch information
ronnygunawan committed Feb 6, 2024
1 parent e5b3651 commit 7864a30
Showing 1 changed file with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using BotNet.Services.MarkdownV2;
Expand Down Expand Up @@ -37,7 +38,16 @@ public static async Task<Message> SendTextMessageAsync(
continue;
}
}
throw new ApiRequestException("Text could not be parsed.");

// Last resort: escape everything
return await telegramBotClient.SendTextMessageAsync(
chatId: chatId,
text: WebUtility.HtmlEncode(text),
parseMode: ParseMode.Html,
replyToMessageId: replyToMessageId,
replyMarkup: replyMarkup,
cancellationToken: cancellationToken
);
}

public static async Task<Message> EditMessageTextAsync(
Expand Down Expand Up @@ -67,7 +77,16 @@ public static async Task<Message> EditMessageTextAsync(
continue;
}
}
throw new ApiRequestException("Text could not be parsed.");

// Last resort: escape everything
return await telegramBotClient.EditMessageTextAsync(
chatId: chatId,
messageId: messageId,
text: WebUtility.HtmlEncode(text),
parseMode: ParseMode.Html,
replyMarkup: replyMarkup,
cancellationToken: cancellationToken
);
}
}
}

0 comments on commit 7864a30

Please sign in to comment.