コード例 #1
0
        private async Task <SkillResponse> CommuteAsync(ICollection <string> favoriteLines)
        {
            IList <Line> lines = await GetStatusesAsync(string.Join(",", favoriteLines));

            var paragraphs = new List <string>();

            bool hasMultipleStatuses = lines.Count > 1;

            foreach (Line line in lines.OrderBy((p) => p.Name, StringComparer.Ordinal))
            {
                string text = StatusIntent.GenerateResponse(new[] { line });

                if (hasMultipleStatuses)
                {
                    string displayName = Verbalizer.LineName(line.Name, asTitleCase: true);
                    text = string.Format(CultureInfo.CurrentCulture, Strings.CommuteIntentPrefixFormat, displayName, text);
                }

                paragraphs.Add(text);
            }

            return(SkillResponseBuilder
                   .Tell(paragraphs)
                   .WithCard(Strings.CommuteIntentCardTitle, string.Join("\n", paragraphs))
                   .Build());
        }
コード例 #2
0
        private SkillResponse Unauthorized(Session session)
        {
            Logger.LogInformation(
                "User with Id {UserId} has an invalid access token.",
                session.User.UserId);

            return(SkillResponseBuilder
                   .Tell(Strings.CommuteIntentInvalidToken)
                   .LinkAccount()
                   .Build());
        }
コード例 #3
0
        private SkillResponse NotLinked(Session session)
        {
            Logger.LogInformation(
                "User with Id {UserId} has not linked account.",
                session.User?.UserId);

            return(SkillResponseBuilder
                   .Tell(Strings.CommuteIntentAccountNotLinked)
                   .LinkAccount()
                   .Build());
        }
コード例 #4
0
        /// <inheritdoc />
        public Task <SkillResponse> RespondAsync(Intent intent, Session session)
        {
            Logger.LogWarning(
                "Unknown intent {IntentName} cannot be handled for session Id {SessionId}.",
                intent.Name,
                session.SessionId);

            var response = SkillResponseBuilder
                           .Tell(Strings.UnknownCommand)
                           .Build();

            return(Task.FromResult(response));
        }
コード例 #5
0
        private SkillResponse NoFavorites(Session session)
        {
            Logger.LogInformation(
                "User with Id {UserId} has set no line preferences.",
                session.User.UserId);

            string text = Strings.CommuteIntentNoFavorites;

            return(SkillResponseBuilder
                   .Tell(text)
                   .WithCard(Strings.CommuteIntentCardTitle, text)
                   .Build());
        }
コード例 #6
0
        /// <inheritdoc />
        public Task <SkillResponse> RespondAsync(Intent intent, Session session)
        {
            string[] paragraphs = new[]
            {
                Strings.HelpIntentParagraph1,
                Strings.HelpIntentParagraph2,
                Strings.HelpIntentParagraph3,
                Strings.HelpIntentParagraph4,
            };

            var result = SkillResponseBuilder
                         .Tell(paragraphs)
                         .ShouldNotEndSession()
                         .Build();

            return(Task.FromResult(result));
        }
コード例 #7
0
        /// <inheritdoc />
        public async Task <SkillResponse> RespondAsync(Intent intent, Session session)
        {
            string rawLineName = null;

            if (intent.Slots.TryGetValue("LINE", out Slot slot))
            {
                rawLineName = slot.Value;
            }

            string id = Lines.MapNameToId(rawLineName);
            SkillResponseBuilder builder;

            if (string.IsNullOrEmpty(id))
            {
                builder = SkillResponseBuilder
                          .Tell(Strings.StatusIntentUnknownLine)
                          .WithReprompt();
            }
            else if (string.Equals(id, "elizabeth", StringComparison.Ordinal))
            {
                builder = SkillResponseBuilder
                          .Tell(Strings.StatusIntentElizabethLineNotImplemented)
                          .WithReprompt();
            }
            else
            {
                IList <Line> statuses = await GetStatusesAsync(id);

                string cardTitle = Lines.ToCardTitle(statuses[0]?.Name ?? string.Empty);
                string text      = GenerateResponse(statuses);

                builder = SkillResponseBuilder
                          .Tell(text)
                          .WithCard(cardTitle, text);
            }

            return(builder.Build());
        }
コード例 #8
0
        /// <inheritdoc />
        public async Task <SkillResponse> RespondAsync(Intent intent, Session session)
        {
            ICollection <string> sentences = await GetRawDisruptionsAsync();

            string cardContent;

            if (sentences.Count > 0)
            {
                cardContent = string.Join("\n", sentences);
                sentences.Add(Strings.DisruptionIntentGoodServiceOnOtherLines);
            }
            else
            {
                string text = Strings.DisruptionIntentNoDisruption;

                sentences.Add(text);
                cardContent = text;
            }

            return(SkillResponseBuilder
                   .Tell(sentences)
                   .WithCard(Strings.DisruptionIntentCardTitle, cardContent)
                   .Build());
        }