コード例 #1
0
        private static async Task WatchExpression(ChatSession session)
        {
            var result = JintService.TestExpression(session.CurrentMessage.Trim());

            switch (result)
            {
            case EvaluationResult.INVALID:
                await TelegramBotManager.SendMessage(session.ChatId, "Expresion invalida, verificar identificadores");

                break;

            case EvaluationResult.NOT_BOOLEAN:
                await TelegramBotManager.SendMessage(session.ChatId, "Esta expresion no es booleana");

                break;

            case EvaluationResult.NO_CONTAINS_VAL:
                await TelegramBotManager.SendMessage(session.ChatId, "Esta expresion no contiene el identificador");

                break;

            case EvaluationResult.SUCCESS:
                session.SelectedWatch.Expression = session.CurrentMessage.Trim();
                await TelegramBotManager.SendMessage(session.ChatId, "Expresion valida, Que mensaje quieres que se envie al cumplirse esta condicion");

                session.Status = ChatStatus.WATCH_MESSAGE;
                break;

            default:
                break;
            }
        }
コード例 #2
0
        private static async Task AskRegister(ChatSession session)
        {
            if (session.CurrentMessage == SI)
            {
                User new_usr = new User()
                {
                    ChatId = session.ChatId, Username = session.Username, Token = CreateToken(session.ChatId)
                };
                await DataService.Users.InsertUser(new_usr);

                await TelegramBotManager.SendMessage(session.ChatId, $"Has sido registrado, tu token es : {new_usr.Token}");

                session.Status = ChatStatus.USER_EXISTS;
                await UserExists(session);
            }
            else if (session.CurrentMessage == NO)
            {
                await TelegramBotManager.SendMessage(session.ChatId, "De acuerdo, si deseas registrarte en otro momento, mandame un mensaje");

                session.Status = ChatStatus.NEW;
            }
            else
            {
                await TelegramBotManager.SendMessage(session.ChatId, "Entrada no valida");

                session.Status = session.PreviousStatus;
            }
        }
コード例 #3
0
        private static async Task ControlSelected(ChatSession session)
        {
            switch (session.CurrentMessage)
            {
            case CONTROLAR:
                await TelegramBotManager.SendMessage(session.ChatId, "Que accion deseas realizar?", ControlDeviceMenu);

                session.Status = ChatStatus.CONTROL_DEVICE;
                break;

            case ACTUALIZAR:
                await TelegramBotManager.SendMessage(session.ChatId, "Cual sera el nuevo nombre del Control?");

                session.Status = ChatStatus.CONTROL_RENAMING;
                break;

            case REGRESAR:
                session.SelectedControl = null;
                await TelegramBotManager.SendMessage(session.ChatId, $"Dispositivo seleccionado ({session.SelectedDevice.KeyItem})", DeviceMenuKeyboard);

                session.Status = ChatStatus.DEVICE_SELECTED;
                break;

            case ELIMINAR:
                await TelegramBotManager.SendMessage(session.ChatId, "Estas seguro que deseas eliminar este control?", SiNoKeyboard);

                session.Status = ChatStatus.CONTROL_ASK_ELIMINATION;
                break;

            default:
                await TelegramBotManager.SendMessageSameKeyboard(session.ChatId, "Entrada no valida");

                break;
            }
        }
コード例 #4
0
 private static async Task WatchNaming(ChatSession session)
 {
     session.SelectedWatch      = session.IsUpdatingWatch ? session.SelectedWatch : new Watch();
     session.SelectedWatch.Name = session.CurrentMessage.Trim();
     session.Status             = ChatStatus.WATCH_EXPRESSION;
     await TelegramBotManager.SendMessage(session.ChatId, "Que expresion se va a evaluar para mandar el mensaje? ( usar 'val' como variable de la metrica ejemplo val > 30)");
 }
コード例 #5
0
        private static async Task MainMenu(ChatSession session)
        {
            User usr;

            switch (session.CurrentMessage)
            {
            case CONSULTAR_TOKEN:
                usr = await DataService.Users.FindUserByUsername(session.Username);

                await TelegramBotManager.SendMessage(session.ChatId, $"Tu token es : {usr.Token}");
                await UserExists(session);

                break;

            case VER_DISPOSITIVOS:
                usr = await DataService.Users.FindUserByUsername(session.Username);

                var keyboard = await DevicesKeyboard(usr.UserId);

                await TelegramBotManager.SendMessage(session.ChatId, "Estos son tus dispositivos:", keyboard);

                session.Status = ChatStatus.DEVICES;
                break;

            default:
                await TelegramBotManager.SendMessage(session.ChatId, "Entrada no valida");

                session.Status = session.PreviousStatus;
                await UserExists(session);

                break;
            }
        }
