public void MessageActivityWithSignInCard()
        {
            var skillRequest = SkillRequestHelper.CreateIntentRequest();
            var mapper       = new AlexaRequestMapper();

            var signinCard = new SigninCard
            {
                Text    = "sign in text",
                Buttons = new List <CardAction>()
                {
                    new CardAction
                    {
                        Title = "sign in",
                        Type  = ActionTypes.OpenUrl,
                        Image = "https://image",
                        Value = "https://value"
                    }
                }
            };

            var activity = Activity.CreateMessageActivity() as Activity;

            activity.Attachments.Add(new Attachment()
            {
                ContentType = SigninCard.ContentType, Content = signinCard
            });

            var skillResponse = ExecuteActivityToResponse(mapper, new MergedActivityResult {
                MergedActivity = activity
            }, skillRequest);

            Assert.NotNull(skillResponse.Response.Card);
            Assert.Equal(typeof(LinkAccountCard), skillResponse.Response.Card.GetType());
        }
        public void LaunchRequestMappedReturnsLocale()
        {
            // arrange
            var skillRequest = new SkillRequest
            {
                Request = new LaunchRequest()
                {
                    Locale = "en-US"
                },
                Context = new Context
                {
                    System = new AlexaSystem()
                    {
                        Application = new Application(), User = new User()
                    }
                },
                Session = new Session()
                {
                    User = new User()
                }
            };


            // act
            var alexaMapper = new AlexaRequestMapper();
            var result      = alexaMapper.RequestToActivity(skillRequest);

            // assert
            Assert.Equal("en-US", result.Locale);
        }
        public void MessageActivityWithAlexaCardDirectiveAttachmentsConverted()
        {
            var skillRequest = SkillRequestHelper.CreateIntentRequest();
            var mapper       = new AlexaRequestMapper();

            var activity = Activity.CreateMessageActivity() as Activity;

            activity.Text = "Hello world";

            var hintDirective = new HintDirective("hint text");

            var displayDirective = new DisplayRenderTemplateDirective()
            {
                Template = new BodyTemplate1()
                {
                    BackgroundImage = new TemplateImage()
                    {
                        ContentDescription = "Test",
                        Sources            = new List <ImageSource>()
                        {
                            new ImageSource()
                            {
                                Url = "https://via.placeholder.com/576.png/09f/fff",
                            }
                        }
                    },
                    Content = new TemplateContent()
                    {
                        Primary = new TemplateText()
                        {
                            Text = "Test", Type = "PlainText"
                        }
                    },
                    Title = "Test title",
                }
            };

            var simpleCard = new SimpleCard()
            {
                Title   = "This is a simple card",
                Content = "This is the simple card content"
            };

            activity.Attachments.Add(hintDirective.ToAttachment());
            activity.Attachments.Add(displayDirective.ToAttachment());
            activity.Attachments.Add(simpleCard.ToAttachment());

            var skillResponse = ExecuteActivityToResponse(mapper, new MergedActivityResult {
                MergedActivity = activity
            }, skillRequest);

            VerifyCardAttachmentAndDirectiveResponse(skillResponse, simpleCard, new List <IDirective>()
            {
                hintDirective, displayDirective
            });
        }
        public AlexaAdapter(AlexaAdapterOptions options = null, ILogger logger = null)
        {
            _options = options ?? new AlexaAdapterOptions();
            _logger  = logger ?? NullLogger.Instance;

            _requestMapper = new AlexaRequestMapper(new AlexaRequestMapperOptions
            {
                ShouldEndSessionByDefault = _options.ShouldEndSessionByDefault
            });
        }
        public void NonMessageActivityConverted()
        {
            var skillRequest = SkillRequestHelper.CreateIntentRequest();
            var mapper       = new AlexaRequestMapper();

            var activity = Activity.CreateTraceActivity("This is a trace") as Activity;

            var skillResponse = ExecuteActivityToResponse(mapper, activity, skillRequest);

            VerifyPlainTextResponse(skillResponse, string.Empty);
        }
Exemplo n.º 6
0
        public void MergeActivitiesReturnsSingleActivityAddingSpeakSsmlTag()
        {
            var alexaAdapter  = new AlexaRequestMapper();
            var inputActivity = MessageFactory.Text("This is the single activity", "This is<break strength=\"strong\"/>the SSML");

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                inputActivity
            });

            Assert.Equal(inputActivity, processActivityResult);
        }
