public override APLDocumentReference ReadJson(JsonReader reader, Type objectType, APLDocumentReference existingValue, bool hasExistingValue,
                                                      JsonSerializer serializer)
        {
            var jObject      = JObject.Load(reader);
            var documentType = jObject.Value <string>("type");

            switch (documentType.ToUpper())
            {
            case "APL":
                var apl = new APLDocument();
                serializer.Populate(jObject.CreateReader(), apl);
                return(apl);

            case "APLT":
                var aplt = new APLTDocument();
                serializer.Populate(jObject.CreateReader(), aplt);
                return(aplt);

            case "APLA":
                var apla = new APLADocument();
                serializer.Populate(jObject.CreateReader(), apla);
                return(apla);

            case "LINK":
                var link = new APLDocumentLink();
                serializer.Populate(jObject.CreateReader(), link);
                return(link);
            }

            throw new InvalidOperationException($"Unknown APL Document type {documentType}");
        }
示例#2
0
        private static APLDocument GenerateRollDisplay(DiceRollerResult result)
        {
            //TODO: Get it to play <audio src="soundbank://soundlibrary/toys_games/board_games/board_games_08"/>
            var doc = new APLDocument(APLDocumentVersion.V1_1);

            Import.AlexaLayouts.Into(doc);
            new Import {
                Name    = "transitions",
                Version = "1.0.0",
                Source  = "https://rollcasterassets.s3-eu-west-1.amazonaws.com/apl_transitions.json"
            }
            .Into(doc);

            doc.MainTemplate = new Layout(new AlexaHeadline
            {
                BackgroundImageSource = "https://rollcasterassets.s3-eu-west-1.amazonaws.com/backg_shrunk.jpg",
                BackgroundBlur        = true,
                HeaderBackButton      = false,
                PrimaryText           = $"You rolled {result.Total}",
                SecondaryText         = string.Join(" + ", result.Dice.Select(d => d.ToString())),
                OnMount = new APLValue <IList <APLCommand> >(new APLCommand[]
                {
                    new CustomCommand("rollIn")
                })
            }).AsMain();
            return(doc);
        }
        private RenderDocumentDirective BuildListTextDirective(string sentences, string bg = "")
        {
            if (string.IsNullOrEmpty(bg))
            {
                //bg = "https://kids-advice.s3.amazonaws.com/apl-wallpaper.jpg";
                bg = "https://i.ibb.co/5cWztFH/brown-on-seashore-near-mountain-1007657.jpg";
            }
            var document = new APLDocument
            {
                MainTemplate = new Layout
                {
                    Parameters = new List <Parameter>
                    {
                        new Parameter("textListData")
                    },
                    Description = "List View",
                    Items       = new APLComponent[]
                    {
                        new AlexaTextList
                        {
                            BackgroundImageSource = bg,
                            HeaderTitle           = "Alexa text list header title",
                            HeaderSubtitle        = "sub",
                            HeaderDivider         = true,
                            BackgroundScale       = new APLValue <Scale>(Scale.BestFill),
                            BackgroundAlign       = new APLValue <string>("center"),
                            BackgroundColor       = new APLValue <string>("transparent"),
                            ListItems             = new APLValue <List <AlexaTextListItem> >()
                            {
                                Value = new List <AlexaTextListItem>
                                {
                                    new AlexaTextListItem
                                    {
                                        PrimaryText = "Hello world! 1"
                                    },
                                    new AlexaTextListItem
                                    {
                                        PrimaryText = "Hello world! 2"
                                    },
                                    new AlexaTextListItem
                                    {
                                        PrimaryText = "Hello world! 3"
                                    }
                                }
                            }
                        }
                    }
                }
            };

            ;
            var renderDocument = new RenderDocumentDirective
            {
                Token    = "randToken",
                Document = document
            };

            return(renderDocument);
        }
示例#4
0
        public void PrimaryUserChanged()
        {
            var doc           = new APLDocument();
            var entitySensing = new EntitySensingExtension("EntitySensing");

            entitySensing.OnPrimaryUserChanged(doc, null);
            Assert.True(doc.Handlers.ContainsKey("EntitySensing:OnPrimaryUserChanged"));
        }
