MongoDB Rasa Interaction

Hello everyone!,

I have some Issue using Rasa and MongoDB (tracker store). When I make a query in Python, they always brings 15 records less. I’ll show you some configuration detailed below:

stories.yml

- story: Flujo
  steps:  - intent: msg_inicial
  - action: utter_asesor_en_linea
  - action: contacto_cliente_form
  - active_loop: contacto_cliente_form
  - slot_was_set:    - requested_slot: usuario_acepta_documentacion
  - slot_was_set:    - requested_slot: usuario_ingresa_rut
  - slot_was_set:    - requested_slot: razon_respuesta
  - slot_was_set:    - requested_slot: alternativa_solicitud
  - slot_was_set:    - requested_slot: adjuntar_documentos
  - slot_was_set:    - requested_slot: null
  - active_loop: null
  - action: action_despedida
  - action: action_final
  - action: action_restart

The action_final calls the function to query the MongoDB table.

class ActionFinal(Action):

    def name(self) -> Text:
        return "action_final"    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:  
        
        derivar_ejecutivo = tracker.get_slot('derivar_ejecutivo')
        razon_respuesta = tracker.get_slot('razon_respuesta')
        
        vocalcom(derivar_ejecutivo, razon_respuesta) # Calling table in MongoDB

        return [Restarted()]
def vocalcom(derivar_ejecutivo, razon_respuesta):
    mongo = pymongo.MongoClient('mongodb://localhost', 27017)
    dbase = mongo['COP16-DEV']
    interaction = dbase['conversations']
    interaction_bkp = dbase['conversations_bkp']
    result = interaction.find({ 'latest_event_time': { '$exists': True } }).sort("latest_event_time", -1).limit(1)

    k=0    
    is_ejecutivo = derivar_ejecutivo
    respuesta_bool = False
    texto_bot = ""
    conv = []
    
   for x in result:
        for i in x['events']:
            if i['event'] == 'bot':
                if 'text' in x['events'][k]:
                    print(type(i['text']))
                    conv.append(i['text'])
                    if 'Un ejecutivo' in i['text']:
                        respuesta_bool = 'Un ejecutivo' in i['text']
                        texto_bot = i['text']
                        print(respuesta_bool)
                        print(is_ejecutivo)
                        print("Aqui va la respuesta: ", texto_bot)
                timestamp_bot = i['timestamp']
                date_boot = datetime.fromtimestamp(timestamp_bot)
                print(i['text'], " :::::" + str(date_boot))        
            elif i['event'] == 'user':
                if 'text' in x['events'][k]:
                    conv.append(i['text'])
                timestamp_user = i['timestamp']
                date_user = datetime.fromtimestamp(timestamp_user)
                print(i['text'], " :::::" + str(date_user))
            k = k + 1        print(len(x['events']))

I am actually using Rasa 3.3.1, python 3.7.15, and creating a chatbot.

Thanks for any help!