Rasa Rest API implementation in 3.x version

I am using rasa v2.2.3 and implemented custom rest api for user interaction. Now as I am upgrading to rasa v3.6 I am facing issue with this rest api configuration. I am trying to fetch tracker in channel configuration, but it is not working with app.agent. Can someone help to achieve this?

Hello, To fetch the tracker in Rasa v3.6, ensure you’re using the updated API endpoints and methods. Check the Rasa documentation for any changes in the API structure between v2.2.3 and v3.6. You might need to update your code to match the new configuration. New York DMV

Best Regards,

Daniel Lopez

In Rasa 3.6, access the tracker in your custom REST API by injecting the TrackerStore and using tracker_store.get_or_create_tracker(conversation_id). The crucial step is determining how to access your Rasa application’s tracker_store object, which depends on your Rasa server setup (remote or embedded). Adapt the provided example code to your framework and test thoroughly.

It sounds like you’re facing a challenge with fetching the tracker in your custom REST API configuration while upgrading from Rasa v2.2.3 to v3.6. Here are a few steps you can take to resolve this issue:

  1. Enable API: Ensure that the REST API is enabled in your Rasa server by running the command:

    rasa run --enable-api
    

    This will expose the necessary API endpoints for interacting with the tracker.

  2. Custom Channel Configuration: Make sure your custom channel is correctly configured. You can use the RestInput class as a template for your custom channel connector. Here’s an example:

    from rasa.core.channels.channel import InputChannel, CollectingOutputChannel
    from rasa.core.channels.rest import RestInput
    
    class MyCustomChannel(InputChannel):
        def name(self) -> Text:
            return "myio"
    
        def blueprint(self, server: Sanic) -> Blueprint:
            blueprint = Blueprint("myio", __name__)
    
            @blueprint.route("/webhook", methods=["POST"])
            async def receive(request: Request) -> Response:
                user_message = UserMessage(
                    text=request.json.get("message"),
                    output_channel=CollectingOutputChannel(),
                    sender_id=request.json.get("sender_id")
                )
                await self.handle_message(user_message, server)
                return response.json({"message": "Received"})
    
            return blueprint
    
        async def handle_message(self, user_message: UserMessage, server: Sanic) -> None:
            # Your logic to handle the message
            pass
    

    This example sets up a custom channel named “myio” and defines a webhook endpoint to receive messages.

  3. Fetch Tracker: To fetch the tracker programmatically, you can use the agent object within your custom channel. Here’s an example:

    tracker = request.app.agent.tracker_store.retrieve(sender_id)
    

    This will retrieve the tracker for the given sender_id.

  4. Check Permissions: Ensure that your custom channel has the necessary permissions to access the tracker. You might need to configure your tracker store to allow access from custom channels.

  5. Persistent Tracker Store: If you’re using a persistent tracker store like MongoDB, make sure it’s correctly set up and accessible by your custom channel.