Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        bool RegisterNewUsers(Update[] result)
        {
            bool registered = false;

            foreach (Update upd in result)
            {
                if (upd.Message == null || string.IsNullOrEmpty(upd.Message.Text))
                {
                    continue;
                }
                if (upd.Message.Text.Trim() == "/regme " + RegistrationCode)
                {
                    registered = true;
                    long chatId = upd.Message.Chat.Id;
                    if (Clients.Values.FirstOrDefault(c => c.ChatId.Identifier == chatId) != null)
                    {
                        ClientRegistered.Invoke(this, new TelegramClientInfoEventArgs()
                        {
                            Client = Clients.Values.FirstOrDefault(c => c.ChatId.Identifier == chatId)
                        });
                        continue;
                    }

                    TelegramClientInfo clientInfo = new TelegramClientInfo();
                    clientInfo.ChatId           = new ChatId(chatId);
                    clientInfo.ClientId         = RegistrationId;
                    clientInfo.RegistrationCode = RegistrationCode;
                    clientInfo.Enabled          = true;

                    Clients.Add(chatId, clientInfo);
                    if (ClientRegistered != null)
                    {
                        ClientRegistered.Invoke(this, new TelegramClientInfoEventArgs()
                        {
                            Client = clientInfo
                        });
                    }
                }
            }
            if (!registered)
            {
                Telemetry.Default.TrackEvent("Telegram bot not recv /regme command");
                Telemetry.Default.Flush();
            }
            return(true);
        }