Skip to content

Commit

Permalink
Merge pull request #739 from TelegramBots/develop
Browse files Browse the repository at this point in the history
v14.6.0
  • Loading branch information
Poulad authored Jun 12, 2018
2 parents 5384e43 + 2385dc7 commit ea8e7a8
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 18 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@ 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]

### Added

- Property `ParseMode` to requests with a caption
- `EditMessageCaptionRequest`
- `EditInlineMessageCaptionRequest`
- Parameter `parseMode` to method `ITelegramBotClient.EditMessageCaptionAsync`

## [14.5.0] - 2018-06-06

### Added

Expand Down
8 changes: 6 additions & 2 deletions src/Telegram.Bot/ITelegramBotClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,7 @@ Task StopMessageLiveLocationAsync(
/// <param name="chatId"><see cref="ChatId"/> for the target chat</param>
/// <param name="messageId">Unique identifier of the sent message</param>
/// <param name="caption">New caption of the message</param>
/// <param name="parseMode">Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.</param>
/// <param name="replyMarkup">A JSON-serialized object for an inline keyboard.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns>On success, the edited Description is returned.</returns>
Expand All @@ -863,13 +864,15 @@ Task<Message> EditMessageCaptionAsync(
int messageId,
string caption,
InlineKeyboardMarkup replyMarkup = default,
CancellationToken cancellationToken = default);
CancellationToken cancellationToken = default,
ParseMode parseMode = default);

/// <summary>
/// Use this method to edit captions of messages sent by the bot or via the bot (for inline bots).
/// </summary>
/// <param name="inlineMessageId">Unique identifier of the sent message</param>
/// <param name="caption">New caption of the message</param>
/// <param name="parseMode">Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption.</param>
/// <param name="replyMarkup">A JSON-serialized object for an inline keyboard.</param>
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
/// <returns><c>true</c> on success.</returns>
Expand All @@ -878,7 +881,8 @@ Task EditMessageCaptionAsync(
string inlineMessageId,
string caption,
InlineKeyboardMarkup replyMarkup = default,
CancellationToken cancellationToken = default);
CancellationToken cancellationToken = default,
ParseMode parseMode = default);

/// <summary>
/// Use this method to edit only the reply markup of messages sent by the bot or via the bot (for inline bots).
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,6 +12,7 @@ namespace Telegram.Bot.Requests
/// </summary>
[JsonObject(MemberSerialization.OptIn, NamingStrategyType = typeof(SnakeCaseNamingStrategy))]
public class EditInlineMessageCaptionRequest : RequestBase<bool>,
IFormattableMessage,
IInlineMessage,
IInlineReplyMarkupMessage
{
Expand All @@ -24,6 +26,10 @@ public class EditInlineMessageCaptionRequest : RequestBase<bool>,
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Caption { get; set; }

/// <inheritdoc />
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public ParseMode ParseMode { get; set; }

/// <inheritdoc cref="IInlineReplyMarkupMessage.ReplyMarkup" />
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public InlineKeyboardMarkup ReplyMarkup { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -32,6 +33,10 @@ public class EditMessageCaptionRequest : RequestBase<Message>,
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string Caption { get; set; }

/// <inheritdoc />
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public ParseMode ParseMode { get; set; }

/// <inheritdoc cref="IInlineReplyMarkupMessage.ReplyMarkup" />
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public InlineKeyboardMarkup ReplyMarkup { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/Telegram.Bot/Telegram.Bot.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard1.1;net45</TargetFrameworks>
<VersionPrefix>14.5.0</VersionPrefix>
<VersionPrefix>14.6.0</VersionPrefix>
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
Expand Down
23 changes: 15 additions & 8 deletions src/Telegram.Bot/TelegramBotClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -350,9 +350,11 @@ public void StopReceiving()
_receivingCancellationTokenSource.Cancel();
}
catch (WebException)
{ }
{
}
catch (TaskCanceledException)
{ }
{
}
}

#endregion Helpers
Expand Down Expand Up @@ -714,6 +716,7 @@ public async Task DownloadFileAsync(
{
throw new ArgumentException("Invalid file path", nameof(filePath));
}

if (destination == null)
{
throw new ArgumentNullException(nameof(destination));
Expand Down Expand Up @@ -934,11 +937,13 @@ public Task<Message> EditMessageCaptionAsync(
int messageId,
string caption,
InlineKeyboardMarkup replyMarkup = default,
CancellationToken cancellationToken = default
CancellationToken cancellationToken = default,
ParseMode parseMode = default
) =>
MakeRequestAsync(new EditMessageCaptionRequest(chatId, messageId)
{
Caption = caption,
ParseMode = parseMode,
ReplyMarkup = replyMarkup
}, cancellationToken);

Expand All @@ -947,11 +952,13 @@ public Task EditMessageCaptionAsync(
string inlineMessageId,
string caption,
InlineKeyboardMarkup replyMarkup = default,
CancellationToken cancellationToken = default
CancellationToken cancellationToken = default,
ParseMode parseMode = default
) =>
MakeRequestAsync(new EditInlineMessageCaptionRequest(inlineMessageId)
{
Caption = caption,
ParseMode = parseMode,
ReplyMarkup = replyMarkup
}, cancellationToken);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ea8e7a8

Please sign in to comment.