public async Task StartAsync(IDialogContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var activity = (IMessageActivity)context.Activity;

            EndUserAndAgentConversationMappingState mappingState =
                await VsoHelper.GetStateFromVsoGivenAgentConversationId(activity.Conversation.Id);

            if (ActivityHelper.HasAttachment(activity))
            {
                await context.PostWithRetryAsync(
                    $"Sending file attachments to user is not supported. " +
                    $"Please send it via SharePoint > Share > Email. Email is in VSO ticket");
            }
            else
            {
                await ActivityHelper.SendMessageToUserEx((IMessageActivity)context.Activity,
                                                         mappingState.EndUserName,
                                                         mappingState.EndUserId,
                                                         activity.Text.Replace(DialogMatches.ReplyToUser + " ", ""),
                                                         mappingState.VsoId);
            }

            await OnlineStatus.SetMemberActive(
                context.Activity.From.Name,
                context.Activity.From.Id,
                OnlineStatus.AgentMemberType);

            context.Done <object>(null);
        }
Esempio n. 2
0
        private async Task OnDeadlineSelected(IDialogContext context, IAwaitable<IEnumerable<DateTime>> result)
        {
            try
            {
                // "result" contains the date (or array of dates) returned from the prompt
                IEnumerable<DateTime> momentOrRange = await result;
                var deadline = momentOrRange.First(); // DeadlinePrompt.MomentOrRangeToString(momentOrRange);

                // Store date
                context.ConversationData.SetValue("deadline", deadline);

                var description = context.ConversationData.GetValue<string>("description");

                string mobilePhone = string.Empty;
                string alias = string.Empty;

                if (!context.UserData.TryGetValue(UserProfileHelper.UserProfileKey, out UserProfile userProfile))
                {
                    mobilePhone = userProfile.MobilePhone;
                    alias = userProfile.Alias;
                }

                var vsoTicketNumber = await VsoHelper.CreateTaskInVso(VsoHelper.VirtualAssistanceTaskType,
                    context.Activity.From.Name,
                    description,
                    ConfigurationManager.AppSettings["AgentToAssignVsoTasksTo"],
                    deadline,
                    "",
                    null,
                    context.Activity.ChannelId);

                MicrosoftAppCredentials.TrustServiceUrl(ActivityHelper.TeamsServiceEndpoint);

                AdaptiveCard card = new AdaptiveCard();
                card.Body.Add(new AdaptiveTextBlock()
                {
                    Text = $"New Virtual Assistance request from {context.Activity.From.Name}. VSO:{vsoTicketNumber}",
                    Size = AdaptiveTextSize.Large,
                    Wrap = true,
                    Separator = true
                });
                var summary = new AdaptiveFactSet
                {
                    Facts = new List<AdaptiveFact>
                    {
                        new AdaptiveFact("Who", context.Activity.From.Name),
                        new AdaptiveFact("What", description),
                        new AdaptiveFact("When", deadline.ToString()),
                        new AdaptiveFact("Vso", vsoTicketNumber.ToString()),
                    }
                };
                card.Body.Add(summary);

                using (var connectorClient = await BotConnectorUtility.BuildConnectorClientAsync(ActivityHelper.TeamsServiceEndpoint))
                {
                    var channelInfo = GetHardcodedChannelId();
                    context.ConversationData.SetValue("VsoId", vsoTicketNumber);
                    context.ConversationData.SetValue("EndUserConversationId", context.Activity.Conversation.Id);

                    var conversationResourceResponse = await ConversationHelpers.CreateAgentConversation(channelInfo,
                        card,
                        $"New research request from {context.Activity.Recipient.Name}",
                        connectorClient,
                        vsoTicketNumber,
                        context.Activity as IMessageActivity);

                    EndUserAndAgentConversationMappingState state =
                        new EndUserAndAgentConversationMappingState(vsoTicketNumber.ToString(),
                            context.Activity.From.Name,
                            context.Activity.From.Id,
                            context.Activity.Conversation.Id,
                            conversationResourceResponse.Id);

                    await state.SaveInVso(vsoTicketNumber.ToString());
                }

                await context.PostWithRetryAsync("Thank you! I have posted following to internal agents. " +
                                                 "I will be in touch with you shortly. " +
                                                 $"Please use reference #{vsoTicketNumber} for this request in future. " +
                                                 $"What: {description}. When: {deadline}.");

                context.Done<object>(null);
            }
            catch (TooManyAttemptsException)
            {
                await context.PostWithRetryAsync("TooManyAttemptsException. Restarting now...");
            }
            catch (System.Exception e)
            {
                WebApiConfig.TelemetryClient.TrackException(e, new Dictionary<string, string>
                {
                    {"dialog", "InternetResearchDialog" },
                    {"function", "OnDeadlineSelected" }
                });
                throw;
            }
        }
        private async Task OnConfirmResearchDialog(IDialogContext context, IAwaitable <bool> result)
        {
            if (result == null)
            {
                throw new InvalidOperationException((nameof(result)) + Strings.NullException);
            }

            var sendIt = await result;

            if (sendIt)
            {
                var additionalInfoFromUser = context.ConversationData.GetValue <string>(AdditionalInfoKey);
                var description            = context.ConversationData.GetValue <string>(DescriptionKey);
                var deadline = DateTime.Parse(context.ConversationData.GetValue <string>(DeadlineKey));

                var vsoTicketNumber = await VsoHelper.CreateTaskInVso(VsoHelper.ResearchTaskType,
                                                                      context.Activity.From.Name,
                                                                      description + Environment.NewLine + additionalInfoFromUser,
                                                                      ConfigurationManager.AppSettings["AgentToAssignVsoTasksTo"],
                                                                      deadline,
                                                                      "",
                                                                      userProfile,
                                                                      context.Activity.ChannelId);

                context.ConversationData.SetValue(VsoIdKey, vsoTicketNumber);
                context.ConversationData.SetValue(EndUserConversationIdKey, context.Activity.Conversation.Id);

                try
                {
                    var    conversationTitle   = $"Web research request from {userProfile} via {context.Activity.ChannelId} due {deadline}";
                    string agentConversationId = await ConversationHelpers.CreateAgentConversationEx(context,
                                                                                                     conversationTitle,
                                                                                                     CreateCardForAgent(context,
                                                                                                                        additionalInfoFromUser,
                                                                                                                        description,
                                                                                                                        deadline,
                                                                                                                        vsoTicketNumber),
                                                                                                     userProfile);

                    EndUserAndAgentConversationMappingState state =
                        new EndUserAndAgentConversationMappingState(vsoTicketNumber.ToString(),
                                                                    context.Activity.From.Name,
                                                                    context.Activity.From.Id,
                                                                    context.Activity.Conversation.Id,
                                                                    agentConversationId);

                    await state.SaveInVso(vsoTicketNumber.ToString());

                    await context.PostWithRetryAsync("Sure. I have sent your request to a freelancer. " +
                                                     $"Please use #{vsoTicketNumber} for referencing this request in future. " +
                                                     "At this point, any message you send will be sent directly to the freelancer. They may take time to respond, " +
                                                     "or may have clarifying questions which I will relay back to you.");

                    context.Done <object>(true);
                }
                catch (System.Exception e)
                {
                    await context.PostWithRetryAsync("Sorry, I ran into an issue while connecting with agent. Please try again later.");

                    WebApiConfig.TelemetryClient.TrackException(e, new Dictionary <string, string> {
                        { "function", "OnConfirmResearchDialog.CreateAgentConversation" }
                    });
                    context.Done <object>(false);
                }
            }
            else
            {
                await context.PostWithRetryAsync("Okay, I have cancelled this request.");

                context.Done <object>(false);
            }
        }
