This repository was archived by the owner on May 2, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Configuring bot with console hosting
Mikhail edited this page Jan 11, 2021
·
3 revisions
In the case of using console hosting, bot will use LongPolling to receive updates.
Sample code:
static void Main(string args)
{
ConsoleBotHost consoleBotHost = ConsoleBotHost
.CreateDefault(args)
.WithBot(BuildMyBot);
consoleBotHost.OnBotStarted += (o, e) => Console.WriteLine("Bot has been started.");
consoleBotHost.OnBotStopped += (o, e) => Console.WriteLine("Bot has been stopped.");
consoleBotHost.OnUpdateProcessed += (o, e) =>
Console.WriteLine(
$"Update with id {e.ProcessingResult.Update.Id} and {e.ProcessingResult.Update.Type} type has been processed in {e.ProcessingResult.Time}.");
consoleBotHost.OnErrorOccured += (o, e) =>
Console.WriteLine(e.Exception, "An error was occured when receiving/processing an update.");
consoleBotHost.Run();
while (true)
{
System.Console.ReadKey();
consoleBotHost.Stop();
}
}
public IBot BuildMyBot(BotConfigurationOptions options)
{
//Configure bot here.
}
In this case, your application should start with command line parameters like: MyBotApp.exe --apiToken Your_Bot_Api_Token --botName YourBotName.