public async Task <SkillResponse> FunctionHandler(SkillRequest input, ILambdaContext context)
        {
            var requestType = input.GetRequestType();

            if (requestType == typeof(LaunchRequest))
            {
                return(HelpMessage());
            }
            else if (requestType == typeof(IntentRequest))
            {
                var intentRequest = input.Request as IntentRequest;
                switch (intentRequest.Intent.Name)
                {
                case INSTALL_SQLSERVER_INTENT:
                    context.Logger.LogLine(intentRequest.Intent.Slots["SQLServerName"].Value);
                    SqlPassInstallerShared.AlexaCommand alexaCommand = new AlexaCommand
                    {
                        Type    = AlexaCommandType.INSTALL_SQLSERVER,
                        Payload = new Payload {
                            SqlServerName = intentRequest.Intent.Slots["SQLServerName"].Value,
                            IPAddress     = intentRequest.Intent.Slots["IPAddress"].Value.ToString().Replace(",", "."),
                            InstanceName  = intentRequest.Intent.Slots["InstanceName"].Value.ToString().Replace(",", ".")
                        }
                    };
                    using (var httpClient = new HttpClient())
                    {
                        string retval = string.Empty;
                        try
                        {
                            HttpContent stringContent = new StringContent(JsonConvert.SerializeObject(alexaCommand));
                            stringContent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                            HttpResponseMessage response = await httpClient.PostAsync(HTTPS_ENDPOINT + "/Init", stringContent);
                        }
                        catch (Exception ex)
                        {
                            context.Logger.LogLine(string.Format("Exception: {0}", ex.ToString()));
                        }

                        return(MakeSkillResponse($"Ich soll also einen SQL-Server installieren? Dann mache ich das jetzt. Der Server, " + intentRequest.Intent.Slots["SQLServerName"].Value + ", wird jetzt installiert.", true));
                    }

                case CANCEL_INTENT:
                case STOP_INTENT:
                    return(StopMessage());

                case HELP_INTENT:
                    return(HelpMessage());

                default:
                    return(HelpMessage());
                }
            }
            else
            {
                return(MakeSkillResponse($"Da ist was schiefgelaufen.", true));
            }
        }
Example #2
0
        private void FromAlexa(string body)
        {
            var simpleRequest = JsonConvert.DeserializeObject <SimpleAlexaRequest>(body, Utils.ConverterSettingsCamel);

            switch (simpleRequest.Request.Type)
            {
            case "LaunchRequest":
            {
                var request = JsonConvert.DeserializeObject <AlexaLaunchRequest>(body, Utils.ConverterSettingsCamel);

                Id           = request.Request.RequestId;
                User         = new User(request.Session.User);
                Text         = "";
                Payload      = "";
                AlexaCommand = new AlexaCommand(request);
                break;
            }

            case "IntentRequest":
            {
                var request = JsonConvert.DeserializeObject <AlexaIntentRequest>(body, Utils.ConverterSettingsCamel);

                Id   = request.Request.RequestId;
                User = new User(request.Session.User);
                Text = request.Request?.Intent?.Slots != null && request.Request.Intent.Slots.Keys.Count > 0
                        ? request.Request.Intent.Slots.First().Value.Value
                        : "";
                Payload      = "";
                AlexaCommand = new AlexaCommand(request);
                break;
            }

            case "SessionEndedRequest":
            {
                var request = JsonConvert.DeserializeObject <AlexaSessionEndedRequest>(body, Utils.ConverterSettingsCamel);

                Id           = request.Request.RequestId;
                User         = new User(request.Session.User);
                Text         = "";
                Payload      = "";
                AlexaCommand = new AlexaCommand(request);
                break;
            }
            }
        }
Example #3
0
        public bool Check(CommandContent content, Locale locale)
        {
            if (content.Text != null && !content.Text.ContainsKey(locale))
            {
                throw new ArgumentException("Locale is not supported");
            }

            if (AliceCommand != null)
            {
                Utils.CheckLocale(Layer.Alice, locale);
                if (content.IsEnter)
                {
                    return(string.IsNullOrEmpty(AliceCommand.Command));
                }
                return(AliceCommand.Check(content));
            }

            if (TelegramCommand != null)
            {
                Utils.CheckLocale(Layer.Telegram, locale);
                if (content.IsEnter)
                {
                    return(Text != null && Text.StartsWith("/start"));
                }
                if (content.Text == null)
                {
                    return(Payload == content.Payload);
                }
                return(content.Text[locale].ToLower() == Text.ToLower());
            }

            if (AlexaCommand != null)
            {
                Utils.CheckLocale(Layer.Alexa, locale);
                if (content.IsEnter)
                {
                    return(AlexaCommand.IsLaunchIntent);
                }
                return(AlexaCommand.Check(content));
            }

            throw new ArgumentException("None of layers data were assigned");
        }
Example #4
0
        // Executing Powershell from C# with the help of: https://blogs.msdn.microsoft.com/kebab/2014/04/28/executing-powershell-scripts-from-c/
        public AlexaCommand Post([FromBody]AlexaCommand input)
        {
            switch(input.Type)
            {
                case AlexaCommandType.INSTALL_SQLSERVER:
                    using (PowerShell PowerShellInstance = PowerShell.Create())
                    {
                        string functions = System.IO.File.ReadAllText(Path.Combine(MyScriptFolder, "Functions.ps1"));
                        string script = System.IO.File.ReadAllText(Path.Combine(MyScriptFolder, "InstallSqlServer.ps1"));

                        PowerShellInstance.AddScript(functions);
                        PowerShellInstance.AddScript(script);

                        PowerShellInstance.AddParameter("Servername",input.Payload.SqlServerName);
                        PowerShellInstance.AddParameter("IPAddress", input.Payload.IPAddress);
                        PowerShellInstance.AddParameter("InstanceName", input.Payload.InstanceName);

                        Collection<PSObject> PSOutput = PowerShellInstance.Invoke();
                    }

                    break;
            }
            return new AlexaCommand { Type = AlexaCommandType.RESULT, Payload = new Payload { ResultText = "Success" } };
        }