Skip to content

Commit 1b25d7c

Browse files
LeftTwixWandclaude
andauthored
feat: auto-register Telegram bot commands on startup via SetMyCommands (#15)
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent c6d473c commit 1b25d7c

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

src/Clients.Telegram/WebhookSetupService.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using System.Text.Json;
33
using Telegram;
44
using Telegram.BotAPI;
5+
using Telegram.BotAPI.AvailableMethods;
6+
using Telegram.BotAPI.AvailableTypes;
57
using Telegram.BotAPI.GettingUpdates;
68

79
namespace TelegramClient;
@@ -36,13 +38,36 @@ await botClient.SetWebhookAsync(
3638
cancellationToken: ct);
3739

3840
logger.LogInformation("Webhook registered: {Url}", webhookUrl);
41+
42+
await RegisterBotCommandsAsync(ct);
3943
}
4044
catch (Exception ex)
4145
{
4246
logger.LogError(ex, "Failed to set webhook at {Url}", webhookUrl);
4347
}
4448
}
4549

50+
private async Task RegisterBotCommandsAsync(CancellationToken ct)
51+
{
52+
try
53+
{
54+
BotCommand[] commands =
55+
[
56+
new("/start", "Set up topics and get started"),
57+
new("/newchat", "Start a fresh conversation"),
58+
new("/clear", "Reset conversation in current topic"),
59+
new("/status", "Show agent and system status"),
60+
new("/cleanup", "Clean up old messages"),
61+
];
62+
await botClient.SetMyCommandsAsync(commands, cancellationToken: ct);
63+
logger.LogInformation("Registered {Count} bot commands", commands.Length);
64+
}
65+
catch (Exception ex)
66+
{
67+
logger.LogWarning(ex, "Failed to register bot commands");
68+
}
69+
}
70+
4671
private async Task<string?> ResolveNgrokUrlAsync(string ngrokApiUrl, CancellationToken ct)
4772
{
4873
// Ngrok may take a few seconds to start — retry with backoff

0 commit comments

Comments
 (0)