techlift-tech / TelegramBotForPokerAnalysis

0 stars 0 forks source link

Get registered commands for from telegram #7 #9

Open palashjhabak opened 3 years ago

palashjhabak commented 3 years ago

7

Lets start with coding now and finish the part to get all the commands currently registered with telegram for the bot. this we should call whenever the service starts and later probably after every hour or so.

disha-2401 commented 3 years ago

we can first get all commands registered using GetMyCommandsAsync() method as : -

var commands = botClient.GetMyCommandsAsync().Result;
            for (int i = 0; i < commands.Count(); ++i)
            {
                Console.WriteLine(commands[i].Command);
            }

the GetMyCommandsAsync() on bot will return json format as : -

"result": [
{
"command": "command1",
"description": "Description"
},
{
"command": "command2",
"description": "Another description"
}
]

we can configure all this in Program.cs file so that it performs when we start the app.

palashjhabak commented 3 years ago

we can first get all commands registered using GetMyCommandsAsync() method as : -

var commands = botClient.GetMyCommandsAsync().Result;
            for (int i = 0; i < commands.Count(); ++i)
            {
                Console.WriteLine(commands[i].Command);
            }

the GetMyCommandsAsync() on bot will return json format as : -

"result": [
{
"command": "command1",
"description": "Description"
},
{
"command": "command2",
"description": "Another description"
}
]

we can configure all this in Program.cs file so that it performs when we start the app.

doing it in Program.cs is a bad idea. We should create a new class and have it registered as a singleton class as dependency injection and in that we can have a timer run every 1 hour or so to check this and perform our action.

disha-2401 commented 3 years ago

can you show me how I can use our new class to run on startup?

palashjhabak commented 3 years ago

can you show me how I can use our new class to run on startup?

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-5.0#call-services-from-main

@disha-2401 check the above link so you will have to register your class as a singleton service in configureservices and call a method from that service in Main class by getting the registered service.