Skip to content

Commit

Permalink
Merge pull request #9 from 0xF6/update/deps
Browse files Browse the repository at this point in the history
Update Telegram.Bot to 19.0 and adaptation to API changes
  • Loading branch information
k0dep committed Jan 2, 2024
2 parents ad69d64 + 7e1df73 commit aa8144d
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 19 deletions.
6 changes: 4 additions & 2 deletions Deployf.Botf/BotController.cs
Expand Up @@ -147,6 +147,7 @@ protected async Task<Message> Send(string text, ParseMode mode)
message = await Client.SendTextMessageAsync(
ChatId == 0 ? Context!.GetSafeChatId()! : ChatId,
text,
null,
ParseMode.Html,
replyMarkup: Message.Markup,
cancellationToken: CancelToken,
Expand All @@ -156,7 +157,8 @@ protected async Task<Message> Send(string text, ParseMode mode)
{
message = await Client.SendPhotoAsync(
ChatId == 0 ? Context!.GetSafeChatId()! : ChatId,
Message.PhotoUrl,
new InputFileUrl(Message.PhotoUrl),
null,
text,
ParseMode.Html,
replyMarkup: Message.Markup,
Expand Down Expand Up @@ -196,7 +198,7 @@ public async Task<Message> Update(InlineKeyboardMarkup? markup = null, string? t
messageId,
messageText,
previousMessage!,
nextMessagePhotoUrl,
new InputMediaPhoto(new InputFileUrl(nextMessagePhotoUrl)),

Check warning on line 201 in Deployf.Botf/BotController.cs

View workflow job for this annotation

GitHub Actions / build

Possible null reference argument for parameter 'url' in 'InputFileUrl.InputFileUrl(string url)'.
markupValue,
mode,
Message.ReplyToMessageId,
Expand Down
2 changes: 1 addition & 1 deletion Deployf.Botf/Deployf.Botf.csproj
Expand Up @@ -26,7 +26,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Telegram.Bot" Version="18.0.0" />
<PackageReference Include="Telegram.Bot" Version="19.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion Deployf.Botf/Messages/MessageSender.cs
Expand Up @@ -20,6 +20,7 @@ public async ValueTask<Message> Send(MessageBuilder message, CancellationToken t
return await _client.SendTextMessageAsync(
message.ChatId,
message.Message,
null,
message.ParseMode,
replyMarkup: message.Markup,
cancellationToken: token,
Expand All @@ -30,7 +31,8 @@ public async ValueTask<Message> Send(MessageBuilder message, CancellationToken t
{
return await _client.SendPhotoAsync(
message.ChatId,
message.PhotoUrl,
new InputFileUrl(message.PhotoUrl),
null,
message.Message,
message.ParseMode,
replyMarkup: message.Markup,
Expand Down
Expand Up @@ -17,9 +17,8 @@ public EditTextMessageStrategy(BotfBot bot)

public bool CanHandle(IUpdateMessageContext context)
{
var newMessageFileIsEmpty = string.IsNullOrEmpty(context.MediaFile?.FileId) &&
string.IsNullOrEmpty(context.MediaFile?.Url);

var newMessageFileIsEmpty = context.MediaFile is InputMediaDocument;

return context.PreviousMessage.Photo == null && newMessageFileIsEmpty;
}

Expand Down
Expand Up @@ -17,9 +17,8 @@ public MediaToMediaFileStrategy(BotfBot bot)

public bool CanHandle(IUpdateMessageContext context)
{
var newMessageHasFile = !string.IsNullOrEmpty(context.MediaFile?.FileId) ||
!string.IsNullOrEmpty(context.MediaFile?.Url);

var newMessageHasFile = context.MediaFile is InputMediaDocument;

return context.PreviousMessage.Photo != null && newMessageHasFile;
}

Expand All @@ -31,7 +30,8 @@ public async Task<Message> UpdateMessage(IUpdateMessageContext context)
await _bot.Client.DeleteMessageAsync(context.ChatId, context.PreviousMessage.MessageId, context.CancelToken);
return await _bot.Client.SendPhotoAsync(
context.ChatId,
context.MediaFile!,
context.MediaFile!.Media,
null,
context.MessageText,
context.ParseMode,
replyMarkup: context.KeyboardMarkup,
Expand All @@ -43,7 +43,7 @@ public async Task<Message> UpdateMessage(IUpdateMessageContext context)
return await _bot.Client.EditMessageMediaAsync(
context.ChatId,
context.MessageId,
new InputMediaPhoto(context.MediaFile!)
new InputMediaPhoto(context.MediaFile!.Media)
{
Caption = context.MessageText,
ParseMode = context.ParseMode
Expand Down
Expand Up @@ -17,9 +17,8 @@ public MediaToPlainTextStrategy(BotfBot bot)

public bool CanHandle(IUpdateMessageContext context)
{
var newMessageFileIsEmpty = string.IsNullOrEmpty(context.MediaFile?.FileId) &&
string.IsNullOrEmpty(context.MediaFile?.Url);

var newMessageFileIsEmpty = context.MediaFile is InputMediaDocument;

return context.PreviousMessage.Photo != null && newMessageFileIsEmpty;
}

Expand All @@ -29,6 +28,7 @@ public async Task<Message> UpdateMessage(IUpdateMessageContext context)
return await _bot.Client.SendTextMessageAsync(
context.ChatId,
context.MessageText,
null,
context.ParseMode,
replyMarkup: context.KeyboardMarkup,
cancellationToken: context.CancelToken,
Expand Down
Expand Up @@ -17,9 +17,8 @@ public PlainTextToMediaStrategy(BotfBot bot)

public bool CanHandle(IUpdateMessageContext context)
{
var newMessageHasFile = !string.IsNullOrEmpty(context.MediaFile?.FileId) ||
!string.IsNullOrEmpty(context.MediaFile?.Url);

var newMessageHasFile = context.MediaFile is InputMediaDocument;

return context.PreviousMessage.Photo == null && newMessageHasFile;
}

Expand All @@ -28,7 +27,8 @@ public async Task<Message> UpdateMessage(IUpdateMessageContext context)
await _bot.Client.DeleteMessageAsync(context.ChatId, context.PreviousMessage.MessageId, context.CancelToken);
return await _bot.Client.SendPhotoAsync(
context.ChatId,
context.MediaFile!,
context.MediaFile!.Media,
null,
context.MessageText,
context.ParseMode,
replyMarkup: context.KeyboardMarkup,
Expand Down

0 comments on commit aa8144d

Please sign in to comment.