Open palashjhabak opened 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.
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.
can you show me how I can use our new class to run on startup?
can you show me how I can use our new class to run on startup?
@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.
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.