Esempio n. 4
0
        private async Task CreateProject(IDialogContext context)
        {
            try
            {
                var description = context.ConversationData.GetValue <string>(DescriptionKey);
                var userProfile = context.UserData.GetValue <UserProfile>(UserProfileHelper.UserProfileKey);
                var deadline    = DateTime.UtcNow.AddHours(_minHoursToCompleteResearch);

                var vsoTicketNumber = await VsoHelper.CreateTaskInVso(VsoHelper.ResearchTaskType,
                                                                      context.Activity.From.Name,
                                                                      description,
                                                                      ConfigurationManager.AppSettings["AgentToAssignVsoTasksTo"],
                                                                      deadline,
                                                                      "",
                                                                      userProfile,
                                                                      context.Activity.ChannelId);

                context.ConversationData.SetValue(VsoIdKey, vsoTicketNumber);
                context.ConversationData.SetValue(EndUserConversationIdKey, context.Activity.Conversation.Id);

                var    conversationTitle   = $"Web research request from {userProfile} via {context.Activity.ChannelId} due {deadline}";
                string agentConversationId = await ConversationHelpers.CreateAgentConversationEx(context,
                                                                                                 conversationTitle,
                                                                                                 CreateCardForAgent(context,
                                                                                                                    description,
                                                                                                                    deadline,
                                                                                                                    vsoTicketNumber,
                                                                                                                    userProfile),
                                                                                                 userProfile);

                EndUserAndAgentConversationMappingState state =
                    new EndUserAndAgentConversationMappingState(vsoTicketNumber.ToString(),
                                                                context.Activity.From.Name,
                                                                context.Activity.From.Id,
                                                                context.Activity.Conversation.Id,
                                                                agentConversationId);

                await state.SaveInVso(vsoTicketNumber.ToString());

                WebApiConfig.TelemetryClient.TrackEvent("CreateProject", new Dictionary <string, string>()
                {
                    { "from", context.Activity.From.Name },
                    { UserProfileHelper.UserProfileKey, userProfile.ToString() },
                    { DescriptionKey, description },
                    { "deadline", deadline.ToString() },
                    { VsoIdKey, vsoTicketNumber.ToString() },
                });

                await context.PostWithRetryAsync($"OK, your research project is #{vsoTicketNumber}. " +
                                                 $"We'll get to work on this shortly and send you a confirmation email.\n\n\n\n" +
                                                 $"In the meantime, feel free to tell me more, like: " +
                                                 $"what do you want to do with this info?");

                context.Done <object>(true);
            }
            catch (System.Exception e)
            {
                try
                {
                    if (context.ConversationData.TryGetValue(VsoIdKey, out string vsoTicketNumber))
                    {
                        // close this ticket
                        await VsoHelper.CloseProject(Convert.ToInt32(vsoTicketNumber));
                    }
                }
                catch (System.Exception exception)
                {
                    WebApiConfig.TelemetryClient.TrackException(exception, new Dictionary <string, string>
                    {
                        { "debugNote", "Error closing project during exception received in CreateProject" },
                        { "CreateProjectException", e.ToString() },
                    });
                }
                await context.PostWithRetryAsync("Sorry, I ran into an issue while connecting with agent. Please try again later.");

                WebApiConfig.TelemetryClient.TrackException(e, new Dictionary <string, string> {
                    { "function", "OnConfirmResearchDialog.CreateAgentConversation" }
                });
                context.Done <object>(false);
            }
        }