コード例 #6
0
        private static async Task WatchSelected(ChatSession session)
        {
            switch (session.CurrentMessage)
            {
            case ACTUALIZAR:
                await TelegramBotManager.SendMessage(session.ChatId, "Cual sera el nuevo nombre del watch?");

                session.IsUpdatingWatch = true;
                session.Status          = ChatStatus.WATCH_NAMING;
                break;

            case ELIMINAR:
                await TelegramBotManager.SendMessage(session.ChatId, "Estas seguro que deseas eliminar este dispositivo?", SiNoKeyboard);

                session.Status = ChatStatus.WATCH_ASK_ELIMINATION;
                break;

            case REGRESAR:
                await TelegramBotManager.SendMessage(session.ChatId, $"Metrica ({session.SelectedMetric.KeyItem}), Que accion deseas realizar?", MetricsMenuKeyboard);

                session.Status = ChatStatus.METRIC_SELECTED;
                break;

            default:
                await TelegramBotManager.SendMessage(session.ChatId, "Entrada no valida", DeviceMenuKeyboard);

                break;
            }
        }
コード例 #7
0
        private static async Task ControlDevice(ChatSession session)
        {
            switch (session.CurrentMessage)
            {
            case ENCENDER:
            case APAGAR:
                ControlQueue controlQueueDesactivar = new ControlQueue()
                {
                    ControlId  = session.SelectedControl.ControlId,
                    InsertedAt = DateTime.UtcNow,
                    Value      = session.CurrentMessage == ENCENDER ? 1 : 0
                };
                await DataService.ControlQueues.InsertControlQueue(controlQueueDesactivar);

                await TelegramBotManager.SendMessage(session.ChatId, $"El control ({session.SelectedControl.KeyItem}) ha sido {(session.CurrentMessage == ENCENDER ? "encendido" : "apagado")}, Que deseas realizar?", ControlMenuKeyboard);

                session.Status = ChatStatus.CONTROL_SELECTED;
                break;

            case REGRESAR:
                await TelegramBotManager.SendMessage(session.ChatId, $"Control seleccionado ({session.SelectedControl.KeyItem})", ControlMenuKeyboard);

                session.Status = ChatStatus.CONTROL_SELECTED;
                break;


            default:
                await TelegramBotManager.SendMessageSameKeyboard(session.ChatId, "Entrada no valida");

                break;
            }
        }
コード例 #8
0
        private static async Task DeviceRenaming(ChatSession session)
        {
            session.SelectedDevice.Name = session.CurrentMessage.Trim();
            await DataService.Devices.UpdateDevice(session.SelectedDevice);

            session.Status = ChatStatus.DEVICE_SELECTED;
            await TelegramBotManager.SendMessage(session.ChatId, "Renombrado, Que accion deseas realizar", DeviceMenuKeyboard);
        }
コード例 #9
0
        private static async Task MetricNaming(ChatSession session)
        {
            session.SelectedMetric      = session.IsUpdatingMetric ? session.SelectedMetric : new Metric();
            session.SelectedMetric.Name = session.CurrentMessage.Trim();
            await TelegramBotManager.SendMessage(session.ChatId, "En que unidad esta descrita la metrica?");

            session.Status = ChatStatus.METRIC_UNIT_DESC;
        }
コード例 #10
0
        private static async Task ControlRenaming(ChatSession session)
        {
            session.SelectedControl.Name = session.CurrentMessage.Trim();
            await DataService.Controls.UpdateControl(session.SelectedControl);

            session.Status = ChatStatus.CONTROL_SELECTED;

            await TelegramBotManager.SendMessage(session.ChatId, $"Control actualizado ({session.SelectedControl.KeyItem}), que deseas realizar", ControlMenuKeyboard);
        }
