private async Task CloseProject(IDialogContext context, IMessageActivity message) { if (TryParseVsoId(message.Text, out int vsoId)) { await context.PostWithRetryAsync($"Sure I can help close project #{vsoId}"); await VsoHelper.CloseProject(vsoId); await context.PostWithRetryAsync($"{vsoId} project is now closed."); await PromptForCreatingNewProjectAfterClosingExistingOne(context); } else { await context.PostWithRetryAsync("Sorry, I ran into an error"); context.Call(new UserHelpDialog(), EndDialog); } }
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); } }