Exemplo n.º 1
0
        public void ExecuteCommands()
        {
            var directive = new ExecuteCommandsDirective("[SkillProvidedToken]");

            directive.Commands = new List <APLCommand>();
            directive.Commands.Add(new Idle());

            Assert.True(Utility.CompareJson(directive, "ExecuteCommands.json"));
        }
Exemplo n.º 2
0
 public static T ExampleFileContent <T>(string expectedFile)
 {
     RenderDocumentDirective.AddSupport();
     ExecuteCommandsDirective.AddSupport();
     using (var reader = new JsonTextReader(new StringReader(ExampleFileContent(expectedFile))))
     {
         return(new JsonSerializer().Deserialize <T>(reader));
     }
 }
Exemplo n.º 3
0
 public static void Add()
 {
     RenderDocumentDirective.AddSupport();
     ExecuteCommandsDirective.AddSupport();
     SendIndexListDataDirective.AddSupport();
     UpdateIndexListDataDirective.AddSupport();
     new UserEventRequestHandler().AddToRequestConverter();
     new LoadIndexListDataRequestHandler().AddToRequestConverter();
     new RuntimeErrorRequestHandler().AddToRequestConverter();
 }
Exemplo n.º 4
0
        public static async Task <IActionResult> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)]
                                                     HttpRequest req,
                                                     ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed an alexa post request.");

            //deserialize skill request
            string json = await req.ReadAsStringAsync();

            var skillRequest = JsonConvert.DeserializeObject <APLSkillRequest>(json);

            //Validate Request
            // Verifies that the request is a valid request from Amazon Alexa
            var isValid = await skillRequest.ValidateRequestAsync(req, log);

            if (!isValid)
            {
                return(new BadRequestResult());
            }

            RenderDocumentDirective.AddSupport();
            ExecuteCommandsDirective.AddSupport();

            //init respoonse and get current user session
            SkillResponse response = null;
            Session       session  = skillRequest.Session;

            //check for APL support
            if (skillRequest.APLSupported())
            {
                //add support for APL Commands +  Directives
                new UserEventRequestHandler().AddToRequestConverter();
                skillRequest = JsonConvert.DeserializeObject <APLSkillRequest>(json);
                var aplDocumentVersion = skillRequest.APLInterfaceDetails().Runtime.MaxVersion;
                //add apl layout
                var document = new APLDocument();
                document.AddResponsiveDesign();

                document.MainTemplate = new Layout(
                    new Container(
                        new Text("APL in C# TEST!")
                {
                    FontSize = "24vh", TextAlign = "Center"
                },
                        new Image(scotlandFlagURL)
                {
                    Width = "100vw", Height = "100vw", Scale = Scale.BestFit
                }
                        )
                {
                    Direction = "row", Position = "absolute"
                })
                                        .AsMain();

                var directive = new RenderDocumentDirective
                {
                    Token    = "randomToken",
                    Document = new APLDocument
                    {
                        MainTemplate = new Layout(new[]
                        {
                            new Container(new APLComponent[] {
                                new Text("APL in C#")
                                {
                                    FontSize = "24dp", TextAlign = "Center"
                                },
                                new Image("https://images.example.com/photos/2143/lights-party-dancing-music.jpg?cs=srgb&dl=cheerful-club-concert-2143.jpg&fm=jpg")
                                {
                                    Width = 400, Height = 400
                                }
                            })
                            {
                                Direction = "row"
                            }
                        })
                    }
                };

                response.Response.Directives.Add(directive);
            }


            switch (skillRequest.Request)
            {
            case LaunchRequest launchRequest:
                return(HandleLaunch(launchRequest, log));

            case IntentRequest intentRequest:
                switch (intentRequest.Intent.Name)
                {
                case "NewQuizIntent":
                    return(NewQuizIntent());

                default:
                    return(HandleLaunch(null, log));
                }
            }

            return(new OkObjectResult(response));
        }