コード例 #11
0
        private static async Task MetricSelected(ChatSession session)
        {
            switch (session.CurrentMessage)
            {
            case WATCHES:
                var keyboard = await WatchesKeyboard(session.SelectedMetric.MetricId);

                session.Status = ChatStatus.WATCHES;
                await TelegramBotManager.SendMessage(session.ChatId, "Estos son tus watches", keyboard);

                break;

            case REINICIAR_WATCHES:
                var watches = await DataService.Watches.WatchesByMetric(session.SelectedMetric.MetricId);

                session.Status = ChatStatus.METRIC_SELECTED;
                foreach (var watch in watches)
                {
                    watch.Sent = 0;
                    await DataService.Watches.UpdateWatch(watch);
                }
                await TelegramBotManager.SendMessage(session.ChatId, "Watches reiniciados", MetricsMenuKeyboard);

                break;

            case ACTUALIZAR:
                await TelegramBotManager.SendMessage(session.ChatId, "Cual sera el nuevo nombre de la metrica?");

                session.IsUpdatingMetric = true;
                session.Status           = ChatStatus.ADD_METRIC;
                break;

            case REGRESAR:
                session.SelectedMetric = null;
                await TelegramBotManager.SendMessage(session.ChatId, $"Dispositivo seleccionado ({session.SelectedDevice.KeyItem})", DeviceMenuKeyboard);

                session.Status = ChatStatus.DEVICE_SELECTED;
                break;

            case ELIMINAR:
                await TelegramBotManager.SendMessage(session.ChatId, "Estas seguro que deseas eliminar este dispositivo?", SiNoKeyboard);

                session.Status = ChatStatus.METRIC_ASK_ELIMINATION;
                break;

            default:
                break;
            }
        }
コード例 #12
0
        private static async Task AddControl(ChatSession session)
        {
            Control new_control = new Control
            {
                DeviceId = session.SelectedDevice.DeviceId,
                Name     = session.CurrentMessage,
            };
            await DataService.Controls.InsertControl(new_control);

            session.SelectedControl = new_control;
            session.Status          = ChatStatus.CONTROL_SELECTED;
            await TelegramBotManager.SendMessage(session.ChatId, $"Si quieres consultar las acciones de tu control GET a la siguiente direccion {Program.MainUrl}/api/control/{session.SelectedControl.ControlId}/TOKEN");

            await TelegramBotManager.SendMessage(session.ChatId, $"Control seleccionado ({session.SelectedControl.KeyItem}), que deseas realizar", ControlMenuKeyboard);
        }
コード例 #13
0
        private static async Task AddDevice(ChatSession session)
        {
            var usr = await DataService.Users.FindUserByUsername(session.Username);

            var new_dev = new Device()
            {
                UserId = usr.UserId,
                Name   = session.CurrentMessage.Trim()
            };
            await DataService.Devices.InsertDevice(new_dev);

            session.SelectedDevice = new_dev;

            session.Status = ChatStatus.DEVICE_SELECTED;
            await TelegramBotManager.SendMessage(session.ChatId, "Dispositivo nuevo anadido, Que deseas realizar", DeviceMenuKeyboard);
        }
コード例 #14
0
        private static async Task New(ChatSession session)
        {
            User usr = await DataService.Users.FindUserByUsername(session.Username);

            if (usr == null)
            {
                await TelegramBotManager.SendMessage(session.ChatId, "No existes en el registro, deseas registrarte?", SiNoKeyboard);

                session.Status = ChatStatus.ASK_REGISTER;
            }
            else
            {
                session.Status = ChatStatus.USER_EXISTS;
                await UserExists(session);
            }
        }
コード例 #15
0
        private static async Task WatchMessage(ChatSession session)
        {
            session.SelectedWatch.Message  = session.CurrentMessage.Trim();
            session.SelectedWatch.MetricId = session.SelectedMetric.MetricId;
            if (session.IsUpdatingWatch)
            {
                await DataService.Watches.UpdateWatch(session.SelectedWatch);
            }
            else
            {
                await DataService.Watches.InsertWatch(session.SelectedWatch);
            }

            session.Status = ChatStatus.WATCH_SELECTED;
            await TelegramBotManager.SendMessage(session.ChatId, $"Watch {(session.IsUpdatingWatch ? "actualizado" : "creado")} ({session.SelectedWatch.KeyItem}) que deseas realizar", WatchesMenuKeyboard);
        }
コード例 #16
0
        private static async Task MetricUnitDesc(ChatSession session)
        {
            session.SelectedMetric.Unit     = session.CurrentMessage.Trim();
            session.SelectedMetric.DeviceId = session.SelectedDevice.DeviceId;
            if (session.IsUpdatingMetric)
            {
                await DataService.Metrics.UpdateMetric(session.SelectedMetric);
            }
            else
            {
                await DataService.Metrics.InsertMetric(session.SelectedMetric);
            }

            session.Status = ChatStatus.METRIC_SELECTED;
            await TelegramBotManager.SendMessage(session.ChatId, $"Si quieres registrar datos de esta metrica manda una peticion GET a la siguiente direccion {Program.MainUrl}/api/sendData/{session.SelectedMetric.MetricId}/TOKEN/VALOR");

            await TelegramBotManager.SendMessage(session.ChatId, $"Metrica {(session.IsUpdatingMetric? "actualizada" : "creada")} ({session.SelectedMetric.KeyItem}) que deseas realizar", MetricsMenuKeyboard);
        }
