コード例 #1
0
        private string GetSuggestedActionsReplyText(IMessageActivity reply, string replyText)
        {
            int start = replyText.IndexOf("(");
            int end   = replyText.IndexOf(")") + 1;

            var suggestedActionSubString = replyText.Substring(start, end - start);

            int startActions = suggestedActionSubString.IndexOf("'") + 1;
            int endActions   = suggestedActionSubString.LastIndexOf("'");

            var suggestedActions = suggestedActionSubString.Substring(startActions, endActions - startActions).Split("/");

            reply.SuggestedActions = AdaptiveCards.CreateSuggestedAction(suggestedActions);
            return(replyText.Replace(suggestedActionSubString, ""));
        }
コード例 #2
0
        private async Task HandleConversation(ITurnContext turnContext, CancellationToken cancellationToken)
        {
            var text = turnContext.Activity.Text;
            IMessageActivity reply = Activity.CreateMessageActivity();

            // Handle conversation scenarios
            if (conversation.ConversationDictionary.ContainsKey(text))
            {
                var replyText = conversation.ConversationDictionary[text];
                if (replyText.Contains("Adaptive Card"))
                {
                    replyText = await GetAdaptiveCardsReplyText(reply, replyText, turnContext, cancellationToken);
                }
                if (replyText.Contains("Suggested Action"))
                {
                    replyText = GetSuggestedActionsReplyText(reply, replyText);
                }
                reply.Text = replyText;
            }
            else
            {
                switch (text.ToLower())
                {
                case "microsoft store":
                case "adaptive card":
                    // Display an Adaptive Card for Microsoft Store
                    reply.Attachments.Add(AdaptiveCards.CreateAdaptiveCardAttachment("store.json"));
                    break;

                case "microsoft article":
                    // Display an Adaptive Card for support article
                    reply.Attachments.Add(AdaptiveCards.CreateAdaptiveCardAttachment("article.json"));
                    break;

                case "suggested action":
                    reply.SuggestedActions = AdaptiveCards.CreateSuggestedAction(new string[] { "10am", "1pm", "3pm" });
                    break;

                default:
                    reply.Text = $"I am sorry, I cannot help you with\n'{text}'\n\n If you would like me to transfer you to a customer service agent please type 'Talk to agent'";
                    break;
                }
            }

            await turnContext.SendActivityAsync(reply, cancellationToken);
        }