Skip to content

Commit

Permalink
#12 added forms
Browse files Browse the repository at this point in the history
  • Loading branch information
mariasanzs committed Jun 22, 2021
1 parent f74a700 commit 166e952
Show file tree
Hide file tree
Showing 8 changed files with 211 additions and 55 deletions.
Binary file modified actions/__pycache__/actions.cpython-36.pyc
Binary file not shown.
Binary file not shown.
104 changes: 82 additions & 22 deletions actions/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import time
from pathlib import Path
from typing import Any, Text, Dict, List
#from database_connectivity import DataUpdate
from database_connectivity import *

from rasa_sdk import Action, Tracker
from rasa_sdk.forms import FormAction
Expand Down Expand Up @@ -231,24 +231,84 @@ def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[T
dispatcher.utter_message(text="Ya has terminado con tu relajación! 😀")
return []

# class ActionPreguntarApellido(Action):
# def name(self) -> Text:
# return "action_ask_last_name"

# def run(
# self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
# ) -> List[EventType]:
# first_name = tracker.get_slot("first_name")
# dispatcher.utter_message(text=f"So {first_name}, what is your last name?")
# return []

#class ActionSubmit(Action):
# def name(self) -> Text:
# return "action_submit"

# def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
#dispatcher.utter_message(text="Vale, me acordaré de que tu nombre es {0} y tus apellidos {1}".format(
# tracker.get_slot("nombre"), tracker.get_slot("apellidos")))
# DataUpdate(tracker.get_slot('nombre'),tracker.get_slot('apellidos'))
# dispatcher.utter_message("Tus datos han sido guardados. Gracias")
# return []
class ActionPointsValorate(Action):

def name(self) -> Text:
return "action_points_valorate"

def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
puntuacion1 = int(tracker.get_slot('puntos1'))
puntuacion2 = int(tracker.get_slot('puntos2'))
puntuacion3 = int(tracker.get_slot('puntos3'))

dispatcher.utter_message(text="Me has dado una puntuación de ...")
points = puntuacion1+puntuacion2+puntuacion3
if points == 0:
dispatcher.utter_message(text="*️⃣*️⃣*️⃣*️⃣*️⃣")
dispatcher.utter_message(text="Jo, intentaremos mejorar, gracias")
elif points <= 6:
dispatcher.utter_message(text="⭐*️⃣*️⃣*️⃣*️⃣")
dispatcher.utter_message(text="Algo es algo ... seguiremos mejorando")
elif points <=12:
dispatcher.utter_message(text="⭐⭐*️⃣*️⃣*️⃣")
dispatcher.utter_message(text="bueno, muchas gracias por tu valoración")
elif points <=18:
dispatcher.utter_message(text="⭐⭐⭐*️⃣*️⃣")
dispatcher.utter_message(text="No está mal, muchas gracias.")
elif points <=24:
dispatcher.utter_message(text="⭐⭐⭐⭐*️⃣")
dispatcher.utter_message(text="Genial!, muchisimas gracias")
else:
dispatcher.utter_message(text="⭐⭐⭐⭐⭐")
dispatcher.utter_message(text="Guau!, muchisimas gracias, me alegro de que te haya gustado tanto")
return []

class ActionPreguntarApellido(Action):
def name(self) -> Text:
return "action_ask_last_name"
def run(
self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
) -> List[EventType]:
first_name = tracker.get_slot("first_name")
dispatcher.utter_message(text=f"So {first_name}, what is your last name?")
return []


class ActionSubmit(Action):
def name(self) -> Text:
return "action_submit"
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
#dispatcher.utter_message(text="Vale, me acordaré de que tu nombre es {0} y tus apellidos {1}".format(
# tracker.get_slot("nombre"), tracker.get_slot("apellidos")))
DataUpdate(tracker.get_slot('nombre'))
nombre = tracker.get_slot('nombre')
dispatcher.utter_message("Tus datos han sido guardados. Gracias")
return []

class ActionSubmitValoracion(Action):
def name(self) -> Text:
return "action_submit_valoracion"
def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
puntuacion1 = tracker.get_slot('puntos1')
puntuacion2 = tracker.get_slot('puntos2')
puntuacion3 = tracker.get_slot('puntos3')
sugerencias = tracker.get_slot('cambios')

DataValoracion(puntuacion1,puntuacion2,puntuacion3,sugerencias)
dispatcher.utter_message("Genial! tendremos en cuenta tu opinión")
return []
"""
class ValorateForm(FormAction):
def name(self) -> Text:
return "valorate_form"
@staticmethod
def required_slots(tracker):
if tracker.get_slot('puntos1') == True:
return ["puntos1", "puntos2", "puntos3","cambios"]
else:
return ["confirm_exercise", "sleep",
"diet", "stress", "goal"]
"""
49 changes: 49 additions & 0 deletions actions/database_connectivity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import mysql.connector

def DataUpdate(Nombre):
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="root",
database="rasa_database"
)

mycursor = mydb.cursor()

hola = mycursor.execute("SELECT * FROM pacientes WHERE nombre='%s' % (Nombre)")
myresult = mycursor.fetchall()
if (hola):
print("este nombre ya estaba")
else:
sql = 'INSERT INTO pacientes(nombre) VALUES ("{0}");'.format(Nombre)
mycursor.execute(sql)

#sql = 'INSERT IGNORE INTO pacientes(nombre) VALUES ("{0}");'.format(Nombre)
#mycursor.execute(sql)