コード例 #17
0
        private static async Task Devices(ChatSession session)
        {
            User usr;

            if (session.CurrentMessage == ANADIR_DISPOSITIVO)
            {
                await TelegramBotManager.SendMessage(session.ChatId, "Cual es el nombre de tu dispositivo?");

                session.Status = ChatStatus.ADD_DEVICE;
            }
            else if (session.CurrentMessage == REGRESAR)
            {
                await UserExists(session);
            }
            else
            {
                usr = await DataService.Users.FindUserByUsername(session.Username);

                var devices = await DataService.Devices.DevicesByUser(usr.UserId);

                int option = IntOption(session.CurrentMessage);

                if (option < 0)
                {
                    await TelegramBotManager.SendMessageSameKeyboard(session.ChatId, "Entrada no valida");

                    return;
                }

                Device dev = devices.FirstOrDefault(f => f.DeviceId == option);

                if (dev == null)
                {
                    await TelegramBotManager.SendMessageSameKeyboard(session.ChatId, "No existe ese dispositivo");

                    return;
                }

                session.SelectedDevice = dev;
                session.Status         = ChatStatus.DEVICE_SELECTED;

                await TelegramBotManager.SendMessage(session.ChatId, $"Dispositivo seleccionado ({session.SelectedDevice.KeyItem}), que deseas realizar", DeviceMenuKeyboard);
            }
        }
コード例 #18
0
        private static async Task DeviceSelected(ChatSession session)
        {
            switch (session.CurrentMessage)
            {
            case ACTUALIZAR:
                await TelegramBotManager.SendMessage(session.ChatId, "Cual sera el nuevo nombre del dispositivo?");

                session.Status = ChatStatus.DEVICE_RENAMING;
                break;

            case ELIMINAR:
                await TelegramBotManager.SendMessage(session.ChatId, "Estas seguro que deseas eliminar este dispositivo?", SiNoKeyboard);

                session.Status = ChatStatus.DEVICE_ASK_ELIMINATION;
                break;

            case VER_METRICAS:
                var keys = await MetricsKeyboard(session.SelectedDevice.DeviceId);

                await TelegramBotManager.SendMessage(session.ChatId, "Estas son las metricas del dispositivo", keys);

                session.Status = ChatStatus.DEVICE_METRICS;
                break;

            case VER_CONTROLES:
                var keyboard = await ControlsKeyboard(session.SelectedDevice.DeviceId);

                await TelegramBotManager.SendMessage(session.ChatId, "Estas son los controles del dispositivo", keyboard);

                session.Status = ChatStatus.DEVICE_CONTROLS;
                break;

            case REGRESAR:
                await UserExists(session);

                break;

            default:
                await TelegramBotManager.SendMessage(session.ChatId, "Entrada no valida", DeviceMenuKeyboard);

                break;
            }
        }
コード例 #19
0
        private static async Task Watches(ChatSession session)
        {
            if (session.CurrentMessage == ANADIR_WATCH)
            {
                await TelegramBotManager.SendMessage(session.ChatId, "Cual es el nombre de tu watch?");

                session.IsUpdatingWatch = false;
                session.Status          = ChatStatus.WATCH_NAMING;
            }
            else if (session.CurrentMessage == REGRESAR)
            {
                await TelegramBotManager.SendMessage(session.ChatId, $"Metrica ({session.SelectedMetric.KeyItem}), que deseas realizar?", MetricsMenuKeyboard);

                session.Status = ChatStatus.METRIC_SELECTED;
            }
            else
            {
                var watches = await DataService.Watches.WatchesByMetric(session.SelectedMetric.MetricId);

                int option = IntOption(session.CurrentMessage);

                if (option < 0)
                {
                    await TelegramBotManager.SendMessageSameKeyboard(session.ChatId, "Entrada no valida");

                    return;
                }

                Watch watch = watches.FirstOrDefault(f => f.WatchId == option);

                if (watch == null)
                {
                    await TelegramBotManager.SendMessageSameKeyboard(session.ChatId, "No existe ese watch");

                    return;
                }

                session.SelectedWatch = watch;
                session.Status        = ChatStatus.WATCH_SELECTED;

                await TelegramBotManager.SendMessage(session.ChatId, $"Watch seleccionado ({session.SelectedWatch.KeyItem}), que deseas realizar", WatchesMenuKeyboard);
            }
        }
