How to Send/Receive request/response to RASA using Flask


I am trying to create a simple GUI using the flask framework. I am using rasa_sdk and using my custom actions in it. Everything works fine from command line with my new and Now, I want to replace that command line with a simple GUI to mimic a chat application. I have read blogs and of course the RASA community, but, I am not able to do it.

Below are the commands I am using to train and test the model.

python -m rasa_nlu.train -c nlu_config.yml --data data/ -o models --fixed_model_name nlu --project rasbot --verbose

python -m rasa_core.train -d domain.yml -s data/ --nlu_threshold 0.5 --core_threshold 0.4 --fallback_action_name action_not_defined -o models/rasbot/dialogue --epochs 200

python -m rasa_core_sdk.endpoint --actions actions&


python -m -d models/rasbot/dialogue -u models/rasbot/nlu --port 5002 --credentials credentials.yml as suggested here

In my project folder I have a sub-folder named “gui”, which has in it and another sub-folder named templates. Below is how my looks:

from flask import Flask, render_template, request, jsonify
import requests
from flask_socketio import SocketIO

app = Flask(__name__)
app.config['SECRET_KEY'] = 'vnkdjnfjknfl1232#'
socketio = SocketIO(app)

@app.route('/', methods = ['GET'])
def loadPage():
	return render_template("session.html")

@app.route('/chat',methods = ['POST', 'GET'])
def session():
		msg = request.form['user_input']
		response ='http://localhost:5002/parse', params={'q':msg})
		response = response.json()
		entities = response.get("entities")
		topresponse = response["topScoringIntent"]
		intent = topresponse.get("intent")
		print("Intent {}, Entities {}".format(intent,entities))
		if intent == 'greet':
			return jsonify({"status":"success","response":"YAYYYYYYYYYYYYYY!"})
	except Exception as e:
		return jsonify({"status":"success","response":"Sorry no matching intent..."})
if __name__ == '__main__':

My request/response sequence is as follows: I build both rasa nlu and rasa core before following the below steps.

  1. I run “python” which starts the server and @localhost:5000 I can see my xyz.html page loaded.

  2. Then, I try to make a post request using the above code from **“ above)”**to localhost:5002 where my rasa core server is running by entering “Hi bot” and submit from my html page. I get the following error: error.

My questions are:

  1. Is it the right way to do, to connect GUI to rasa sdk?
  2. Am I forming the URL the right way?
  3. What should be the requests form (post or get) to chat with the bot?
  4. Is it the right way to send a message “Hi” from GUI which first goes to localhost:5000 and from there I make a GET/POST request to localhost:5002 to rasa core server?


I can’t see your error. Also what’s in your credentials, are you using the rest input channel?

I’m facing a somewhat similar issue. Were you able to figure it out?

1 Like

i get
requests.exceptions.ConnectionError: ('Connection aborted.', RemoteDisconnected('Remote end closed connection without response',))
did anyone find a solution to that problem ?

Even I am facing same issue with rasa 1.0.1 while training and app is running on Docker. I am using rasa core + nlu.

Can anyone help?

1 Like

Did you get some answer to your queries? I am also trying to do the same and having hard time with building connector.

1 Like

I am also trying to connect my Flask application with RASA. but could not. Please help, if you find any solution.

Hello @Nehasingh1300 and everyone, you can check out this old github repo GitHub - bhavaniravi/rasa-site-bot: A chatbot that fetches events details from a conference's website

I think changing the endpoints in the flask run bot to your local host or to server will work properly in today setup

1 Like