Telegram.Bot icon indicating copy to clipboard operation
Telegram.Bot copied to clipboard

Create implicit convertation between ChatId and Update

Open DmytroSH opened this issue 5 years ago • 1 comments

I would like to request/propose a feature

So usually i do stuff like that to send response

 public async Task Reply(TelegramBotClient client, Update hook)
 {
        await client.SendTextMessageAsync(
                hook.Message.Chat.Id, "Hello World");
 }

But I think it will be good to send message without hardcode chat id position because sometimes it can vary by message type, so i create extension method to retrieve ChatId from hook, but i think its better to have implicit convertion between Update and ChatId so i can use method like this:

 public async Task Reply(TelegramBotClient client, Update hook)
 {
        await client.SendTextMessageAsync(
                hook, "Hello World");
 }

UPDT: or extension method That's great. Let us know what's on on your mind and please try to be specific.

You also can chat with us on Telegram @tgbots_dotnet

DmytroSH avatar May 22 '20 10:05 DmytroSH

Main issue what you wanna do in case where update doesn`t have any chatId/FromId.

My suggestion - add extension methods:

User? GetUser(this Update update); 
Chat? GetChat(this Update update);

Which will return corresponding objects if they exist (or sender != anonymous user) after that you can easily implement methods that you need with Reply if chat exists and handle situation when there is none.

Additionally those methods useful while logging/user authorization, etc.

Fedorus avatar Nov 11 '20 03:11 Fedorus