Skip to content

Commit 63ea369

Browse files
committed
chore: Update BotControllerBase to include User and Update properties
1 parent 86d54a8 commit 63ea369

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

Sources/TelegramBot/BotApp.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ private async Task UpdateHandler(ITelegramBotClient client, Update update, Cance
9191
{
9292
if (botCommandAttribute.Command == command)
9393
{
94+
controller.Update = update;
95+
controller.User = update.Message.From;
9496
var result = method.Invoke(controller, new object[] { });
9597
if (result is Task<IActionResult> taskResult)
9698
{

Sources/TelegramBot/Controllers/BotControllerBase.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
using System;
22
using System.Linq;
3-
using Telegram.Bot.Types.ReplyMarkups;
3+
using Telegram.Bot.Types;
44
using TelegramBot.Abstractions;
55
using TelegramBot.ActionResults;
6+
using Telegram.Bot.Types.ReplyMarkups;
67

78
namespace TelegramBot.Controllers
89
{
@@ -11,6 +12,16 @@ namespace TelegramBot.Controllers
1112
/// </summary>
1213
public abstract class BotControllerBase
1314
{
15+
/// <summary>
16+
/// User who sent the update.
17+
/// </summary>
18+
public User User { get; set; } = null!;
19+
20+
/// <summary>
21+
/// Update received from the user.
22+
/// </summary>
23+
public Update Update { get; set; } = null!;
24+
1425
/// <summary>
1526
/// Sends a text message to the sender.
1627
/// </summary>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using Telegram.Bot.Types;
5+
6+
namespace TelegramBot.Extensions
7+
{
8+
/// <summary>
9+
/// Extension methods for <see cref="Update"/>.
10+
/// </summary>
11+
public static class TelegramUpdateExtensions
12+
{
13+
/// <summary>
14+
/// Determines whether the update is a text message.
15+
/// </summary>
16+
/// <param name="update">Telegram update.</param>
17+
/// <returns>If the update is a text message, returns true; otherwise, false.</returns>
18+
public static bool IsTextMessage(this Update update)
19+
{
20+
return update.Message?.Text != null;
21+
}
22+
23+
/// <summary>
24+
/// Determines whether the update is an inline query.
25+
/// </summary>
26+
/// <param name="update">Telegram update.</param>
27+
/// <returns>If the update is an inline query, returns true; otherwise, false.</returns>
28+
public static bool IsInlineQuery(this Update update)
29+
{
30+
return update.InlineQuery != null;
31+
}
32+
}
33+
}

0 commit comments

Comments
 (0)