コード例 #20
0
        private static async Task DeviceMetrics(ChatSession session)
        {
            if (session.CurrentMessage == ANADIR_METRICA)
            {
                await TelegramBotManager.SendMessage(session.ChatId, "Cual es el nombre de tu nueva metrica?");

                session.IsUpdatingMetric = false;
                session.Status           = ChatStatus.METRIC_NAMING;
            }
            else if (session.CurrentMessage == REGRESAR)
            {
                await TelegramBotManager.SendMessage(session.ChatId, $"Dispositivo seleccionado ({session.SelectedDevice.Name}), que accion deseas realizar", DeviceMenuKeyboard);

                session.Status = ChatStatus.DEVICE_SELECTED;
            }
            else
            {
                var metrics = await DataService.Metrics.MetricsByDevice(session.SelectedDevice.DeviceId);

                int option = IntOption(session.CurrentMessage);
                if (option < 0)
                {
                    await TelegramBotManager.SendMessageSameKeyboard(session.ChatId, "Entrada no valida");

                    return;
                }

                Metric metric = metrics.FirstOrDefault(f => f.MetricId == option);
                if (metric == null)
                {
                    await TelegramBotManager.SendMessageSameKeyboard(session.ChatId, "No existe ese dispositivo");

                    return;
                }
                session.SelectedMetric = metric;
                session.Status         = ChatStatus.METRIC_SELECTED;
                await TelegramBotManager.SendMessage(session.ChatId, "Dispositivo seleccionado, que deseas realizar", MetricsMenuKeyboard);
            }
        }
コード例 #21
0
        private static async Task DeviceControls(ChatSession session)
        {
            if (session.CurrentMessage == ANADIR_CONTROL)
            {
                await TelegramBotManager.SendMessage(session.ChatId, "Cual es el nombre del nuevo control?");

                session.Status = ChatStatus.ADD_CONTROL;
            }
            else if (session.CurrentMessage == REGRESAR)
            {
                await TelegramBotManager.SendMessage(session.ChatId, $"Dispositivo seleccionado ({session.SelectedDevice.KeyItem}) que accion deseas realizar", DeviceMenuKeyboard);

                session.Status = ChatStatus.DEVICE_SELECTED;
            }
            else
            {
                var controls = await DataService.Controls.ControlsByDevice(session.SelectedDevice.DeviceId);

                int option = IntOption(session.CurrentMessage);
                if (option < 0)
                {
                    await TelegramBotManager.SendMessageSameKeyboard(session.ChatId, "Entrada no valida");

                    return;
                }
                Control control = controls.FirstOrDefault(f => f.ControlId == option);
                if (control == null)
                {
                    await TelegramBotManager.SendMessageSameKeyboard(session.ChatId, "No existe ese dispositivo");

                    return;
                }
                session.SelectedControl = control;
                session.Status          = ChatStatus.CONTROL_SELECTED;

                await TelegramBotManager.SendMessage(session.ChatId, $"Control seleccionado ({session.SelectedControl.KeyItem}), que deseas realizar", ControlMenuKeyboard);
            }
        }
コード例 #22
0
        public static async Task WatchAskElimination(ChatSession session)
        {
            switch (session.CurrentMessage)
            {
            case SI:
                await DataService.Watches.DeleteWatch(session.SelectedWatch);

                session.SelectedWatch = null;
                await UserExists(session);

                break;

            case NO:
                await TelegramBotManager.SendMessage(session.ChatId, $"Operacion cancelada, watch seleccionado ({session.SelectedWatch.KeyItem}) Que deseas realizar?", WatchesMenuKeyboard);

                session.Status = ChatStatus.WATCH_SELECTED;
                break;

            default:
                await TelegramBotManager.SendMessage(session.ChatId, "Entrada no valida", SiNoKeyboard);

                break;
            }
        }
コード例 #23
0
        private static async Task MetricAskElimination(ChatSession session)
        {
            switch (session.CurrentMessage)
            {
            case SI:
                await DataService.Metrics.DeleteMetric(session.SelectedMetric);

                session.SelectedMetric = null;
                await UserExists(session);

                break;

            case NO:
                await TelegramBotManager.SendMessage(session.ChatId, "Operacion cancelada, Que deseas realizar?", MetricsMenuKeyboard);

                session.Status = ChatStatus.METRIC_SELECTED;
                break;

            default:
                await TelegramBotManager.SendMessage(session.ChatId, "Entrada no valida", SiNoKeyboard);

                break;
            }
        }
コード例 #24
0
        private static async Task UserExists(ChatSession session)
        {
            await TelegramBotManager.SendMessage(session.ChatId, "Que accion deseas realizar", MainMenuKeyboard);

            session.Status = ChatStatus.MAIN_MENU;
        }