Skip to content

Commit 348b890

Browse files
[~] Telegram Bot updated
1 parent 75b3465 commit 348b890

File tree

4 files changed

+53
-60
lines changed

4 files changed

+53
-60
lines changed

AniWorldReminder_API/AniWorldReminder_API.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@
1919
<PackageReference Include="Swashbuckle.AspNetCore" Version="8.1.0" />
2020
<PackageReference Include="System.Drawing.Common" Version="9.0.3" />
2121
<PackageReference Include="System.IdentityModel.Tokens.Jwt" Version="8.7.0" />
22-
<PackageReference Include="System.Text.Json" Version="9.0.3" />
23-
<PackageReference Include="Telegram.Bot" Version="19.0.0" />
22+
<PackageReference Include="Telegram.Bot" Version="22.4.4" />
2423
</ItemGroup>
2524

2625
</Project>

AniWorldReminder_API/Interfaces/ITelegramBotService.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ namespace AniWorldReminder_API.Interfaces
77
public interface ITelegramBotService
88
{
99
Task<bool> Init();
10-
Task<Message?> SendMessageAsync(long chatId, string text, int? replyId = null, bool showLinkPreview = true, ParseMode parseMode = ParseMode.Html, bool silentMessage = false, ReplyKeyboardMarkup? rkm = null);
11-
Task SendChatAction(long chatId, ChatAction chatAction);
10+
Task<Message?> SendMessageAsync(long chatId, string text, bool showLinkPreview = true, ParseMode parseMode = ParseMode.Html, bool silentMessage = false, ReplyKeyboardMarkup? rkm = null);
1211
Task<Message?> SendPhotoAsync(long chatId, string photoUrl, string? text = null, ParseMode parseMode = ParseMode.Html, bool silentMessage = false);
1312
}
1413
}

AniWorldReminder_API/Models/AniListSearchMediaResponseModel.cs

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,143 +1,143 @@
1-
using Newtonsoft.Json;
1+
using System.Text.Json.Serialization;
22

