From 4416ae98ca0f296385256196982144a148963352 Mon Sep 17 00:00:00 2001 From: Poulad Date: Wed, 6 Jun 2018 21:38:08 -0400 Subject: [PATCH 1/4] Update changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 728439174..43d49d481 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). -[Unreleased] +## [Unreleased] + +## [14.5.0] - 2018-06-06 ### Added From 5d479e0c6263240e9dd004e0291bbe275b819d83 Mon Sep 17 00:00:00 2001 From: karb0f0s Date: Thu, 7 Jun 2018 11:41:48 +0300 Subject: [PATCH 2/4] Add ParseMode support to EditMessageCaptionAsync Add - Property `ParseMode` to requests with a caption - `EditMessageCaptionRequest` - `EditInlineMessageCaptionRequest` - Parameter `parseMode` to method `ITelegramBotClient.EditMessageCaptionAsync` --- CHANGELOG.md | 7 +++++++ src/Telegram.Bot/ITelegramBotClient.cs | 4 ++++ .../EditInlineMessageCaptionRequest.cs | 8 +++++++- .../Update Messages/EditMessageCaptionRequest.cs | 7 ++++++- src/Telegram.Bot/TelegramBotClient.cs | 4 ++++ .../Update Messages/EditMessageContentTests.cs | 3 ++- .../Update Messages/EditMessageContentTests2.cs | 11 ++++++++--- 7 files changed, 38 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43d49d481..559e9b36e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Added + +- Property `ParseMode` to requests with a caption + - `EditMessageCaptionRequest` + - `EditInlineMessageCaptionRequest` +- Parameter `parseMode` to method `ITelegramBotClient.EditMessageCaptionAsync` + ## [14.5.0] - 2018-06-06 ### Added diff --git a/src/Telegram.Bot/ITelegramBotClient.cs b/src/Telegram.Bot/ITelegramBotClient.cs index 20f3e26f9..1fc69fae3 100644 --- a/src/Telegram.Bot/ITelegramBotClient.cs +++ b/src/Telegram.Bot/ITelegramBotClient.cs @@ -854,6 +854,7 @@ Task StopMessageLiveLocationAsync( /// for the target chat /// Unique identifier of the sent message /// New caption of the message + /// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. /// A JSON-serialized object for an inline keyboard. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// On success, the edited Description is returned. @@ -862,6 +863,7 @@ Task EditMessageCaptionAsync( ChatId chatId, int messageId, string caption, + ParseMode parseMode = default, InlineKeyboardMarkup replyMarkup = default, CancellationToken cancellationToken = default); @@ -870,6 +872,7 @@ Task EditMessageCaptionAsync( /// /// Unique identifier of the sent message /// New caption of the message + /// Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. /// A JSON-serialized object for an inline keyboard. /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// true on success. @@ -877,6 +880,7 @@ Task EditMessageCaptionAsync( Task EditMessageCaptionAsync( string inlineMessageId, string caption, + ParseMode parseMode = default, InlineKeyboardMarkup replyMarkup = default, CancellationToken cancellationToken = default); diff --git a/src/Telegram.Bot/Requests/Update Messages/EditInlineMessageCaptionRequest.cs b/src/Telegram.Bot/Requests/Update Messages/EditInlineMessageCaptionRequest.cs index 60d647b58..9493c90b4 100644 --- a/src/Telegram.Bot/Requests/Update Messages/EditInlineMessageCaptionRequest.cs +++ b/src/Telegram.Bot/Requests/Update Messages/EditInlineMessageCaptionRequest.cs @@ -1,6 +1,7 @@ -using Newtonsoft.Json; +using Newtonsoft.Json; using Newtonsoft.Json.Serialization; using Telegram.Bot.Requests.Abstractions; +using Telegram.Bot.Types.Enums; using Telegram.Bot.Types.ReplyMarkups; // ReSharper disable once CheckNamespace @@ -11,6 +12,7 @@ namespace Telegram.Bot.Requests /// [JsonObject(MemberSerialization.OptIn, NamingStrategyType = typeof(SnakeCaseNamingStrategy))] public class EditInlineMessageCaptionRequest : RequestBase, + IFormattableMessage, IInlineMessage, IInlineReplyMarkupMessage { @@ -24,6 +26,10 @@ public class EditInlineMessageCaptionRequest : RequestBase, [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string Caption { get; set; } + /// + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + public ParseMode ParseMode { get; set; } + /// [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public InlineKeyboardMarkup ReplyMarkup { get; set; } diff --git a/src/Telegram.Bot/Requests/Update Messages/EditMessageCaptionRequest.cs b/src/Telegram.Bot/Requests/Update Messages/EditMessageCaptionRequest.cs index f42d929d8..9c11e5931 100644 --- a/src/Telegram.Bot/Requests/Update Messages/EditMessageCaptionRequest.cs +++ b/src/Telegram.Bot/Requests/Update Messages/EditMessageCaptionRequest.cs @@ -1,7 +1,8 @@ -using Newtonsoft.Json; +using Newtonsoft.Json; using Newtonsoft.Json.Serialization; using Telegram.Bot.Requests.Abstractions; using Telegram.Bot.Types; +using Telegram.Bot.Types.Enums; using Telegram.Bot.Types.ReplyMarkups; // ReSharper disable once CheckNamespace @@ -32,6 +33,10 @@ public class EditMessageCaptionRequest : RequestBase, [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public string Caption { get; set; } + /// + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] + public ParseMode ParseMode { get; set; } + /// [JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)] public InlineKeyboardMarkup ReplyMarkup { get; set; } diff --git a/src/Telegram.Bot/TelegramBotClient.cs b/src/Telegram.Bot/TelegramBotClient.cs index 62de13d61..02b4d0094 100644 --- a/src/Telegram.Bot/TelegramBotClient.cs +++ b/src/Telegram.Bot/TelegramBotClient.cs @@ -933,12 +933,14 @@ public Task EditMessageCaptionAsync( ChatId chatId, int messageId, string caption, + ParseMode parseMode = default, InlineKeyboardMarkup replyMarkup = default, CancellationToken cancellationToken = default ) => MakeRequestAsync(new EditMessageCaptionRequest(chatId, messageId) { Caption = caption, + ParseMode = parseMode, ReplyMarkup = replyMarkup }, cancellationToken); @@ -946,12 +948,14 @@ public Task EditMessageCaptionAsync( public Task EditMessageCaptionAsync( string inlineMessageId, string caption, + ParseMode parseMode = default, InlineKeyboardMarkup replyMarkup = default, CancellationToken cancellationToken = default ) => MakeRequestAsync(new EditInlineMessageCaptionRequest(inlineMessageId) { Caption = caption, + ParseMode = parseMode, ReplyMarkup = replyMarkup }, cancellationToken); diff --git a/test/Telegram.Bot.Tests.Integ/Update Messages/EditMessageContentTests.cs b/test/Telegram.Bot.Tests.Integ/Update Messages/EditMessageContentTests.cs index f212e69e1..7b25e61e5 100644 --- a/test/Telegram.Bot.Tests.Integ/Update Messages/EditMessageContentTests.cs +++ b/test/Telegram.Bot.Tests.Integ/Update Messages/EditMessageContentTests.cs @@ -166,7 +166,8 @@ await _fixture.SendTestCaseNotificationAsync(FactTitles.ShouldEditInlineMessageC await BotClient.EditMessageCaptionAsync( inlineMessageId: callbackQUpdate.CallbackQuery.InlineMessageId, - caption: "Caption is edited 👌" + caption: "_Caption is edited_ 👌", + parseMode: ParseMode.Markdown ); } diff --git a/test/Telegram.Bot.Tests.Integ/Update Messages/EditMessageContentTests2.cs b/test/Telegram.Bot.Tests.Integ/Update Messages/EditMessageContentTests2.cs index e5eac7dcf..c21b95631 100644 --- a/test/Telegram.Bot.Tests.Integ/Update Messages/EditMessageContentTests2.cs +++ b/test/Telegram.Bot.Tests.Integ/Update Messages/EditMessageContentTests2.cs @@ -114,17 +114,22 @@ public async Task Should_Edit_Message_Caption() DateTime timeBeforeEdition = DateTime.UtcNow; await Task.Delay(1_000); - const string newCaption = "Caption is edited."; + const string captionPrefix = "Modified caption"; + (MessageEntityType Type, string Value) captionEntity = (MessageEntityType.Italic, "_with Markdown_"); + string caption = $"{captionPrefix} {captionEntity.Value}"; Message editedMessage = await BotClient.EditMessageCaptionAsync( chatId: originalMessage.Chat.Id, messageId: originalMessage.MessageId, - caption: newCaption + caption: caption, + parseMode: ParseMode.Markdown ); Assert.Equal(originalMessage.MessageId, editedMessage.MessageId); - Assert.Equal(newCaption, editedMessage.Caption); Assert.True(timeBeforeEdition < editedMessage.EditDate); + Assert.StartsWith(captionPrefix, editedMessage.Caption); + + Assert.Equal(editedMessage.CaptionEntities.Single().Type, captionEntity.Type); } private static class FactTitles From f58b5d5893200228ad65eb70b58cc6e14ee94959 Mon Sep 17 00:00:00 2001 From: Poulad Date: Mon, 11 Jun 2018 19:56:16 -0400 Subject: [PATCH 3/4] Prevent a breaking change --- src/Telegram.Bot/ITelegramBotClient.cs | 8 ++++---- src/Telegram.Bot/TelegramBotClient.cs | 23 +++++++++++++---------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/Telegram.Bot/ITelegramBotClient.cs b/src/Telegram.Bot/ITelegramBotClient.cs index 1fc69fae3..f23c0300b 100644 --- a/src/Telegram.Bot/ITelegramBotClient.cs +++ b/src/Telegram.Bot/ITelegramBotClient.cs @@ -863,9 +863,9 @@ Task EditMessageCaptionAsync( ChatId chatId, int messageId, string caption, - ParseMode parseMode = default, InlineKeyboardMarkup replyMarkup = default, - CancellationToken cancellationToken = default); + CancellationToken cancellationToken = default, + ParseMode parseMode = default); /// /// Use this method to edit captions of messages sent by the bot or via the bot (for inline bots). @@ -880,9 +880,9 @@ Task EditMessageCaptionAsync( Task EditMessageCaptionAsync( string inlineMessageId, string caption, - ParseMode parseMode = default, InlineKeyboardMarkup replyMarkup = default, - CancellationToken cancellationToken = default); + CancellationToken cancellationToken = default, + ParseMode parseMode = default); /// /// Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots). diff --git a/src/Telegram.Bot/TelegramBotClient.cs b/src/Telegram.Bot/TelegramBotClient.cs index 02b4d0094..456429ed4 100644 --- a/src/Telegram.Bot/TelegramBotClient.cs +++ b/src/Telegram.Bot/TelegramBotClient.cs @@ -303,10 +303,10 @@ private async void ReceiveAsync( try { updates = await GetUpdatesAsync( - MessageOffset, - timeout: timeout, - allowedUpdates: allowedUpdates, - cancellationToken: cancellationToken + MessageOffset, + timeout: timeout, + allowedUpdates: allowedUpdates, + cancellationToken: cancellationToken ).ConfigureAwait(false); } catch (OperationCanceledException) @@ -350,9 +350,11 @@ public void StopReceiving() _receivingCancellationTokenSource.Cancel(); } catch (WebException) - { } + { + } catch (TaskCanceledException) - { } + { + } } #endregion Helpers @@ -714,6 +716,7 @@ public async Task DownloadFileAsync( { throw new ArgumentException("Invalid file path", nameof(filePath)); } + if (destination == null) { throw new ArgumentNullException(nameof(destination)); @@ -933,9 +936,9 @@ public Task EditMessageCaptionAsync( ChatId chatId, int messageId, string caption, - ParseMode parseMode = default, InlineKeyboardMarkup replyMarkup = default, - CancellationToken cancellationToken = default + CancellationToken cancellationToken = default, + ParseMode parseMode = default ) => MakeRequestAsync(new EditMessageCaptionRequest(chatId, messageId) { @@ -948,9 +951,9 @@ public Task EditMessageCaptionAsync( public Task EditMessageCaptionAsync( string inlineMessageId, string caption, - ParseMode parseMode = default, InlineKeyboardMarkup replyMarkup = default, - CancellationToken cancellationToken = default + CancellationToken cancellationToken = default, + ParseMode parseMode = default ) => MakeRequestAsync(new EditInlineMessageCaptionRequest(inlineMessageId) { From 8e1452df8e81ca661dcbbf8a1bbb564569c78e8d Mon Sep 17 00:00:00 2001 From: Poulad Date: Mon, 11 Jun 2018 19:57:38 -0400 Subject: [PATCH 4/4] Upgrade to v14.6.0 --- src/Telegram.Bot/Telegram.Bot.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Telegram.Bot/Telegram.Bot.csproj b/src/Telegram.Bot/Telegram.Bot.csproj index 817a5a41e..86067d351 100644 --- a/src/Telegram.Bot/Telegram.Bot.csproj +++ b/src/Telegram.Bot/Telegram.Bot.csproj @@ -1,7 +1,7 @@  netstandard1.1;net45 - 14.5.0 + 14.6.0 latest True True