public RenderDocumentDirective GetIntroDirective() { var directive = new RenderDocumentDirective { Token = "randomToken", Document = new APLDocument { MainTemplate = new Layout(new[] { new Container( new Image(INTRO_IMAGE) { Width = "100%", Height = "100%", Align = "center" } ) { Width = "100%", Height = "100%", AlignItems = "center", JustifyContent = "center", Direction = "column", } }) } }; return(directive); }
private RenderDocumentDirective BuildAPL() { 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" } }) } }; return(directive); }
public RenderDocumentDirective GetUpsellDirective(string productId) { var display_image = GetSessionLogo(productId); var directive = new RenderDocumentDirective { Token = "randomToken", Document = new APLDocument { MainTemplate = new Layout(new[] { new Container( new Image(display_image) { Width = "100%", Height = "100%", Align = "center" } ) { Width = "100%", Height = "100%", AlignItems = "center", JustifyContent = "center", Direction = "column", } }) } }; return(directive); }
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); }
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)); } }
public static void Add() { RenderDocumentDirective.AddSupport(); ExecuteCommandsDirective.AddSupport(); SendIndexListDataDirective.AddSupport(); UpdateIndexListDataDirective.AddSupport(); new UserEventRequestHandler().AddToRequestConverter(); new LoadIndexListDataRequestHandler().AddToRequestConverter(); new RuntimeErrorRequestHandler().AddToRequestConverter(); }
public void AddAplPage(string token, Layout layout) { RenderDocumentDirective renderDocumentDirective = new RenderDocumentDirective { Token = token, Document = new APLDocument { MainTemplate = layout } }; Skill.Response.Directives.Add(renderDocumentDirective); }
private static void AddWelcomeAPL(SkillResponse response) { var directive = new RenderDocumentDirective { Token = "randomToken", Document = new APLDocument { Imports = new Import[] { new Import("alexa-layouts", "1.0.0") }, MainTemplate = new Layout(new[] { new Container(new APLComponent[] { new Image("https://alexatt.z16.web.core.windows.net/transite.jpg") { Width = "100vw", Height = "100vh", Position = "absolute", Scale = new NET.APL.APLValue <ImageScale>(ImageScale.BestFill), OverlayColor = "#000000bb" }, new Container(new APLComponent[] { new Text("Welcome to PostNord My Shipment") { TextAlign = "${viewport.shape == 'round' ? 'center' : 'left'}", PaddingRight = "40", PaddingLeft = "40", Color = "#ffffff" } }) { Grow = 0, JustifyContent = "${viewport.shape == 'round' ? 'center' : 'end'}" }, new AlexaFooter() { When = When.RectangleViewport, FooterHint = "Say find shipment followed by your reference number to get the latest status" } }) { Height = "100vh" } }) } }; response.Response.Directives.Add(directive); }
public static RenderDocumentDirective GenerateDirective(string token, params APLComponent[] components) { var directive = new RenderDocumentDirective() { Token = token, Document = new APLDocument() }; directive.Document.MainTemplate = new Layout().AsMain(); directive.Document.MainTemplate.Items = new List <APLComponent>(); for (int i = 0; i < components.Length; i++) { directive.Document.MainTemplate.Items.Add(components[i]); } return(directive); }
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 RenderDocumentDirective GetCurrentWordDirective(string currentWord) { var directive = new RenderDocumentDirective { Token = "randomToken", Document = new APLDocument(APLDocumentVersion.V1_2) { Imports = new List <Import> { new Import("alexa-layouts", "1.2.0") }, MainTemplate = new Layout(new[] { new Container(new APLComponent[] { new AlexaBackground() { BackgroundImageSource = FLASH_CARD_IMAGE }, new Text(currentWord) { Width = "100%", Height = "100%", FontSize = "160dp", TextAlign = "center", TextAlignVertical = "center", Color = "black" }, }) { Width = "100%", Height = "100%", AlignItems = "center", Direction = "column", JustifyContent = "center", } }) } }; return(directive); }
/// <summary> /// /// </summary> /// <param name="data"></param> /// <returns></returns> public RenderDocumentDirective VerticalScrollList(ScrollListData data) { var layout = new Layout(); layout.Parameters = new[] { new Parameter("payload") }; layout.Items = new APLComponent[] { new VerticalScrollListContainer() { Title = "${payload.data.title}", BackgroundImage = "${payload.data.backgroundImage}", ListData = "${payload.data.listItems}" } }; var directive = new RenderDocumentDirective { Token = "randomToken", Document = new APLDocument { Imports = new Import[] { new Import("alexa-layouts", "1.0.0") }, MainTemplate = layout, Layouts = new Dictionary <string, Layout>() { { nameof(VerticalScrollListContainer), MakeVerticalScrollListContainer() }, { nameof(VerticalListItem), MakeVerticalScrollListItem() } } }, DataSources = new Dictionary <string, APLDataSource>() { { "data", new KeyValueDataSource() { Properties = data.GetType().GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public).ToDictionary(s => s.GetCustomAttributes(typeof(JsonPropertyAttribute), false).Cast <JsonPropertyAttribute>().Select(p => p.PropertyName).First(), k => k.GetValue(data)) } } } }; return(directive); }
private async Task AddEventDisplay(ResponseBody response, Group groupData) { var eventData = new ObjectDataSource { Properties = new Dictionary <string, object>(), TopLevelData = new Dictionary <string, object> { { "backgroundUrl", groupData.GroupPhoto?.HighRes ?? groupData.KeyPhoto?.HighRes }, { "groupName", groupData.Name } }, Transformers = new List <APLTransformer>() }; var document = await S3Helper.GetDocument(System.Environment.GetEnvironmentVariable("bucket"), "assets/EventDetail.json"); var directive = new RenderDocumentDirective { Document = document, DataSources = new Dictionary <string, APLDataSource> { { "eventData", eventData } }, Token = groupData.Id.ToString() }; var initialText = groupData.ExtraFields[Consts.DataPlainTextDescription].ToString() .Replace("https://", string.Empty); eventData.Properties.Add("text", initialText); var speech = new Speech(initialText.Split("\n\n") .SelectMany(t => new ISsml[] { new Paragraph(new Sentence(new PlainText(t))), new PlainText("\n\n") }).ToArray()); response.Directives.Add(directive); }
public RenderDocumentDirective BuildItemListDirective(string sentences, string bg = "", string title = "", string subtitle = "") { if (!string.IsNullOrEmpty(bg)) { bgUrl = bg; } var items = new List <AlexaTextListItem>(); foreach (var item in sentences.Split(",")) { items.Add(new AlexaTextListItem { PrimaryText = item }); } var layout = new Layout { Description = "Main template", Parameters = new List <Parameter> { new Parameter("payload") }, Items = new Container[] { new Container { Height = "100vh", Items = new APLValue <List <APLComponent> > { Value = new List <APLComponent> { new AlexaTextList { BackgroundImageSource = bgUrl, HeaderTitle = title, HeaderSubtitle = subtitle, HeaderAttributionImage = new APLValue <string>(logoUrl), HeaderDivider = true, ColorOverlay = new APLValue <bool?>(true), BackgroundScale = new APLValue <Scale>(Scale.BestFill), BackgroundAlign = new APLValue <string>("center"), BackgroundColor = new APLValue <string>("transparent"), ListItems = new APLValue <List <AlexaTextListItem> >() { Value = items } } } } } } }; var renderDocument = new RenderDocumentDirective { Token = "randomToken", Document = new APLDocument { MainTemplate = layout, Version = APLDocumentVersion.V1_3, Imports = new List <Import> { new Import { Name = "alexa-layouts", Version = "1.1.0" } } } }; return(renderDocument); }
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)); }
public RenderDocumentDirective BuildAPLDirective(string sentences, string bg = "", string title = "", string subtitle = "") { if (!string.IsNullOrEmpty(bg)) { bgUrl = bg; } var layout = new Layout { Description = "Main template", Parameters = new List <Parameter> { new Parameter("payload") }, Items = new Container[] { new Container { Height = "100vh", Items = new APLValue <List <APLComponent> > { Value = new List <APLComponent> { new Image { Width = "100vw", Height = "100vh", Position = new APLValue <string>("absolute"), Scale = new APLValue <Scale?>(Scale.BestFill), Source = new APLValue <string>(bgUrl) }, new AlexaHeader { HeaderTitle = new APLValue <string>(title), HeaderSubtitle = new APLValue <string>(subtitle), HeaderAttributionImage = new APLValue <string>(logoUrl) }, new Container { Grow = new APLValue <int?>(1), PaddingLeft = 60, PaddingRight = 60, PaddingBottom = 40, Items = new APLValue <List <APLComponent> > { Value = new List <APLComponent> { new Text(sentences) { FontSize = "30dp", Style = new APLValue <string>("textStyleBody"), Spacing = 12 } } } } } } } } }; var renderDocument = new RenderDocumentDirective { Token = "randomToken", Document = new APLDocument { MainTemplate = layout, Version = APLDocumentVersion.V1_3, Imports = new List <Import> { new Import { Name = "alexa-layouts", Version = "1.1.0" } } } }; return(renderDocument); }
private RenderDocumentDirective BuildDirective(string sentences, string bg = "") { if (string.IsNullOrEmpty(bg)) { bg = "https://i.ibb.co/5cWztFH/brown-on-seashore-near-mountain-1007657.jpg"; } var mainLayout = new Layout( new Container( new AlexaTextList { BackgroundImageSource = APLValue.To <string>("${textListData.backgroundImageSource}"), HeaderTitle = APLValue.To <string>("${textListData.headerTitle}"), HeaderSubtitle = APLValue.To <string>("${textListData.headerSubtitle}"), HeaderDivider = true, BackgroundScale = new APLValue <Scale>(Scale.BestFill), BackgroundAlign = new APLValue <string>("center"), BackgroundColor = new APLValue <string>("transparent"), ListItems = APLValue.To <APLValue <List <AlexaTextListItem> > >("${textListData.listItemsToShow}") } ) { Width = "100vw", Height = "100vh" } ); mainLayout.Parameters = new List <Parameter>(); mainLayout.Parameters.Add(new Parameter("textListData")); var renderDocument = new RenderDocumentDirective { Token = "randomToken", Document = new APLDocument { MainTemplate = mainLayout }, DataSources = new Dictionary <string, APLDataSource> { { "textListData", new ObjectDataSource { Properties = new Dictionary <string, object> { { "headerTitle", "Alexa text list header title" }, { "headerSubtitle", "Header subtitle" }, { "backgroundImageSource", bg }, { "listItemsToShow", 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" } } } } } } } } }; return(renderDocument); }
private RenderDocumentDirective BuildAPLDirective(string sentences, string bg = "") { if (string.IsNullOrEmpty(bg)) { bg = "https://i.ibb.co/5cWztFH/brown-on-seashore-near-mountain-1007657.jpg"; } var mainLayout = new Layout( new Container( new Image("${payload.bodyTemplate1Data.Properties.backgroundImage.sources[0].url}") { Width = "100vw", Height = "100vh", Position = new APLValue <string>("absolute"), Scale = new APLValue <Scale?>(Scale.BestFill) }, new Text(sentences) { FontSize = "40dp", Style = new APLValue <string>("textStyleBody"), TextAlign = new APLValue <string>("center"), Id = "talker", Content = APLValue.To <string>("${payload.script.properties.textContent.primaryText.text}"), Speech = APLValue.To <string>("${payload.script.properties.textContent.primaryText.text}") } ) { Width = "100vw", Height = "100vh", JustifyContent = new APLValue <string>("center"), Grow = new APLValue <int?>(1) } ); mainLayout.Parameters = new List <Parameter>(); mainLayout.Parameters.Add(new Parameter("payload")); var speech = new Speech(new PlainText(sentences)); var renderDocument = new RenderDocumentDirective { Token = "randomToken", Document = new APLDocument { MainTemplate = mainLayout }, DataSources = new Dictionary <string, APLDataSource> { { "script", new Alexa.NET.APL.DataSources.ObjectDataSource { ObjectId = "bt1Sample", Title = "Sylvester Assistant", Properties = new Dictionary <string, object> { { "backgroundImage", new Dictionary <string, object> { { "contentDescription", null }, { "smallSourceUrl", null }, { "largeSourceUrl", null }, { "sources", new List <object> { new Dictionary <string, object> { { "url", "https://d2o906d8ln7ui1.cloudfront.net/images/BT1_Background.png" }, { "size", "small" }, { "widthPixels", 0 }, { "heightPixels", 0 } }, new Dictionary <string, object> { { "url", "https://d2o906d8ln7ui1.cloudfront.net/images/BT1_Background.png" }, { "size", "small" }, { "widthPixels", 0 }, { "heightPixels", 0 } } } } } }, { "textContent", new Dictionary <string, object> { { "primaryText", new Dictionary <string, object> { { "type", "PlainText" }, { "text", sentences } } } } }, { "logoUrl", "https://d2o906d8ln7ui1.cloudfront.net/images/cheeseskillicon.png" } } } } } }; return(renderDocument); }
public RenderDocumentDirective BuildScrollingTextDirective(string sentences, string bg = "", string title = "", string subtitle = "") { if (!string.IsNullOrEmpty(bg)) { bgUrl = bg; } var speech = new Speech(new PlainText(sentences)); var layout = new Layout { Parameters = new List <Parameter> { new Parameter("payload") }, Items = new Container[] { new Container { Height = "100vh", Items = new APLValue <List <APLComponent> > { Value = new List <APLComponent> { new Image { Width = "100vw", Height = "100vh", Position = new APLValue <string>("absolute"), Scale = new APLValue <Scale?>(Scale.BestFill), Source = new APLValue <string>(bgUrl) }, new AlexaHeader { HeaderTitle = new APLValue <string>(title), HeaderSubtitle = new APLValue <string>(subtitle), HeaderAttributionImage = new APLValue <string>(logoUrl) }, new ScrollView( new Text(sentences) { FontSize = "40dp", TextAlign = "Center", Id = "talker", Content = APLValue.To <string>("${payload.script.properties.text}"), Speech = APLValue.To <string>("${payload.script.properties.speech}"), OnMount = new APLValue <IList <APLCommand> > { Value = new List <APLCommand> { new SpeakItem { ComponentId = "talker", HighlightMode = new APLValue <HighlightMode?>(HighlightMode.Line) } } } } ) { Width = "100vw", Height = "100vh", PaddingLeft = 60, PaddingRight = 60, PaddingBottom = 140 } } } } } }; var renderDocument = new RenderDocumentDirective { Token = "randomToken", Document = new APLDocument { MainTemplate = layout, Version = APLDocumentVersion.V1_3, Imports = new List <Import> { new Import { Name = "alexa-layouts", Version = "1.1.0" } } }, DataSources = new Dictionary <string, APLDataSource> { { "script", new ObjectDataSource { Properties = new Dictionary <string, object> { { "ssml", speech.ToXml() } }, Transformers = new List <APLTransformer> { APLTransformer.SsmlToText( "ssml", "text"), APLTransformer.SsmlToSpeech( "ssml", "speech") } } } } }; return(renderDocument); }
public RenderDocumentDirective BuildScrollingSequenceWithVoiceDirective(string sentences, string bg = "", string title = "", string subtitle = "") { if (!string.IsNullOrEmpty(bg)) { bgUrl = bg; } var items = new List <APLComponent>(); var prayers = sentences.Replace("\n", "").Split(","); for (int i = 0; i < prayers.Length; i++) { items.Add(new Text() { Id = $"itm{i.ToString()}", Width = "100vw", Height = "100vh", PaddingLeft = 40, PaddingRight = 40, TextAlign = new APLValue <string>("center"), AlignSelf = new APLValue <string>("center"), TextAlignVertical = new APLValue <string>("center"), Content = APLValue.To <string>("${payload.script.properties.text" + i.ToString() + "}"), //Speech = APLValue.To<string>("${payload.script.properties.speech" + i.ToString() + "}") }); } var ppt = new Dictionary <string, object>(); Speech speech = null; for (int i = 0; i < prayers.Length; i++) { speech = new Speech(new PlainText($"{i + 1}. {prayers[i]}")); ppt.Add($"ssml{i}", speech.ToXml()); } var ff = new List <APLTransformer>(); for (int i = 0; i < prayers.Length; i++) { ff.Add(APLTransformer.SsmlToText($"ssml{i}", $"text{i}")); ff.Add(APLTransformer.SsmlToSpeech($"ssml{i}", $"speech{i}")); } var layout = new Layout { Parameters = new List <Parameter> { new Parameter("payload") }, Items = new Container[] { new Container { Height = "100vh", Items = new APLValue <List <APLComponent> > { Value = new List <APLComponent> { //new Video //{ // Width = "100vw", // Height = "100vh", // Position = new APLValue<string>("absolute"), // Scale = new APLValue<Scale>(Scale.BestFill), // Autoplay = new APLValue<bool?>(true), // AudioTrack = new APLValue<string>("none"), // //Source = new APLValue<string>("https://bestilldemo.azurewebsites.net/images/gifbg.gif") // Source = new APLValue<IList<VideoSource>> // { // Value = new List<VideoSource> // { // new VideoSource // { // RepeatCount = new APLValue<int?>(10), // Uri = new APLValue<Uri>(new Uri("https://bestilldemo.azurewebsites.net/images/soundwave.mp4")) // } // } // } //}, new AlexaBackground { Width = "100vw", Height = "100vh", Position = new APLValue <string>("absolute"), VideoAudioTrack = new APLValue <string>("none"), BackgroundVideoSource = new APLValue <VideoSource> { Value = new VideoSource { Uri = new APLValue <Uri>(new Uri("https://bestilldemo.azurewebsites.net/images/soundwave.mp4")), RepeatCount = new APLValue <int?>(10) } }, VideoAutoPlay = new APLValue <bool?>(true) }, new AlexaHeader { HeaderTitle = new APLValue <string>(title), HeaderSubtitle = new APLValue <string>(subtitle), HeaderAttributionImage = new APLValue <string>(logoUrl) }, new Pager { Id = "myPager", Width = "100vw", Height = "100vh", PaddingBottom = 140, AlignSelf = new APLValue <string>("center"), Items = new APLValue <List <APLComponent> > { Value = items }, OnMount = new APLValue <IList <APLCommand> > { Value = new List <APLCommand> { new AutoPage { ComponentId = "myPager", ScreenLock = new APLValue <bool?>(true), DelayMilliseconds = new APLValue <int?>(40000), Count = new APLValue <int?>(items.Count), Duration = new APLValue <int?>(40000), } //new Parallel //{ // Commands= new APLValue<IList<APLCommand>> // { // Value = new List<APLCommand> // { // new SpeakList // { // ComponentId = "myPager", // Start = new APLValue<int>(0), // Count = new APLValue<int>(items.Count), // MinimumDwellTime = new APLValue<int?>(40000), // ScreenLock = new APLValue<bool?>(true), // Align = new APLValue<ItemAlignment?>(ItemAlignment.Center), // }, // new AutoPage // { // ComponentId = "myPager", // ScreenLock = new APLValue<bool?>(true), // DelayMilliseconds = new APLValue<int?>(40000), // Count = new APLValue<int?>(items.Count), // Duration = new APLValue<int?>(40000), // } // } // } //} } } } } } } } }; var renderDocument = new RenderDocumentDirective { Token = "randomToken", Document = new APLDocument { MainTemplate = layout, Version = APLDocumentVersion.V1_3, Imports = new List <Import> { new Import { Name = "alexa-layouts", Version = "1.1.0" } } }, DataSources = new Dictionary <string, APLDataSource> { { "script", new ObjectDataSource { Properties = ppt, Transformers = ff } } } }; return(renderDocument); }