33
namespace AniWorldReminder_API.Models
44
{
55
// Root myDeserializedClass = JsonConvert.DeserializeObject<Root>(myJsonResponse);
66
public class CoverImage
77
{
8-
[JsonProperty("large")]
8+
[JsonPropertyName("large")]
99
public string? Large { get; set; }
1010

11-
[JsonProperty("medium")]
11+
[JsonPropertyName("medium")]
1212
public string? Medium { get; set; }
1313

14-
[JsonProperty("color")]
14+
[JsonPropertyName("color")]
1515
public string? Color { get; set; }
1616
}
1717

1818
public class Data
1919
{
20-
[JsonProperty("Page")]
20+
[JsonPropertyName("Page")]
2121
public Page? Page { get; set; }
2222
}
2323

2424
public class EndDate
2525
{
26-
[JsonProperty("year")]
26+
[JsonPropertyName("year")]
2727
public int? Year { get; set; }
2828

29-
[JsonProperty("month")]
29+
[JsonPropertyName("month")]
3030
public int? Month { get; set; }
3131

32-
[JsonProperty("day")]
32+
[JsonPropertyName("day")]
3333
public int? Day { get; set; }
3434
}
3535

3636
public class Medium
3737
{
38-
[JsonProperty("id")]
38+
[JsonPropertyName("id")]
3939
public int? Id { get; set; }
4040

41-
[JsonProperty("title")]
41+
[JsonPropertyName("title")]
4242
public Title? Title { get; set; }
4343

44-
[JsonProperty("coverImage")]
44+
[JsonPropertyName("coverImage")]
4545
public CoverImage? CoverImage { get; set; }
4646

47-
[JsonProperty("startDate")]
47+
[JsonPropertyName("startDate")]
4848
public StartDate? StartDate { get; set; }
4949

50-
[JsonProperty("endDate")]
50+
[JsonPropertyName("endDate")]
5151
public EndDate? EndDate { get; set; }
5252

53-
[JsonProperty("season")]
53+
[JsonPropertyName("season")]
5454
public string? Season { get; set; }
5555

56-
[JsonProperty("seasonYear")]
56+
[JsonPropertyName("seasonYear")]
5757
public int? SeasonYear { get; set; }
5858

59-
[JsonProperty("description")]
59+
[JsonPropertyName("description")]
6060
public string? Description { get; set; }
6161

62-
[JsonProperty("type")]
62+
[JsonPropertyName("type")]
6363
public string? Type { get; set; }
6464

65-
[JsonProperty("format")]
65+
[JsonPropertyName("format")]
6666
public string? Format { get; set; }
6767

68-
[JsonProperty("status")]
68+
[JsonPropertyName("status")]
6969
public string? Status { get; set; }
7070

71-
[JsonProperty("episodes")]
71+
[JsonPropertyName("episodes")]
7272
public int? Episodes { get; set; }
7373

74-
[JsonProperty("duration")]
74+
[JsonPropertyName("duration")]
7575
public int? Duration { get; set; }
7676

77-
[JsonProperty("genres")]
77+
[JsonPropertyName("genres")]
7878
public List<string>? Genres { get; set; }
7979

80-
[JsonProperty("isAdult")]
80+
[JsonPropertyName("isAdult")]
8181
public bool? IsAdult { get; set; }
8282

83-
[JsonProperty("averageScore")]
83+
[JsonPropertyName("averageScore")]
8484
public decimal? AverageScore { get; set; }
8585

86-
[JsonProperty("nextAiringEpisode")]
86+
[JsonPropertyName("nextAiringEpisode")]
8787
public object? NextAiringEpisode { get; set; }
8888
}
8989

9090
public class Page
9191
{
92-
[JsonProperty("pageInfo")]
92+
[JsonPropertyName("pageInfo")]
9393
public PageInfo? PageInfo { get; set; }
9494

95-
[JsonProperty("media")]
95+
[JsonPropertyName("media")]
9696
public List<Medium>? Media { get; set; }
9797
}
9898

9999
public class PageInfo
100100
{
101-
[JsonProperty("total")]
101+
[JsonPropertyName("total")]
102102
public int? Total { get; set; }
103103

104-
[JsonProperty("perPage")]
104+
[JsonPropertyName("perPage")]
105105
public int? PerPage { get; set; }
106106

107-
[JsonProperty("currentPage")]
107+
[JsonPropertyName("currentPage")]
108108
public int? CurrentPage { get; set; }
109109

110-
[JsonProperty("lastPage")]
110+
[JsonPropertyName("lastPage")]
111111
public int? LastPage { get; set; }
112112

113-
[JsonProperty("hasNextPage")]
113+
[JsonPropertyName("hasNextPage")]
114114
public bool? HasNextPage { get; set; }
115115
}
116116

117117
public class AniListSearchMediaResponseModel
118118
{
119-
[JsonProperty("data")]
119+
[JsonPropertyName("data")]
120120
public Data? Data { get; set; }
121121
}
122122

123123
public class StartDate
124124
{
125-
[JsonProperty("year")]
125+
[JsonPropertyName("year")]
126126
public int? Year { get; set; }
127127

128-
[JsonProperty("month")]
128+
[JsonPropertyName("month")]
129129
public int? Month { get; set; }
130130

131-
[JsonProperty("day")]
131+
[JsonPropertyName("day")]
132132
public int? Day { get; set; }
133133
}
134134

135135
public class Title
136136
{
137-
[JsonProperty("english")]
137+
[JsonPropertyName("english")]
138138
public string? English { get; set; }
139139

140-
[JsonProperty("userPreferred")]
140+
[JsonPropertyName("userPreferred")]
141141
public string? UserPreferred { get; set; }
142142
}
143143

AniWorldReminder_API/Services/TelegramBotService.cs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public async Task<bool> Init()
1515
{
1616
TelegramBotSettingsModel? settings = SettingsHelper.ReadSettings<TelegramBotSettingsModel>();
1717

18-
if (settings is null)
18+
if(settings is null)
1919
{
2020
logger.LogError($"{DateTime.Now} | {ErrorMessage.ReadSettings}");
2121
return false;
@@ -25,15 +25,15 @@ public async Task<bool> Init()
2525

2626
try
2727
{
28-
User? bot_me = await BotClient.GetMeAsync();
28+
User? bot_me = await BotClient.GetMe();
2929

30-
if (bot_me is null)
30+
if(bot_me is null)
3131
{
3232
logger.LogError($"{DateTime.Now} | {ErrorMessage.RetrieveBotInfo}");
3333
return false;
3434
}
3535
}
36-
catch (Exception ex)
36+
catch(Exception ex)
3737
{
3838
logger.LogError($"{DateTime.Now} | {ex}");
3939
return false;
@@ -46,24 +46,19 @@ public async Task<bool> Init()
4646

4747
return true;
4848
}
49-
public async Task SendChatAction(long chatId, ChatAction chatAction)
50-
{
51-
await BotClient.SendChatActionAsync(chatId, chatAction);
52-
}
53-
public async Task<Message?> SendMessageAsync(long chatId, string text, int? replyId = null, bool showLinkPreview = true, ParseMode parseMode = ParseMode.Html, bool silentMessage = false, ReplyKeyboardMarkup? rkm = null)
49+
public async Task<Message?> SendMessageAsync(long chatId, string text, bool showLinkPreview = true, ParseMode parseMode = ParseMode.Html, bool silentMessage = false, ReplyKeyboardMarkup? rkm = null)
5450
{
5551
try
5652
{
57-
return await BotClient.SendTextMessageAsync(
53+
return await BotClient.SendMessage(
5854
chatId: chatId,
5955
text: text.HtmlDecode(),
60-
replyToMessageId: replyId,
6156
parseMode: parseMode,
62-
disableWebPagePreview: !showLinkPreview,
57+
linkPreviewOptions: new() { IsDisabled = !showLinkPreview },
6358
replyMarkup: rkm,
6459
disableNotification: silentMessage);
6560
}
66-
catch (Exception)
61+
catch(Exception)
6762
{
6863
return null;
6964
}
@@ -73,12 +68,12 @@ public async Task SendChatAction(long chatId, ChatAction chatAction)
7368
const string base64Prefix = "data:image/png;base64,";
7469

7570
try
76-
{
77-
if (photoUrl.Trim().StartsWith(base64Prefix))
71+
{
72+
if(photoUrl.Trim().StartsWith(base64Prefix))
7873
{
7974
photoUrl = photoUrl.Replace(base64Prefix, "");
8075

81-
return await BotClient.SendPhotoAsync(
76+
return await BotClient.SendPhoto(
8277
chatId,
8378
new InputFileStream(new MemoryStream(Convert.FromBase64String(photoUrl))),
8479
caption: text.HtmlDecode(),
@@ -87,15 +82,15 @@ public async Task SendChatAction(long chatId, ChatAction chatAction)
8782
}
8883
else
8984
{
90-
return await BotClient.SendPhotoAsync(
85+
return await BotClient.SendPhoto(
9186
chatId,
9287
new InputFileUrl(photoUrl),
9388
caption: text.HtmlDecode(),
9489
parseMode: parseMode,
9590
disableNotification: silentMessage);
9691
}
9792
}
98-
catch (Exception)
93+
catch(Exception)
9994
{
10095
return await SendMessageAsync(chatId, text, parseMode: parseMode);
10196
}

0 commit comments

Comments
 (0)