示例#5
0
        public void DeviceStateChangedHandler()
        {
            var doc         = new APLDocument();
            var smartMotion = new SmartMotionExtension("SmartMotion");

            smartMotion.OnDeviceStateChanged(doc, null);
            Assert.True(doc.Handlers.ContainsKey("SmartMotion:OnDeviceStateChanged"));
        }
示例#6
0
        public void AlexaFooterAddsImport()
        {
            var document = new APLDocument();

            Import.AlexaLayouts.Into(document);
            document.MainTemplate = new Layout(
                new AlexaFooter("Hint Text")
                ).AsMain();
            Assert.Contains(Import.AlexaLayouts, document.Imports);
        }
示例#7
0
        public void AlexaFooterRecognisesExistingImport()
        {
            var document = new APLDocument {
                Imports = new List <Import> {
                    Import.AlexaLayouts
                }
            };

            Import.AlexaLayouts.Into(document);
            Assert.Single(document.Imports);
        }
示例#8
0
        public void BackStackExtension()
        {
            var backstack = new BackstackExtension("Back");
            var doc       = new APLDocument(APLDocumentVersion.V1_4);

            doc.Extensions.Value.Add(backstack);
            doc.Settings = new APLDocumentSettings();
            doc.Settings.Add(backstack.Name, new BackStackSettings {
                BackstackId = "myDocument"
            });
            Assert.True(Utility.CompareJson(doc, "ExtensionBackStack.json"));
        }
示例#9
0
        public void SmartMotion()
        {
            var smartMotion = new SmartMotionExtension("SmartMotion");
            var doc         = new APLDocument(APLDocumentVersion.V1_4);

            doc.Extensions.Value.Add(smartMotion);
            doc.Settings = new APLDocumentSettings();
            doc.Settings.Add(smartMotion.Name, new SmartMotionSettings
            {
                DeviceStateName  = "MyDeviceState",
                WakeWordResponse = WakeWordResponse.FollowOnWakeWord
            });
            Assert.True(Utility.CompareJson(doc, "ExtensionSmartMotion.json"));
        }
示例#10
0
        public void EntitySensing()
        {
            var entitySensing = new EntitySensingExtension("EntitySensing");
            var doc           = new APLDocument(APLDocumentVersion.V1_4);

            doc.Extensions.Value.Add(entitySensing);
            doc.Settings = new APLDocumentSettings();
            doc.Settings.Add(entitySensing.Name, new EntitySensingSettings
            {
                EntitySensingStateName = "EntitySensingState",
                PrimaryUserName        = "******"
            });
            Assert.True(Utility.CompareJson(doc, "ExtensionEntitySensing.json"));
        }
示例#11
0
        public static RenderDocumentDirective GetRenderDirective(string token, string hint, params APLComponent[] components)
        {
            APLDocument document = new APLDocument();

            AlexaFooter.ImportInto(document);

            document.MainTemplate       = new Layout(new AlexaFooter(hint)).AsMain();
            document.MainTemplate.Items = new List <APLComponent>();
            for (int i = 0; i < components.Length; i++)
            {
                document.MainTemplate.Items.Add(components[i]);
            }

            RenderDocumentDirective renderDirective = new RenderDocumentDirective
            {
                Token    = token,
                Document = document
            };

            return(renderDirective);
        }
        public override APLDocumentBase ReadJson(JsonReader reader, Type objectType, APLDocumentBase existingValue, bool hasExistingValue,
                                                 JsonSerializer serializer)
        {
            var jObject      = JObject.Load(reader);
            var documentType = jObject.Value <string>("type");

            if (documentType == "APL")
            {
                var apl = new APLDocument();
                serializer.Populate(jObject.CreateReader(), apl);
                return(apl);
            }

            if (documentType == "APLT")
            {
                var aplt = new APLTDocument();
                serializer.Populate(jObject.CreateReader(), aplt);
                return(aplt);
            }

            throw new InvalidOperationException($"Unknown APL Document type {documentType}");
        }
示例#13
0
 public static void AddResponsiveDesign(this APLDocument document)
 {
     Import.AlexaLayouts.Into(document);
 }
示例#14
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));
        }