Issue with Rasa Custom Action Data Passing to External Node.js Server

Hello Rasa Community,

I’m currently facing an issue with passing data from a custom action to my external Node.js server. I’ve configured my endpoints.yml file as follows:

action_endpoint:
  url: "http://localhost:5055/webhook"
  cors:
    enable: true
    allow_origin: "*"

And this is my Node.js server code:

const express = require("express");
const cors = require("cors");
const morgan = require('morgan');

const app = express();
app.use(express.json());
app.use(cors());
app.use(morgan('dev'));

app.post("/webhook", (req, res) => {
  try {
    // Get data from Rasa action request
    const { action, domain, sender, session_id, tracker } = req.body;

    console.log('Tracks', action, domain, sender, session_id, tracker);

    // Custom logic for handling Rasa actions

    // Example: Send a response back to Rasa
    const response = {
      events: [],
      responses: {
        your_action_name: "Hello, this is your custom action response.",
      },
    };

    res.json(response);
  } catch (error) {
    console.error(error);
    res.status(500).json({ error: "An error occurred" });
  }
});

app.use("*", (req, res) => {
  return res.status(404).json({
    events: [],
    responses: {
      your_action_name: "This route is not available.",
    },
  })
})

app.listen(5055, () => {
  console.log("Listening :)");
});

My problem is that when I trigger the custom action, it reaches my external server, but I don’t receive the expected data in the console.log('Tracks', action, domain, sender, session_id, tracker);. Instead, all I get is the raw message sent from the user in JSON format:

{
  message: "Message sent from user"
}

The custom action involves a form, and I need access to its data on my external server. Any assistance in resolving this issue would be greatly appreciated.

Thank you for your help! If you need any additional information, please let me know.

You might want to take a look at this project which implements the action server in Javascript.

@stephens Thank you for your response. This project was my initial attempt, and the outcome remained unchanged. The action merely sends the message, which ultimately led to a crash in the app when using that library.

Can you offer any other suggestions? I’m currently facing a significant challenge and have attempted several approaches without success so far.

My other suggestion would be to use python instead of Javascript since this is supported and widely use. You’ll have to re-create the rasa-sdk if you want to use another language.

I have never used another language for the action server.

If you want to pursue Javascript further, I would read the rasa-sdk source code since you’ll need to implement this yourself.