I am having trouble sending multiple messages via dispatcher.utter_message(). I am sending requests to an API then the results i get i show them in a loop via dispatcher.utter_message(). The problem is that is only displays the first coincidence or the first elemen in the request result. if i have more that one coincidence i need to show it Here is my code:
class ActionBuscarVacante(Action):
def name(self):
return "action_buscar_vacante"
def run(self,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
ubicacion=tracker.get_slot("ubicacion")
puesto=tracker.get_slot("puesto")
if ubicacion and puesto:
r = requests.get(url=url+"?filterByFormula=AND(%7BReg%7D%3D%22"+ubicacion+"%22%2C%7BStatus%7D%3D%22Activa%22%2C%7BPuesto%7D%3D%22"+puesto+"%22)", headers=h)
elif ubicacion and not puesto:
r = requests.get(url=url+"?filterByFormula=AND(%7BReg%7D%3D%22"+ubicacion+"%22%2C%7BStatus%7D%3D%22Activa%22)", headers=h)
elif puesto and not ubicacion:
r = requests.get(url=url+"?filterByFormula=AND(%7BPuesto%7D%3D%22"+puesto+"%22%2C%7BStatus%7D%3D%22Activa%22)", headers=h)
data = r.json()
rec =data['records']
if not rec:
dispatcher.utter_message(template="utter_no_encontrado")
return [AllSlotsReset()]
for i in range(len(rec)):
registro=rec[i]
f=registro['fields']
imagen=f['Imagen'][0]['url']
reg=ubicacion
info=f['info']
puesto=f['Puesto']
dispatcher.utter_message(
template="utter_info_vacante",
ubicacion=reg,
puesto=puesto,
informacion=info,
img=imagen,
)
return [FollowupAction('action_listen')]