예제 #1
0
        public async Task Goodbye(IDialogContext context, LuisResult result)
        {
            IdentifyLanguage();
            Activity replyToConversation = (Activity)context.MakeMessage();

            replyToConversation.Recipient = replyToConversation.Recipient;
            replyToConversation.Type      = "Message";
            try
            {
                var response = ChatResponse.Goodbye;

                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  = response;
                DBot.UserLogins.Add(NewUserLogBot);
                DBot.SaveChanges();

                await context.PostAsync(response);

                //await context.PostAsync("El lenguaje es: " + TranslatorHandler.isoName);

                context.Wait(MessageReceived);
            }
            catch (Exception exc)
            {
                // await context.PostAsync("El error es: " + exc);
                throw exc;
            }
        }
예제 #2
0
        public async Task Greet(IDialogContext context, LuisResult result)
        {
            IdentifyLanguage();

            Activity replyToConversation = (Activity)context.MakeMessage();

            replyToConversation.Recipient = replyToConversation.Recipient;
            replyToConversation.Type      = "Message";

            try
            {
                IdentifyLanguage();
                var response = ChatResponse.Greeting;

                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  = response;
                DBot.UserLogins.Add(NewUserLogBot);
                DBot.SaveChanges();
                DBot.Dispose();

                await context.PostAsync(response);

                context.Wait(MessageReceived);
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }
예제 #3
0
        public async Task ConsultStatus(IDialogContext context, LuisResult result)
        {
            IdentifyLanguage();
            Activity replyToConversation = (Activity)context.MakeMessage();

            replyToConversation.Recipient = replyToConversation.Recipient;
            replyToConversation.Type      = "Message";
            try
            {
                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  = replyToConversation.Text;
                DBot.UserLogins.Add(NewUserLogBot);
                DBot.SaveChanges();

                var denunciationD = new FormDialog <FormStatus>(new FormStatus(), FormStatus.BuildForm, FormOptions.PromptInStart);
                context.Call(denunciationD, FormStatusComplete);
            }
            catch (Exception)
            {
                var error = ChatResponse.Error;
                await context.PostAsync(error);

                context.Wait(MessageReceived);
            }
        }
예제 #4
0
        public async Task InformationR(IDialogContext context, LuisResult result)
        {
            Activity replyToConversation = (Activity)context.MakeMessage();

            replyToConversation.Recipient = replyToConversation.Recipient;
            replyToConversation.Type      = "Message";

            try
            {
                IdentifyLanguage();
                var request = ChatResponse.InformationRGreet;

                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  = request;
                DBot.UserLogins.Add(NewUserLogBot);
                DBot.SaveChanges();

                await context.PostAsync(request);

                var informationrForm = new FormDialog <InformationRForm>(new InformationRForm(), InformationRForm.BuildForm, FormOptions.PromptInStart);
                context.Call(informationrForm, InformationRFormComplete);
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }
예제 #5
0
        public async Task Suggestion(IDialogContext context, LuisResult result)
        {
            IdentifyLanguage();

            Activity replyToConversation = (Activity)context.MakeMessage();

            replyToConversation.Recipient = replyToConversation.Recipient;
            replyToConversation.Type      = "Message";

            try
            {
                var suggestion = ChatResponse.SuggestionGreet;
                var ifcancel   = ChatResponse.IfCancel;

                await context.PostAsync(suggestion + "\n\n" + ifcancel);

                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  = suggestion + " " + ifcancel;
                DBot.UserLogins.Add(NewUserLogBot);
                DBot.SaveChanges();
                DBot.Dispose();

                var suggestionForm = new FormDialog <SuggestionForm>(new SuggestionForm(), SuggestionForm.BuildForm, FormOptions.PromptInStart);
                context.Call(suggestionForm, SuggestionFormComplete);
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }
예제 #6
0
        private async Task <Activity> HandleSystemMessage(Activity message)
        {
            if (message.Type == ActivityTypes.DeleteUserData)
            {
                // Implement user deletion here
                // If we handle user deletion, return a real message
            }
            else if (message.Type == ActivityTypes.ConversationUpdate)
            {
                IConversationUpdateActivity conversationupdate = message;
                using (var scope = DialogModule.BeginLifetimeScope(Conversation.Container, message))
                {
                    var client = scope.Resolve <IConnectorClient>();
                    if (conversationupdate.MembersAdded.Any())
                    {
                        var reply = message.CreateReply();


                        foreach (var newMember in conversationupdate.MembersAdded)
                        {
                            if (newMember.Id != message.Recipient.Id)
                            {
                                reply.Text = "¡Hola!";

                                ConnectionDB.Chatbot_PGBEntities1 DBTop         = new ConnectionDB.Chatbot_PGBEntities1();
                                ConnectionDB.UserLogin            NewUserLogTop = new ConnectionDB.UserLogin();
                                NewUserLogTop.Channel  = message.ChannelId;
                                NewUserLogTop.UserID   = message.From.Id;
                                NewUserLogTop.UserName = message.From.Name;
                                NewUserLogTop.Created  = DateTime.UtcNow;
                                NewUserLogTop.Message  = "Inicia nueva conversación --> " + reply.Text;
                                DBTop.UserLogins.Add(NewUserLogTop);
                                DBTop.SaveChanges();
                                DBTop.Dispose();

                                await client.Conversations.ReplyToActivityAsync(reply);
                            }
                        }
                    }
                }
            }
            else if (message.Type == ActivityTypes.ContactRelationUpdate)
            {
                // Handle add/remove from contact lists
                // Activity.From + Activity.Action represent what happened
            }
            else if (message.Type == ActivityTypes.Typing)
            {
                // Handle knowing tha the user is typing
            }
            else if (message.Type == ActivityTypes.Ping)
            {
            }

            return(null);
        }
예제 #7
0
        //private async Task ComplaintFormStatusComplete(IDialogContext context, IAwaitable<ComplaintFormStatus> result)
        //{
        //}
        #endregion

        #region FormInformationR
        public async Task InformationRFormComplete(IDialogContext context, IAwaitable <InformationRForm> result)
        {
            Activity replyToConversation = (Activity)context.MakeMessage();

            replyToConversation.Recipient = replyToConversation.Recipient;
            replyToConversation.Type      = "Message";

            IdentifyLanguage();

            try
            {
                var informationr = await result;

                int    idtipocaso = 4; //Tipo de caso: solicitud de informacion
                int    idstatus   = 1; //Estado: No revisado
                string folio;
                int    idciudadano = 1;
                var    fecha       = DateTime.UtcNow;

                //Creación de folio
                folio = informationr.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         = informationr.Name;
                NewCaso.email          = informationr.Contact;
                NewCaso.descripcion    = informationr.Information;
                NewCaso.fecha_registro = DateTime.UtcNow;
                DB.Casos.Add(NewCaso);
                DB.SaveChanges();

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

                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);
            }
        }
예제 #8
0
        /// <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);
        }