How to Fetch MongoDb Data in Custom Action?

endpoint.yml

tracker_store:
   type: mongod
   url: mongodb://localhost:27017/
   db: sample
   collection: actions
   username:  
   password:

Action File

from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
class ActionHelloWorld(Action):
    def name(self):
        return "action_hello_world"
    def run(self, dispatcher, tracker, domain):
        print("Hello Your Name",(tracker.latest_message)['text'])
        print("Here oim ")
        print("this is tracker",tracker)
        dispatcher.utter_message("Hello World!")
        return []

You should be able to access it the way you would any database from within the action code. The custom action is full python so you can run arbitrary code there.

1 Like