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); } }
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); } }