Unable to connect the custom action functions

Hi, I am trying to upgrade to the latest rasa version, I couldn’t able to connet the custom action functions the below code is my server.py file:

import logging from rasa_core.agent import Agent from rasa_core.interpreter import RasaNLUInterpreter from rasa_core.channels import CollectingOutputChannel from flask import json, render_template from klein import Klein

logger = logging.getLogger(name)

def request_parameters(request): if request.method.decode(‘utf-8’, ‘strict’) == ‘GET’: return { key.decode(‘utf-8’, ‘strict’): value[0].decode(‘utf-8’, ‘strict’) for key, value in request.args.items()} else: content = request.content.read() try: return json.loads(content.decode(‘utf-8’, ‘strict’)) except ValueError as e: logger.error("Failed to decode json during respond request. " "Error: {}. Request content: " “’{}’”.format(e, content)) raise

class Server: app = Klein() def init(self, model_directory, interpreter): self.model_directory = model_directory self.interpreter = interpreter self.agent = self._create_agent(model_directory, interpreter)

@staticmethod
def _create_agent(model_directory, interpreter):
	"""Creates a Rasa Agent which runs when the server is started"""
	try:
		return Agent.load(model_directory, interpreter)
	except Exception as e:
		logger.warn("Failed to load any agent model. Running "
					"Rasa Core server with out loaded model now. {}"
					"".format(e))
		return None

@app.route("/api/v1/status", methods=['GET'])
def status(self, request):
	"""Check if the server is running and responds with the status."""
	request.setHeader('Access-Control-Allow-Origin', '*')
	return json.dumps({'status': 'OK'})

@app.route('/api/v1/<sender_id>/parse', methods=['GET', 'POST'])
def parse(self, request, sender_id):
	request.setHeader('Content-Type', 'application/json')
	request_params = request_parameters(request)

	if 'query' in request_params:
		message = request_params.pop('query')
	elif 'q' in request_params:
		message = request_params.pop('q')
	else:
		request.setResponseCode(400)
		return json.dumps({"error": "Invalid parse parameter specified"})
	try:
		response = self.agent.start_message_handling(message, sender_id)
		request.setResponseCode(200)
		return json.dumps(response)
	except Exception as e:
		request.setResponseCode(500)
		logger.error("Caught an exception during "
					 "parse: {}".format(e), exc_info=1)
		return json.dumps({"error": "{}".format(e)})

@app.route('/api/v1/<sender_id>/respond', methods=['GET', 'POST'])
def respond(self, request, sender_id):
	request.setHeader('Content-Type', 'application/json')
	request.setHeader('Access-Control-Allow-Origin', '*')
	request_params = request_parameters(request)
	if 'query' in request_params:
		message = request_params.pop('query')
	elif 'q' in request_params:
		message = request_params.pop('q')
	else:
		request.setResponseCode(400)
		return json.dumps({"error": "Invalid parse parameter specified"})
	try:
		out = CollectingOutputChannel()
		response = self.agent.handle_message(message, output_channel=out, sender_id=sender_id)
		request.setResponseCode(200)
		return json.dumps(response)
	except Exception as e:
		request.setResponseCode(500)
		logger.error("Caught an exception during "
					 "parse: {}".format(e), exc_info=1)
		return json.dumps({"error": "{}".format(e)})

if name == “main”: server = Server(“models/default/dialogue”, RasaNLUInterpreter(“models/default” “/nlu”)) server.app.run(“0.0.0.0”, 8081)

Please help me to resolve the issue, Thank you.

i am currently used below versions: rasa_nlu - 0.13.7, rasa_core - 0.13.0a4

Hello @gsagarvarma Are you still working on this issue? If yes, do you mind formatting all the code you provided so that it would be easier to debug it? :slight_smile:

Hello @Juste thanks for your reply. I am still working on that issue. Please would you mind sending me any reference links or docs on how to integrate my bot which runs on cmd to any other custom web UI’s? I would be thankful to you!

i am unable to integrate my advance Rasa chatbot with Custom UI. Previously i used Rasa stack versions as follows: rasa nlu: 0.12.0, rasa core: 0.9.0. I am working fine with old once but when i tried to migrate to latest updates i am face this integration issue with custom UI. Please help me. Thanks in advance.