Exemplo n.º 1
0
        public void UpdateCommands()
        {
            if (BroadcastId == null)
            {
                return;
            }
            Task t = InnerClient.GetUpdatesAsync(0, 2, 0, new Telegram.Bot.Types.Enums.UpdateType[] { Telegram.Bot.Types.Enums.UpdateType.All }).ContinueWith(task => {
                foreach (Update upd in task.Result)
                {
                    if (upd.Message.Date <= LastCommandTime)
                    {
                        continue;
                    }
                    LastCommandTime = upd.Message.Date;
                    if (upd.Message.Chat.Id == BroadcastId.Identifier)
                    {
                        if (upd.Message.Text == "/stopit!")
                        {
                            IsActive = false;
                            InnerClient.SendTextMessageAsync(BroadcastId, "I am stopped!");
                        }
                        if (upd.Message.Text == "/startit")
                        {
                            IsActive = true;
                            InnerClient.SendTextMessageAsync(BroadcastId, "I am started!");
                        }
                        break;
                    }
                }
            });

            t.Wait(10000);
        }
Exemplo n.º 2
0
        public void SendNotification(string text, long chatId)
        {
            TelegramClientInfo client = null;

            Clients.TryGetValue(chatId, out client);
            if (client == null || !client.Enabled)
            {
                return;
            }

            InnerClient.SendTextMessageAsync(client.ChatId, text, Telegram.Bot.Types.Enums.ParseMode.Html);
        }
Exemplo n.º 3
0
 bool RegisterNewUsers(Update[] result)
 {
     foreach (Update upd in result)
     {
         if (upd.Message.Text.Trim() == "/regme " + RegistrationCode)
         {
             BroadcastId = upd.Message.Chat.Id;
             XtraMessageBox.Show("Telegram bot successfully registered!");
             InnerClient.SendTextMessageAsync(BroadcastId, "Hello my friend!");
             SettingsStore.Default.TelegramBotBroadcastId = BroadcastId.Identifier;
             IsActive = true;
             return(true);
         }
     }
     return(false);
 }