Ejemplo n.º 1
0
        private async Task <DialogTurnResult> MessagePromptStepAsync(
            WaterfallStepContext stepContext,
            CancellationToken cancellationToken)
        {
            PromptOptions messagePrompt = new PromptOptions();

            if (!stepContext.Values.TryGetValue(HandoffState, out HandoffContextState contextState))
            {
                // Attempt to continue on from a previous context

                if (stepContext.Options is HandoffContextState passthoughContextState)
                {
                    stepContext.Values.Add(HandoffState, passthoughContextState);
                }
                else
                {
                    // Build our conversation callback

                    ConversationReference conversationReference = stepContext.Context.Activity.GetConversationReference();

                    string proxyId = await _conversationProxy.RegisterConversationAsync(conversationReference, cancellationToken);

                    // Net new connection, connect to the handoff agent

                    string sessionId = await _matchmaker.NewSessionAsync(proxyId);

                    HandoffContextState newContextState = new HandoffContextState
                    {
                        MatchmakerSessionId = sessionId,
                        ProxyId             = proxyId
                    };

                    stepContext.Values.Add(HandoffState, newContextState);

                    // Add message to the background info
                    // TODO: Refactor
                    IStatePropertyAccessor <List <string> > conversationStateAccessors = _conversationState.CreateProperty <List <string> >(MessageHistoryStateKey);

                    List <string> conversationData = await conversationStateAccessors.GetAsync(stepContext.Context, () => new List <string>());

                    if (conversationData != null && conversationData.Count > 0)
                    {
                        await _matchmaker.AddSessionBackgroundAsync(sessionId, conversationData);

                        // Clear the current history once it has been passed to the matchmaker
                        await conversationStateAccessors.DeleteAsync(stepContext.Context);
                    }

                    _log.LogInformation("Set up new handoff session");

                    // Let the user know
                    messagePrompt.Prompt = MessageFactory.Text("You are being connected to a support agent, please wait...");
                }
            }

            return(await stepContext.PromptAsync(nameof(TextPrompt), messagePrompt));
        }
Ejemplo n.º 2
0
        private async Task <DialogTurnResult> MessagePromptStepAsync(
            WaterfallStepContext stepContext,
            CancellationToken cancellationToken)
        {
            PromptOptions messagePrompt = new PromptOptions();

            if (!stepContext.Values.TryGetValue(HandoffState, out HandoffContextState contextState) ||
                contextState == null)
            {
                // Attempt to continue on from a previous context

                if (stepContext.Options is HandoffContextState passthoughContextState)
                {
                    stepContext.Values.Add(HandoffState, passthoughContextState);
                }
                else
                {
                    // Build our conversation callback

                    ConversationReference conversationReference = stepContext.Context.Activity.GetConversationReference();

                    string proxyId = await _conversationProxy.RegisterConversationAsync(conversationReference, cancellationToken);

                    // Net new connection, connect to the handoff agent

                    string sessionId = await _matchmaker.NewSessionAsync(proxyId);

                    HandoffContextState newContextState = new HandoffContextState
                    {
                        MatchmakerSessionId = sessionId,
                        ProxyId             = proxyId
                    };

                    stepContext.Values.Add(HandoffState, newContextState);

                    _log.LogInformation("New handoff session created");

                    // Let the user know
                    messagePrompt.Prompt = MessageFactory.Text("You have been put in the queue to be connected with a user, please wait...");
                }
            }

            return(await stepContext.PromptAsync(nameof(TextPrompt), messagePrompt));
        }