RasaHQ / rasa

💬 Open source machine learning framework to automate text- and voice-based conversations: NLU, dialogue management, connect to Slack, Facebook, and more - Create chatbots and voice assistants
https://rasa.com/docs/rasa/
Apache License 2.0
18.65k stars 4.6k forks source link

CollectingOutputChannel - IndexError: list index out of range #3711

Closed DiegoProtec closed 5 years ago

DiegoProtec commented 5 years ago

Rasa version: 1.0.6

Python version: 3.6.8

Operating system: Windows 10 Pro

Issue: Messages list in CollectingOutputChannel always empty. After update version Rasa, the service channels broken. What I do? Help me pls!!!

Error (including full traceback):

ga_connector.py", line 68, in receive
    message = responses[0]
**IndexError: list index out of range**
/opt/conda/lib/python3.6/site-packages/sanic/app.py:948: RuntimeWarning: coroutine 'CustomAction._extract_intent' was never awaited
  "An error occurred while handling an error", status=500

Command or request that led to error:

class CustomAction(InputChannel):

    @classmethod
    def name(cls):
        return 'google_home'

    @staticmethod
    async def _extract_sender(req):
        return req.json['user']['userId']

    @staticmethod
    async def _extract_intent(req):
        return req.json['inputs'][0]['intent']

    @staticmethod
    def _extract_message(req):
        return req.json['inputs'][0]['rawInputs'][0]['query']

    def blueprint(self, on_new_message):
        google_webhook = Blueprint('google_webhook', __name__)

        @google_webhook.route("/", methods=['GET'])
        def health(request: Request):
            return response.json({"status": "ok"})

        @google_webhook.route("/webhook", methods=['POST'])
        async def receive(request: Request):
            sender_id = await self._extract_sender(request)
            text = self._extract_message(request)
            intent = self._extract_intent(request)

            try:
                if intent == 'actions.intent.MAIN':
                    message = "<speak>Olá! <break time=\"1\"/> Seja bem vindo ao Zello, para começarmos diga oi!"
                else:
                    collector = CollectingOutputChannel()
                    await on_new_message(
                        UserMessage(
                            text, collector, sender_id, input_channel=self.name()
                        )
                    )
                    message = [m["text"] for m in collector.messages][0]
            except LookupError as e:
                logger.error("Message handling no reply for user message '{}'.".format(text))
                logger.error(e)
                message = "RASA_NO_REPLY"

            data = json.dumps({
                "conversationToken": "{\"state\":null,\"data\":{}}",
                "expectUserResponse": 'true',
                "expectedInputs": [
                    {
                        "inputPrompt": {
                            "initialPrompts": [
                                {
                                    "ssml": message
                                }
                            ]
                        },
                        "possibleIntents": [
                            {
                                "intent": "actions.intent.TEXT"
                            }
                        ]
                    }
                ]
            })

            return response.json(data)

        return google_webhook
akelad commented 5 years ago

Thanks for raising this issue, @ricwo will get back to you about it soon.

ricwo commented 5 years ago

@DiegoProtec your _extract_intent() doesn't have to be a coroutine. you can either await it, or just change it to

@staticmethod
def _extract_intent(req):
    return req.json['inputs'][0]['intent']

I hope that helps!