How do I trigger a custom action from outside with a slash command?

I have a custom action that I want to be triggered from outside, similar to how you can use /restart, e.g. /action_go_to_next_topic.

As far as I know, this is somehow possible for intents, but I do not want it to be tied to intents since the user should not be able to trigger it accidentally. In general, I do not want to mix internal commands with user input.

1 Like

Hi @melonlord

You could probably use this code

function customActionTrigger() {
  $.ajax({
    url: "http://localhost:5055/webhook/",
    type: "POST",
    contentType: "application/json",
    data: JSON.stringify({
      next_action: action_name,
      tracker: {
        sender_id,
      },
    }),
    success(botResponse, status) {
      console.log("Response from Rasa: ", botResponse, "\nStatus: ", status);

      if (Object.hasOwnProperty.call(botResponse, "responses")) {
        setBotResponse(botResponse.responses);
      }
      $("#userInput").prop("disabled", false);
    },
    error(xhr, textStatus) {
      // if there is no response from rasa server
      setBotResponse("");
      console.log("Error from bot end: ", textStatus);
      $("#userInput").prop("disabled", false);
    },
  });
}

This calls your action server, You would need to pass a senderID

1 Like