Exemplo n.º 7
0
        public void MergeActivitiesTextWithNoPeriodAndEmptyText()
        {
            var alexaAdapter   = new AlexaRequestMapper();
            var firstActivity  = MessageFactory.Text("This is the first activity");
            var secondActivity = MessageFactory.Text("");

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                firstActivity, secondActivity
            });

            // We want to preserve the missing period here even though it is merged with empty text.
            Assert.Equal("This is the first activity", processActivityResult.MergedActivity.Text);
        }
        public void PlainTextMessageActivityConverted()
        {
            var skillRequest = SkillRequestHelper.CreateIntentRequest();
            var mapper       = new AlexaRequestMapper();

            var activity = Activity.CreateMessageActivity() as Activity;

            activity.Text       = "Hello world";
            activity.TextFormat = TextFormatTypes.Plain;

            var skillResponse = ExecuteActivityToResponse(mapper, activity, skillRequest);

            VerifyPlainTextResponse(skillResponse, activity.Text);
        }
        public void SimpleIntentRequestConverted()
        {
            var skillRequest  = SkillRequestHelper.CreateIntentRequest();
            var mapperOptions = new AlexaRequestMapperOptions {
                ServiceUrl = "service url"
            };
            var mapper = new AlexaRequestMapper(mapperOptions);

            ((IntentRequest)skillRequest.Request).Intent.Slots[mapperOptions.DefaultIntentSlotName].Value = "hello world";

            var convertedActivity = mapper.RequestToActivity(skillRequest);

            VerifyIntentRequest(skillRequest, convertedActivity, mapperOptions);
        }
        public void MessageActivityWithHeroCardConverted()
        {
            var skillRequest = SkillRequestHelper.CreateIntentRequest();
            var mapper       = new AlexaRequestMapper();

            var heroCard = new HeroCard
            {
                Title  = "Card title",
                Text   = "Card text",
                Images = new List <Microsoft.Bot.Schema.CardImage>
                {
                    new Microsoft.Bot.Schema.CardImage()
                    {
                        Url = "https://url"
                    }
                },
                Buttons = new List <CardAction>()
                {
                    new CardAction {
                        Title = "Places to buy", Type = ActionTypes.ImBack, Value = "Places To Buy"
                    },
                    new CardAction
                    {
                        Title = "I feel lucky",
                        Type  = ActionTypes.OpenUrl,
                        Image = "https://image",
                        Value = "https://value"
                    }
                }
            };

            var activity = Activity.CreateMessageActivity() as Activity;

            activity.Attachments.Add(new Attachment()
            {
                ContentType = HeroCard.ContentType, Content = heroCard
            });

            var skillResponse = ExecuteActivityToResponse(mapper, new MergedActivityResult {
                MergedActivity = activity
            }, skillRequest);

            Assert.NotNull(skillResponse.Response.Card);
            Assert.Equal(typeof(StandardCard), skillResponse.Response.Card.GetType());
            var card = skillResponse.Response.Card as StandardCard;

            Assert.Equal(heroCard.Text, card.Content);
            Assert.Equal(heroCard.Title, card.Title);
            Assert.Equal(heroCard.Images[0].Url, heroCard.Images[0].Url);
        }
        public void MergeActivitiesReturnsCorrectlyJoinedText()
        {
            var alexaAdapter = new AlexaRequestMapper();

            var firstActivity  = MessageFactory.Text("This is the first activity.");
            var secondActivity = MessageFactory.Text("This is the second activity");

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                firstActivity, secondActivity
            });

            Assert.Equal("This is the first activity. This is the second activity", processActivityResult.MergedActivity.Text);
        }
        public void TaskRequest()
        {
            var request = new LaunchRequest
            {
                Locale    = "en-US",
                RequestId = "amzn1.echo-api.request.00000000-0000-0000-0000-000000000000",
                Type      = "LaunchRequest",
                Timestamp = DateTime.Now,
                Task      = new LaunchRequestTask
                {
                    Name    = "AMAZON.PrintPDF",
                    Version = "1",
                    Input   = new PrintPdfV1
                    {
                        Title       = "Flywheel",
                        Description = "Flywheel",
                        Url         = "http://www.example.com/flywheel.pdf"
                    }
                }
            };

            var skillRequest = new SkillRequest
            {
                Request = request,
                Context = new Context
                {
                    System = new AlexaSystem()
                    {
                        Application = new Application(), User = new User()
                    }
                },
                Session = new Session()
                {
                    User = new User()
                }
            };

            var alexaMapper = new AlexaRequestMapper();
            var result      = alexaMapper.RequestToActivity(skillRequest);

            JsonConvert.SerializeObject(result,
                                        Newtonsoft.Json.Formatting.None,
                                        new JsonSerializerSettings
            {
                NullValueHandling = NullValueHandling.Ignore,
                Formatting        = Formatting.Indented
            });
        }
        public void MergeActivitiesReturnsSingleActivityAddingSpeakSsmlTag()
        {
            const string text = "This is the single activity";
            const string ssml = "This is<break strength=\"strong\"/>the SSML";

            var alexaAdapter  = new AlexaRequestMapper();
            var inputActivity = MessageFactory.Text(text, ssml);

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                inputActivity
            });

            Assert.Equal(text, processActivityResult.MergedActivity.Text);
            Assert.Equal($"<speak>{ssml}</speak>", processActivityResult.MergedActivity.Speak);
        }
        public void MergeActivitiesJoinedTextWithEndOfConversation()
        {
            var alexaAdapter = new AlexaRequestMapper();

            var activites = new List <Activity>()
            {
                MessageFactory.Text("This is the first activity."),
                (Activity)Activity.CreateEndOfConversationActivity(),
                MessageFactory.Text("This is the second activity")
            };

            var processActivityResult = alexaAdapter.MergeActivities(activites);

            Assert.Equal("This is the first activity. This is the second activity", processActivityResult.MergedActivity.Text);
            Assert.True(processActivityResult.EndOfConversationFlagged);
        }
        public void MergeActivitiesWithEndOfConversationOnly()
        {
            var alexaAdapter = new AlexaRequestMapper();

            var activity = (Activity)Activity.CreateEndOfConversationActivity();

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                activity
            });

            // Empty merged activities.
            Assert.NotNull(processActivityResult);
            Assert.Null(processActivityResult.MergedActivity);
            Assert.True(processActivityResult.EndOfConversationFlagged);
        }
        public void MergeActivitiesIgnoresNonMessageActivities()
        {
            var alexaAdapter = new AlexaRequestMapper();

            var firstActivity  = MessageFactory.Text("This is the first activity.");
            var traceActivity  = Activity.CreateTraceActivity("This is a trace") as Activity;
            var secondActivity = MessageFactory.Text("This is the second activity");
            var typingActivity = Activity.CreateTypingActivity() as Activity;

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                firstActivity, traceActivity, secondActivity, typingActivity
            });

            Assert.Equal("This is the first activity. This is the second activity", processActivityResult.Text);
        }
        public void MergeActivitiesReturnIdenticalSingleActivityNoSsml()
        {
            const string text = "This is the single activity";
            const string ssml = null;

            var alexaAdapter  = new AlexaRequestMapper();
            var inputActivity = MessageFactory.Text(text, ssml);

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                inputActivity
            });

            Assert.Equal(text, processActivityResult.MergedActivity.Text);
            Assert.Equal(ssml, processActivityResult.MergedActivity.Speak);
        }
