Esempio n. 1
0
 static void Main(string[] args)
 {
     TelegramMessager.InsertNewApi("440765294:AAG7iqMKrsr6vB2px37ZTTk35m0K7Z902Ag");
     TelegramMessager.IsStop = false;
     TelegramMessager.RunAsync().GetAwaiter();
     Console.ReadKey();
 }
Esempio n. 2
0
        public static async Task RunAsync()
        {
            // Used for getting only the unconfirmed updates.
            // It is recommended to stored this value between sessions.
            // More information at https://core.telegram.org/bots/api#getting-updates
            var offset = 0L;

            while (!IsStop)
            {
                // Use this method to receive incoming updates using long polling.
                // Or use Telebot.SetWebhook() method to specify a URL to receive incoming updates.
                TimeBeforeUpdate = 0;
                Token            = new CancellationToken(false);

                try
                {
                    List <Update> updates = (await _telebot.GetUpdatesAsync(offset: offset, limit: 2, timeout: 2, cancellationToken: Token).ConfigureAwait(false)).ToList();
                    if (updates.Any())
                    {
                        offset = updates.Max(u => u.Id) + 1;

                        foreach (Update update in updates)
                        {
                            switch (update.Type)
                            {
                            case UpdateType.Message:
                                await TelegramMessager.CheckMessagesAsync(update.Message).ConfigureAwait(false);

                                break;

                            case UpdateType.InlineQuery:
                                await TelegramMessager.CheckInlineQueryAsync(update).ConfigureAwait(false);

                                break;

                            case UpdateType.ChosenInlineResult:
                                TelegramMessager.CheckChosenInlineResult(update);
                                break;

                            default:
                                throw new ArgumentOutOfRangeException();
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Thread.Sleep(5000);
                }
                await Task.Delay(TimeSpan.FromSeconds(1)).ConfigureAwait(false);
            }
        }