Esempio n. 1
0
 private void BuildUserTokenRequest()
 {
     _userInteractionService.AddUserInteractionData(new UserInteractionData
     {
         Name   = "SPOTIFY",
         Fields = new List <UserInteractionField>
         {
             new UserInteractionField().Build()
             .SetFieldName("AUTH_URL")
             .SetFieldValue(GenerateOAuthToken(_spotifyScopes))
             .SetFieldType(UserInteractionFieldTypeEnum.LINK)
             .SetDescription("Click on link for authorize spotify API").SetIsRequired(true)
         }
     }, data => { });
 }
Esempio n. 2
0
        public async Task <bool> Start()
        {
            if (string.IsNullOrEmpty(_config.BridgeIpAddress))
            {
                _logger.LogInformation("Searching from Philip Hue bridge...");

                var bridgeIps = await _bridgeLocator.LocateBridgesAsync(TimeSpan.FromSeconds(10));

                if (bridgeIps.Any())
                {
                    _logger.LogInformation($"Found {bridgeIps.Count()} bridges");

                    _hueClient = new LocalHueClient(bridgeIps.ToList()[0].IpAddress);

                    _config.BridgeIpAddress = bridgeIps.ToList()[0].IpAddress;

                    _logger.LogInformation("Button pressed");
                    var appKey = await _hueClient.RegisterAsync("LeonHomeControl", "Leon");

                    _config.ApiKey = appKey;

                    _componentsService.SaveComponentConfig(_config);

                    _hueClient.Initialize(appKey);

                    _logger.LogInformation("Philip Hue Configured");

                    _hueClient = new LocalHueClient(_config.BridgeIpAddress, _config.ApiKey);

                    _logger.LogInformation("Connected to Philip Hue");

                    var lights = await _hueClient.GetLightsAsync();

                    lights.ToList().ForEach(s => { _logger.LogInformation($"{s.Name}"); });
                    var groups = await _hueClient.GetGroupsAsync();

                    groups.ToList().ForEach(g => { _logger.LogInformation($"{g.Name}"); });
                }
            }
            else
            {
                _hueClient = new LocalHueClient(_config.BridgeIpAddress);

                if (string.IsNullOrEmpty(_config.ApiKey))
                {
                    _userInteractionService.AddUserInteractionData(new UserInteractionData
                    {
                        Name   = "Philip hue component",
                        Fields = new List <UserInteractionField>
                        {
                            new UserInteractionField().Build().SetIsRequired(true)
                            .SetFieldType(UserInteractionFieldTypeEnum.BUTTON)
                            .SetFieldName("PHILIP_HUE_BUTTON_PRESS")
                            .SetDescription("Press Philip hue button for link bride")
                        }
                    }, async data => { });
                }
                else
                {
                    _hueClient = new LocalHueClient(_config.BridgeIpAddress, _config.ApiKey);

                    _logger.LogInformation("Connected to Philip Hue");

                    _schedulerService.AddPolling(UpdateEntities, "PhiipHue_UpdateLightEntities",
                                                 SchedulerServicePollingEnum.NORMAL_POLLING);
                }
            }

            return(true);
        }
Esempio n. 3
0
        public async Task <bool> Start()
        {
            if (_telegramConfig.ApiKey == "change_me")
            {
                _logger.LogError($"Telegram notifier need api on config!");
                _userInteractionService.AddUserInteractionData(new UserInteractionData()
                {
                    Name   = GetType().Name,
                    Fields = new List <UserInteractionField>()
                    {
                        new UserInteractionField()
                        {
                            FieldName = "Api key", Description = "Telegram bot Api key", FieldType = UserInteractionFieldTypeEnum.String, IsRequired = true,
                        }
                    }
                }, data =>
                {
                });

                return(false);
            }
            else
            {
                _persistenceConnector = _noSqlService.GetNoSqlConnector(_telegramConfig.PersistenceConnector);
                await _persistenceConnector.Configure(Path.Combine(_neonConfig.NotifierConfig.DirectoryConfig.DirectoryName,
                                                                   "telegram.json"));

                _telegramBotClient = new TelegramBotClient(_telegramConfig.ApiKey);
                _logger.LogInformation($"Connecting to telegram");
                var user = await _telegramBotClient.GetMeAsync();

                _logger.LogInformation($"Telegram connected, Write me @{user.Username}");

                _telegramBotClient.OnMessage += async(sender, args) =>
                {
                    if (args.Message.Text != null)
                    {
                        _logger.LogDebug($"Message from @{args.Message.From.Username}: {args.Message.Text}");

                        if (args.Message.Text.ToLower() == "/version")
                        {
                            await SendVersion(args.Message.Chat.Id);
                        }

                        if (args.Message.Text.ToLower() == "/help")
                        {
                            await SendHelp(args.Message.Chat.Id);
                        }

                        if (args.Message.Text.ToLower() == "/myip")
                        {
                            await SendMyIp(args.Message.Chat.Id);
                        }

                        if (args.Message.Text.ToLower().StartsWith("/exec"))
                        {
                            await ExecuteCode(args.Message.Chat.Id, args.Message.Text);
                        }

                        if (args.Message.Text.ToLower() == "/enable_notify")
                        {
                            await EnableNotification(args.Message.Chat.Id);
                        }
                    }
                };
                _telegramBotClient.StartReceiving();
            }

            return(true);
        }