/// <summary>
        /// This is start of the Dialog and Prompting for User name
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public async Task StartAsync(IDialogContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            isSms       = context.Activity.ChannelId == ActivityHelper.SmsChannelId;
            userProfile = await UserProfileHelper.GetUserProfile(context);

            minHoursToCompleteResearch = Convert.ToInt32(ConfigurationManager.AppSettings["ResearchProjectViaTeamsMinHours"]);

            //// This will Prompt for Name of the user.
            //var message = isSms ? BuildIntroMessageForSms(context) : BuildIntroMessageForTeams(context);
            //await context.PostWithRetryAsync(message);

            var minLength         = isSms ? 5 : 150;
            var maxLength         = 1000;
            var charLimitGuidance = $"I need a minimum of {minLength} characters and maximum of {maxLength} characters to process.";
            var promptDescription = new PromptText(
                "Okay, I'll find a human freelancer who can do the research for you. " +
                $"What would you like a freelancer to research? {(isSms ? "" : charLimitGuidance)}",
                charLimitGuidance + " Please try again.",
                "Sorry, I didn't understand that description. Please reply to start over again.",
                2, minLength, maxLength);

            context.Call(promptDescription, OnDescriptionReceivedAsync);
        }
        public static async Task <bool> RelayMessageToAgentIfThereIsAnOpenResearchProject(IDialogContext context)
        {
            int?vsoId = await GetResearchVsoIdFromVso(context.Activity.ChannelId, context.Activity.From.Name);

            if (vsoId == null)
            {
                return(false);
            }

            var userProfile = await UserProfileHelper.GetUserProfile(context);

            context.UserData.SetValue(UserProfileHelper.UserProfileKey, userProfile);

            string agentConversationId = await VsoHelper.GetAgentConversationIdForVso((int)vsoId);

            if (string.IsNullOrEmpty(agentConversationId))
            {
                return(false);
            }

            await context.PostWithRetryAsync("OK, I'll add that to the project.");

            //await SendAutoReplyIfNeeded(context, vsoId);

            IMessageActivity messageActivity = (IMessageActivity)context.Activity;

            if (ActivityHelper.HasAttachment(messageActivity))
            {
                await context.PostWithRetryAsync(
                    $"Sending file attachments is not supported. " +
                    $"Please send it via an accessible link within Microsoft");
            }
            else
            {
                await ActivityHelper.SendMessageToAgentAsReplyToConversationInAgentsChannel(
                    messageActivity,
                    messageActivity.Text,
                    agentConversationId,
                    (int)vsoId);
            }

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

            return(true);
        }
예제 #3
0
        private static Attachment BuildOptionsForNewUserWithResearchPptApptOptions(IDialogContext context)
        {
            var heroCard = new HeroCard
            {
                Title    = $"Hello {UserProfileHelper.GetFriendlyName(context)}! I am Expert Intelligence Bot.",
                Subtitle = "I am supported by experts who can work for you.",
                Text     = "We can do a few things. Please select one of the options so I can collect few information to get started. " +
                           "After that a project manager will review your request and follow up." +
                           $"You can also reach out to me by sending SMS at {ConfigurationManager.AppSettings["BotPhoneNumber"]}",
                Buttons = new List <CardAction>
                {
                    new CardAction(ActionTypes.ImBack, "Internet Research", value: "research"),
                    new CardAction(ActionTypes.ImBack, "PowerPoint Improvements", value: "ppt"),
                    new CardAction(ActionTypes.ImBack, "virtual assistant", value: "virtual assistant"),
                    new CardAction(ActionTypes.ImBack, "Talk to an agent", value: "agent")
                }
            };

            return(heroCard.ToAttachment());
        }
        private static async Task SendAutoReplyIfNeeded(IDialogContext context, int?vsoId)
        {
            // Check when was the last time we sent message to agent
            var timeStampWhenLastMessageWasSentByAgent =
                await OnlineStatus.GetTimeWhenMemberWasLastActive(OnlineStatus.AgentMemberType);

            var  timeSinceLastMessageWasSentByAgent = DateTime.UtcNow.Subtract((DateTime)timeStampWhenLastMessageWasSentByAgent);
            bool autoReplyWasSentAWhileBack         = DateTime.UtcNow.Subtract(GetAutoReplySentOnTimeStamp(context))
                                                      .TotalMinutes > MinutesToWaitBeforeSendingAutoReply;

            if (timeSinceLastMessageWasSentByAgent.TotalMinutes >= MinutesToWaitForAgentOnlineBeforeSendingAutoReply && autoReplyWasSentAWhileBack)
            {
                await context.PostWithRetryAsync($"Hi {UserProfileHelper.GetFriendlyName(context)}, " +
                                                 $"My experts are working on Project #{vsoId}. " +
                                                 $"Current status of this project is {await VsoHelper.GetProjectStatus((int)vsoId)}. " +
                                                 "Either experts are busy or offline at the moment. " +
                                                 $"They were online {timeSinceLastMessageWasSentByAgent.TimeAgo()}. Please wait. ");

                SetAutoReplySentOnTimeStamp(context);
            }
        }