Get Rasa chatbot response from APIs

Hi, I am using Rasa 2.x

My need is: I want to make POST request using Django app and test it on Postman. The call should go to Rasa and the response should come in json format. Eg: POST Reguest: “Hi” Response: “Hello, How may I help you?”

I want this for my response to be integrated with other app. I found docs and videos around how can I use this via HTML file but I just want conversation to happen at backend. I also saw this but it does not gives me just response. Please help…!

Hi @Sajjadmanal , you can try using requests Python module in Django backend, enable REST channel, run Rasa with rasa run --enable-api and then send POST requests from Django backend pointing to your chatbot.

@stephens please help

@ChrisRahme Please help

Did you configure the rest: endpoint in the credentials.yml as documented here. Also, make sure you see the endpoint as enabled when you start Rasa. With the --debug option you should see output like this when Rasa starts:

2022-01-19 19:06:52 DEBUG    rasa.core.utils  - Available web server routes: 
/conversations/<conversation_id:path>/messages     POST                           add_message
/webhooks/rest                                     GET                            custom_webhook_RestInput.health
/webhooks/rest/webhook                             POST                           custom_webhook_RestInput.receive

Here’s an example curl command that hits one of my demo bots. You’ll see the json response if you run this.

curl --location --request POST 'https://gstephens.org/webhooks/rest/webhook' \
 --header 'Content-Type: application/json' \
 --data-raw '{ "sender": "curl", "message": "Hello"}'
2 Likes

Please don’t spam tags - there’s a reason multiple tagging isn’t allowed in a post as mentioned in the Code of Conduct:

When you mention others to answer your question, be patient, we do our best to answer questions as quickly as possible, but sometimes we cannot jump on all questions right away. Additionally, the list of mentioned people should not exceed one person per post.


That said, you should provide more pertinent detail on what you have tried, as recommended in “How to ask a great question”, for example:

  • What’s the URL you are sending your information to?
  • What does your request look like?
  • What command did you use to run the server?
  • Are you using local mode or server mode? If the latter, which deployment method are you using?
  • What are the relevant configuration points?

What you should generally do is add rest: to your credentials.yml file like here. You then make a POST request to http://localhost:5005/webhooks/rest/webhook with the following raw body:

{
    "sender": "User",
    "message": "Hello, world!"
}

My post was hidden by the spam filter until now, but now I see others provided an answer.

@ChrisRahme Sorry for the multiple tags. Understood the policy now. Thanks

  • What’s the URL you are sending your information to? Just want to receive json response of the POST messages.
  • What does your request look like? Request will be like: {“text”:”Hi”} (need a method to post this request.
  • What command did you use to run the server? I deployed using docker-compose file and inside docker-compose.override.yml, I mentioned the rasa image
  • Are you using local mode or server mode? If the latter, which deployment method are you using? Server mode. I am using docker-compose up to run everything
  • What are the relevant configuration points? Don’t understand this one.

@toza-mimoza thanks

1 Like

@stephens Thanks. Will try checking this.

The REST webhook will take a JSON body and return a JSON response as JSON.

As mentioned, the request should be

{
    "sender": "User",
    "message": "Hello, world!"
}

You shoud use rasa run --enable-api --cors "*" --debug

Your endpoints.yml file


It’s all mentioned in the docs for the REST channel.

1 Like

Thanks @ChrisRahme

1 Like

Happy to help :slight_smile:

1 Like