mydb.commit()

print(mycursor.rowcount, "record inserted.")

def DataValoracion(Puntos1,Puntos2,Puntos3,Cambios):
mydb = mysql.connector.connect(
host="localhost",
user="root",
passwd="root",
database="rasa_database"
)

mycursor = mydb.cursor()

sql = 'INSERT INTO valoracion(fecha,pregunta1,pregunta2,pregunta3,cambios) VALUES (now(),"{0}","{1}","{2}","{3}");'.format(Puntos1,Puntos2,Puntos3,Cambios)
mycursor.execute(sql)

mydb.commit()

print(mycursor.rowcount, "record inserted.")

if __name__=="__main__":
DataUpdate("Maria")
DataValoracion("6","8","7","Mejorar Respuestas")
9 changes: 9 additions & 0 deletions data/nlu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ nlu:
- quiero darte mi nombre
- te he dicho como me llamo?
- queiro darte mi nombre
- intent: valorar_chatbot
examples: |
- encuesta de satisfacción
- realizar encuesta de satisfacción
- quiero hacer una encuesta de satisfacción
- valorar chatbot
- quiero valorar a nonabot
- valorar el sistema
- realizar encuesta
- intent: pedir_consejo
examples: |
- /pedir_consejo{"problema": "miedo"}
Expand Down
27 changes: 24 additions & 3 deletions data/rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@ rules:
- feedback: repeticion2
- action: action_repeticion

- rule: Activate form
- rule: Activate Form - Name
steps:
- intent: pedir_nombre
- action: utter_preguntar_nombre
- action: name_form
- active_loop: name_form

- rule: Submit form
- rule: Submit form - Name
condition:
# Condition that form is active.
- active_loop: name_form
Expand All @@ -85,4 +86,24 @@ rules:
- requested_slot: null
# The actions we want to run when the form is submitted.
- action: action_submit
- action: utter_slots_values
- action: utter_slots_values

- rule: Activate Form - Valorate
steps:
- intent: valorar_chatbot
- action: valorate_form
- active_loop: valorate_form

- rule: Submit form - Valorate
condition:
# Condition that form is active.
- active_loop: valorate_form
steps:
# Form is deactivated
- action: valorate_form
- active_loop: null
- slot_was_set:
- requested_slot: null
# The actions we want to run when the form is submitted.
- action: action_submit_valoracion
- action: action_points_valorate
23 changes: 0 additions & 23 deletions database_connectivity.py

This file was deleted.

54 changes: 47 additions & 7 deletions domain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ intents:
use_entities: true
- preguntar_que_tal:
use_entities: true
- valorar_chatbot:
use_entities: true
- chitchat:
use_entities: true
- pedir_consejo:
Expand All @@ -59,6 +61,10 @@ entities:
- feedback
- repeticiones
- imagen
- puntos1
- puntos2
- puntos3
- cambios
slots:
problema:
type: rasa.shared.core.slots.TextSlot
Expand Down Expand Up @@ -90,16 +96,31 @@ slots:
initial_value: null
auto_fill: true
influence_conversation: true
apellidos:
type: rasa.shared.core.slots.TextSlot
requested_slot:
type: rasa.shared.core.slots.UnfeaturizedSlot
initial_value: null
auto_fill: true
influence_conversation: true
requested_slot:
influence_conversation: false
puntos1:
type: rasa.shared.core.slots.UnfeaturizedSlot
initial_value: null
auto_fill: true
influence_conversation: false
puntos2:
type: rasa.shared.core.slots.UnfeaturizedSlot
initial_value: null
auto_fill: true
influence_conversation: false
puntos3:
type: rasa.shared.core.slots.UnfeaturizedSlot
initial_value: null
auto_fill: true
influence_conversation: false
cambios:
type: rasa.shared.core.slots.TextSlot
initial_value: null
auto_fill: true
influence_conversation: true
responses:
utter_saludar:
- text: Hola! Como te encuentras hoy 👋🏼?
Expand Down Expand Up @@ -192,7 +213,17 @@ responses:
- text: Vale, ¿comenzamos? 🏁
- text: ¿Empezamos ya 💕 ?
utter_slots_values:
- text: Vale, me acordaré de que eres {nombre} {apellidos}.
- text: Vale, me acordaré de que eres {nombre}.
utter_ask_puntos1:
- text: Del uno al 10, ¿Crees que la información que soy es fiable?
utter_ask_puntos2:
- text: Del uno al 10, ¿Crees que soy práctica?
utter_ask_puntos3:
- text: Del uno al 10, ¿Crees que me expreso de una forma correcta? (Amable, cercana, comprensiva ...)
utter_ask_cambios:
- text: ¿Qué aspectos crees que deberíamos de cambiar?
- text: ¿Qué cambiarías tu de NonaBot?
- text: ¿Qué crees que tendríamos que añadir o cambiar en próximas actualizaciones?
utter_valorar_situacion:
- buttons:
- payload: '/pedir_consejo{"problema": "miedo"}'
Expand Down Expand Up @@ -321,10 +352,19 @@ actions:
- action_third_paused
- action_4_paused
- action_end_guided
- action_points_valorate
- action_submit_valoracion
forms:
name_form:
apellidos:
- type: from_text
nombre:
- type: from_text
valorate_form:
puntos1:
- type: from_text
puntos2:
- type: from_text
puntos3:
- type: from_text
cambios:
- type: from_text
e2e_actions: []

0 comments on commit 166e952

Please sign in to comment.