简体   繁体   中英

Handle message in python not working properly

I am working with rasa(latest version),but not able to send response to chatbot just because of handle_channel method,right now i am getting following error

"error": "Object of type coroutine is not JSON serializable"

Here is my code,where i am wrong ?

@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)})

are you sure that you are not mixing methods up here? According to the documentation , you might either want to try:

handle_message(message, message_preprocessor=None, **kwargs)

or

handle_text(text_message, message_preprocessor=None, output_channel=None, sender_id='default')

Keep in mind to import the right libraries since there was a renaming since 1.0, just in case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM