示例#1
0
 private async Task CompleteJobAsync(BotAdapter adapter, string botId, JobStorage jobStorage,
                                     UiPathJobResponse uiPathJobResponse,
                                     CancellationToken cancellationToken)
 {
     jobStorage.TryGetValue(uiPathJobResponse.JobId, out var jobInfo);
     if (jobInfo != null)
     {
         await adapter.ContinueConversationAsync(botId, jobInfo.ConversationReference,
                                                 CompleteJobHandler(uiPathJobResponse),
                                                 cancellationToken);
     }
 }
示例#2
0
        private BotCallbackHandler CompleteJobHandler(UiPathJobResponse uiPathJobResponse)
        {
            return(async(turnContext, token) =>
            {
                var jobStorage = await _jobStatePropertyAccessor.GetAsync(turnContext, () => new JobStorage(), token);

                jobStorage[uiPathJobResponse.JobId].Completed = true;
                await _jobStatePropertyAccessor.SetAsync(turnContext, jobStorage, token);

                await _jobState.SaveChangesAsync(turnContext, cancellationToken : token);

                var activities = new List <IActivity>();
                var jobCompleteActivity = turnContext.Activity.CreateReply();
                jobCompleteActivity.Text = $"Job {uiPathJobResponse.JobId} is complete. {uiPathJobResponse.Message}";
                jobCompleteActivity.Speak = $"Job {uiPathJobResponse.JobId} is complete. {uiPathJobResponse.Message}";
                jobCompleteActivity.InputHint = InputHints.IgnoringInput;
                activities.Add(jobCompleteActivity);
                _logger.LogDebug($"Received UI Path Job Response Type {uiPathJobResponse.Type}");
                Activity reply;
                switch (uiPathJobResponse.Type)
                {
                case UiPathEventType.HelpDesk:
                    reply = turnContext.Activity.CreateReply(
                        "Networking team has approved your help desk ticket. Which of the following approved routers would you like to purchase?");
                    reply.Type = ActivityTypes.Message;
                    reply.Speak =
                        "Networking team has approved your help desk ticket. Which of the following approved routers would you like to purchase?";
                    reply.InputHint = InputHints.IgnoringInput;
                    reply.TextFormat = TextFormatTypes.Plain;
                    reply.SuggestedActions = new SuggestedActions()
                    {
                        Actions = new List <CardAction>()
                        {
                            new CardAction()
                            {
                                Title = "2QW1646 Cisco RV320", Type = ActionTypes.ImBack,
                                Value = "Please purchase 2QW1646 Cisco RV320"
                            },
                            new CardAction()
                            {
                                Title = "NETGEAR R6700 Nighthawk", Type = ActionTypes.PostBack,
                                Value = "Please purchase  NETGEAR R6700 Nighthawk"
                            },
                            new CardAction()
                            {
                                Title = "TP-Link AC1200", Type = ActionTypes.MessageBack,
                                Value = "Please purchase TP-Link AC1200",
                            }
                        }
                    };

                    activities.Add(reply);
                    break;

                case UiPathEventType.Amazon:
                    reply = turnContext.Activity.CreateReply();
                    reply.Attachments.Add(GetReceiptCard().ToAttachment());
                    reply.Speak = "Here is your order information.";
                    reply.InputHint = InputHints.IgnoringInput;
                    activities.Add(reply);
                    break;
                }

                await turnContext.SendActivitiesAsync(activities.ToArray(), token);
            });
        }