//private async Task DenunciationFormStatusComplete(IDialogContext context, IAwaitable<DenunciationFormStatus> result) //{ //} #endregion #region FormSuggestion public async Task SuggestionFormComplete(IDialogContext context, IAwaitable <SuggestionForm> result) { IdentifyLanguage(); Activity replyToConversation = (Activity)context.MakeMessage(); replyToConversation.Recipient = replyToConversation.Recipient; replyToConversation.Type = "Message"; try { var suggestion = await result; int idtipocaso = 1; //Tipo de caso: sugerencia int idstatus = 1; //Estado: No revisado string folio; int idciudadano = 1; var fecha = DateTime.UtcNow; //Creación de folio folio = suggestion.Name.Substring(0, 2).ToUpper() + idciudadano + "_" + idtipocaso; //****Log to DataBase**** ConnectionDB.Chatbot_PGBEntities DB = new ConnectionDB.Chatbot_PGBEntities(); ConnectionDB.Casos NewCaso = new ConnectionDB.Casos(); NewCaso.idtipocaso = idtipocaso; NewCaso.idstatus = idstatus; NewCaso.folio = folio; NewCaso.idciudadano = idciudadano; NewCaso.nombre = suggestion.Name; NewCaso.email = suggestion.Contact; NewCaso.descripcion = suggestion.Suggestion; NewCaso.fecha_registro = DateTime.UtcNow; DB.Casos.Add(NewCaso); DB.SaveChanges(); DB.Dispose(); ConnectionDB.Chatbot_PGBEntities1 DBot = new ConnectionDB.Chatbot_PGBEntities1(); ConnectionDB.UserLogin NewUserLogBot = new ConnectionDB.UserLogin(); NewUserLogBot.Channel = replyToConversation.ChannelId; NewUserLogBot.UserID = replyToConversation.From.Id; NewUserLogBot.UserName = replyToConversation.From.Name; NewUserLogBot.Created = DateTime.UtcNow; NewUserLogBot.Message = ChatResponse.Thanks + " " + ChatResponse.Checkid + " Folio: " + folio + " " + ChatResponse.Status + " " + ChatResponse.Step5Else; DBot.UserLogins.Add(NewUserLogBot); DBot.SaveChanges(); DBot.Dispose(); await context.PostAsync(ChatResponse.Thanks); await context.PostAsync(ChatResponse.Checkid + "Folio: " + folio); await context.PostAsync(ChatResponse.Status); await context.PostAsync(ChatResponse.Step5Else); } catch (FormCanceledException) { await context.PostAsync(ChatResponse.formCanceled); } catch (Exception) { await context.PostAsync(ChatResponse.Error); } finally { context.Wait(MessageReceived); } }
/// <summary> /// POST: api/Messages /// Receive a message from a user and reply to it /// </summary> public async Task <HttpResponseMessage> Post([FromBody] Activity activity) { IdentifyLanguage(); #region Set CurrentBaseURL and ChannelAccount // Get the base URL that this service is running at // This is used to show images string CurrentBaseURL = this.Url.Request.RequestUri.AbsoluteUri.Replace(@"api/messages", ""); // Create an instance of BotData to store data BotData objBotData = new BotData(); // Instantiate a StateClient to save BotData StateClient stateClient = activity.GetStateClient(); // Use stateClient to get current userData BotData userData = await stateClient.BotState.GetUserDataAsync( activity.ChannelId, activity.From.Id); // Update userData by setting CurrentBaseURL and Recipient userData.SetProperty <string>("CurrentBaseURL", CurrentBaseURL); // Save changes to userData await stateClient.BotState.SetUserDataAsync( activity.ChannelId, activity.From.Id, userData); #endregion if (activity.Type == ActivityTypes.Message) { IMessageActivity mensaje = activity.AsMessageActivity(); Activity msj = (Activity)mensaje; msj.Recipient = msj.Recipient; msj.Type = "Message"; ConnectionDB.Chatbot_PGBEntities1 DBTop = new ConnectionDB.Chatbot_PGBEntities1(); ConnectionDB.UserLogin NewUserLogTop = new ConnectionDB.UserLogin(); NewUserLogTop.Channel = msj.ChannelId; NewUserLogTop.UserID = msj.From.Id; NewUserLogTop.UserName = msj.From.Name; NewUserLogTop.Created = DateTime.UtcNow; NewUserLogTop.Message = msj.Text; DBTop.UserLogins.Add(NewUserLogTop); DBTop.SaveChanges(); //DBTop.Dispose(); if (activity.Text.Contains("CANCELAR") || activity.Text.Contains("CANCEL")) { IdentifyLanguage(); ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); string response1 = ChatResponse.Cancel; string response2 = ChatResponse.Step5Else; Activity reply = activity.CreateReply(response1); Activity reply2 = activity.CreateReply(response2); await connector.Conversations.ReplyToActivityAsync(reply); await connector.Conversations.ReplyToActivityAsync(reply2); //Reinicia la conversación activity.GetStateClient().BotState.DeleteStateForUser(activity.ChannelId, activity.From.Id); } //else //{ // if (activity.Text.Contains("Adiós") || activity.Text.Contains("Adios")) // { // ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl)); // string response1 = ChatResponse.Goodbye; // //string response2 = ChatResponse.Step5Else; // Activity reply = activity.CreateReply(response1); // //Activity reply2 = activity.CreateReply(response2); // await connector.Conversations.ReplyToActivityAsync(reply); // //await connector.Conversations.ReplyToActivityAsync(reply2); // //Reinicia la conversación // activity.GetStateClient().BotState.DeleteStateForUser(activity.ChannelId, activity.From.Id); // } //} else { activity.Text = TranslatorHandler.DetectAndTranslate(activity); await Conversation.SendAsync(activity, MakeRoot); } } else { await HandleSystemMessage(activity); } var response = Request.CreateResponse(HttpStatusCode.OK); return(response); }