Exemplo n.º 18
0
        public void MergeActivitiesReturnsSingleActivityWithComplexSpeakSsmlTag()
        {
            const string text = "Microsoft Ignite will take place online";
            const string ssml = "<speak version=\"1.0\" xmlns=\"http://www.w3.org/2001/10/synthesis\" xml:lang=\"en-US\"><voice name=\"en-US-AriaNeural\">Microsoft Ignite will take place online</voice></speak>";

            var alexaAdapter  = new AlexaRequestMapper();
            var inputActivity = MessageFactory.Text(text, ssml);

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                inputActivity
            });

            Assert.Equal(text, processActivityResult.MergedActivity.Text);
            // When removing the speak tag the serializer adds the missing space at the end of the xml element. This doesn't matter for rendering in Alexa so it is fine.
            Assert.Equal("<speak>Microsoft Ignite will take place online</speak>", processActivityResult.MergedActivity.Speak);
        }
        public void MergeActivitiesReturnsIdenticalSingleActivityWithSpeakSsmlTag()
        {
            const string text = "This is the single activity";
            const string ssml = "<speak>This is<break strength=\"strong\"/>the SSML</speak>";

            var alexaAdapter  = new AlexaRequestMapper();
            var inputActivity = MessageFactory.Text(text, ssml);

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                inputActivity
            });

            Assert.Equal(text, processActivityResult.MergedActivity.Text);
            // When removing the speak tag the serializer adds the missing space at the end of the xml element. This doesn't matter for rendering in Alexa so it is fine.
            Assert.Equal(ssml.Replace("/>", " />"), processActivityResult.MergedActivity.Speak);
        }
        public void MergeActivitiesReturnsCorrectlyJoinedSpeakWithSsml()
        {
            var alexaAdapter = new AlexaRequestMapper();

            // Note: The input activities deliberately have an activity where the speak tag
            // is included and one activity where it is not, to ensure the stripping / wrapping
            // of the speak tag is handled correctly.
            var firstActivity  = MessageFactory.Text("This is the first activity.", "This is<break strength=\"strong\"/>the first activity SSML");
            var secondActivity = MessageFactory.Text("This is the second activity.", "<speak>This is the second activity SSML</speak>");

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                firstActivity, secondActivity
            });

            Assert.Equal("<speak>This is<break strength=\"strong\"/>the first activity SSML<break strength=\"strong\"/>This is the second activity SSML</speak>",
                         processActivityResult.Speak);
        }
        public void MergeActivitiesReturnsCorrectlyInconsistentPeriods()
        {
            var alexaAdapter = new AlexaRequestMapper();

            // Note: The input activities deliberately have an activity where the speak tag
            // is included and one activity where it is not, to ensure the stripping / wrapping
            // of the speak tag is handled correctly.
            var firstActivity  = MessageFactory.Text("This is the first activity.", "This is<break strength=\"strong\"/>the first activity SSML");
            var secondActivity = MessageFactory.Attachment(new HeroCard("test", "test").ToAttachment()) as Activity;

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                firstActivity, secondActivity
            });

            Assert.Equal("<speak>This is<break strength=\"strong\"/>the first activity SSML</speak>", processActivityResult.MergedActivity.Speak);
            Assert.Equal("This is the first activity.", processActivityResult.MergedActivity.Text);
            Assert.False(processActivityResult.EndOfConversationFlagged);
        }
        public void MergeActivitiesAttachmentAndPlainText()
        {
            var alexaAdapter = new AlexaRequestMapper();

            var attachment = new Attachment
            {
                Name        = "Attachment1.jpg",
                ContentType = "image/jpeg",
                Content     = "https://somefantasticurl/",
            };
            var firstActivity  = MessageFactory.Text(JsonConvert.SerializeObject(attachment, HttpHelper.BotMessageSerializerSettings));
            var secondActivity = (Activity)MessageFactory.Attachment(attachment);

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity> {
                firstActivity, secondActivity
            });

            Assert.Equal("{   \"contentType\": \"image/jpeg\",   \"content\": \"https://somefantasticurl/\",   \"name\": \"Attachment1.jpg\" }", processActivityResult.MergedActivity.Text);
        }
        public void AppostrophiesNotConvertedNonSsml()
        {
            const string text         = "It's amazing <xml />";
            var          alexaAdapter = new AlexaRequestMapper();

            var skillRequest = SkillRequestHelper.CreateIntentRequest();
            var mapper       = new AlexaRequestMapper();

            var activity = Activity.CreateMessageActivity() as Activity;

            activity.Text = text;

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                activity
            });

            var skillResponse = ExecuteActivityToResponse(mapper, processActivityResult, skillRequest);

            VerifyPlainTextResponse(skillResponse, text);
        }
        public void AppostrophiesNotConvertedSsml()
        {
            const string text         = "It's amazing <break /> really";
            var          alexaAdapter = new AlexaRequestMapper();

            var skillRequest = SkillRequestHelper.CreateIntentRequest();
            var mapper       = new AlexaRequestMapper();

            var activity = Activity.CreateMessageActivity() as Activity;

            activity.Speak = text;

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                activity
            });

            var skillResponse = ExecuteActivityToResponse(mapper, processActivityResult, skillRequest);
            var outputSpeech  = skillResponse.Response.OutputSpeech as SsmlOutputSpeech;

            Assert.Equal($"<speak>{text}</speak>", outputSpeech.Ssml);
        }
        public void MergeActivitiesMergesAttachments()
        {
            var alexaAdapter = new AlexaRequestMapper();

            var firstActivity  = MessageFactory.Text("This is the first activity.");
            var secondActivity = MessageFactory.Text("This is the second activity");

            firstActivity.Attachments.Add(new SimpleCard {
                Title = "Simple card title", Content = "Test content"
            }.ToAttachment());
            secondActivity.Attachments = null;

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                firstActivity, secondActivity
            });

            Assert.Equal("This is the first activity. This is the second activity", processActivityResult.MergedActivity.Text);
            Assert.NotNull(processActivityResult.MergedActivity.Attachments);
            Assert.Equal(1, processActivityResult.MergedActivity.Attachments.Count);
            Assert.Equal(AlexaAttachmentContentTypes.Card, processActivityResult.MergedActivity.Attachments[0].ContentType);
        }
        public void MergeActivitiesCorrectlyConvertsMarkdownToPlainText()
        {
            var alexaAdapter = new AlexaRequestMapper();

            // Note: The input activities deliberately have an activity where the speak tag
            // is included and one activity where it is not, to ensure the stripping / wrapping
            // of the speak tag is handled correctly.

            var message = new StringBuilder();

            message.AppendLine("**This** ~~is~~ ***the*** first activity.");
            message.AppendLine("# Heading 1");
            message.AppendLine("This is another paragraph.");
            message.AppendLine("- Item 1");
            message.AppendLine("- Item 2");
            message.AppendLine("- Item 3");
            message.AppendLine("");
            message.AppendLine("## Heading 2");
            message.AppendLine("1. Item 1");
            message.AppendLine("2. Item 2");
            message.AppendLine("3. Item 3");
            message.AppendLine("");
            message.AppendLine("More info [visit our web site](www.microsoft.com)");

            var firstActivity  = MessageFactory.Text(message.ToString(), "This is<break strength=\"strong\"/>the first activity SSML");
            var secondActivity = MessageFactory.Text("This is the second activity.", "<speak>This is the second activity SSML</speak>");

            var processActivityResult = alexaAdapter.MergeActivities(new List <Activity>()
            {
                firstActivity, secondActivity
            });

            Assert.Equal("This is the first activity. Heading 1. This is another paragraph. Item 1, Item 2, Item 3. Heading 2. 1. Item 1, 2. Item 2, 3. Item 3. More info visit our web site www.microsoft.com. This is the second activity.",
                         processActivityResult.MergedActivity.Text);

            Assert.Equal("<speak>This is<break strength=\"strong\"/>the first activity SSML<break strength=\"strong\"/>This is the second activity SSML</speak>",
                         processActivityResult.MergedActivity.Speak);
        }
        public void IntentRequestMappedReturnsLocale()
        {
            // arrange
            var skillRequest = new SkillRequest
            {
                Request = new IntentRequest()
                {
                    Locale = "en-US",
                    Intent = new Intent()
                    {
                        Slots = new Dictionary <string, Slot>()
                        {
                            { "phrase", new Slot() }
                        }
                    }
                },
                Context = new Context
                {
                    System = new AlexaSystem()
                    {
                        Application = new Application(), User = new User()
                    }
                },
                Session = new Session()
                {
                    User = new User()
                }
            };


            // act
            var alexaMapper = new AlexaRequestMapper();
            var result      = alexaMapper.RequestToActivity(skillRequest);

            // assert
            Assert.Equal("en-US", result.Locale);
        }
 private static SkillResponse ExecuteActivityToResponse(AlexaRequestMapper mapper, MergedActivityResult mergedActivityResult, SkillRequest alexaRequest)
 {
     mergedActivityResult.MergedActivity = ActivityHelper.GetAnonymizedActivity(mergedActivityResult.MergedActivity);
     return(mapper.ActivityToResponse(mergedActivityResult, alexaRequest));
 }
Exemplo n.º 29
0
 private IEnumerable <IAlexaRequest> ConvertToAlexaRequest(IEnumerable <ITwitterResponse> tweets) => tweets.Select(x => AlexaRequestMapper.Map(x));
        public void MergeActivitiesReturnsNullWithNoActivities()
        {
            var alexaAdapter = new AlexaRequestMapper();

            Assert.Null(alexaAdapter.MergeActivities(new List <Activity>()));
        }