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.59k stars 4.6k forks source link

botframework: Exception when trying to handle message. 'type' #3159

Closed selphe closed 5 years ago

selphe commented 5 years ago
**Rasa version**: 0.14.0a9 **Python version**: 3.6 **Operating system** (windows, osx, ...): CoreOS **Issue**: 1. Rasa core running inside docker with botframework channel. Server accessible from outside via nginx proxy. 2. At Microsoft Azure portal side, I've configured endpoint `https://servername/webhooks/botframework/webhook/` (with slash at end regarding to this issue https://github.com/RasaHQ/rasa_nlu/issues/2760) 3. I'm testing from Microsoft Azure webchat (please refer to this issue, to understand how tesing with azure webchat works: https://github.com/RasaHQ/rasa_nlu/issues/2365) 4. From webchat (azure side), I see, what the message is out 5. From rasa server, I see error: >rasa.core.channels.botframework - Exception when trying to handle message. 'type' Screenshot: https://i.imgur.com/v7NzXeB.png **Content of configuration file (docker-compose.yml)**: ```yml version: '3.0' services: rasa_core: image: rasa/rasa_core:stable ports: - 5005:5005 volumes: - ./models/rasa_core:/app/models - ./config:/app/config command: - start - --core - models - -c - botframework - --endpoints - config/endpoints.yml - -u - current/ - --credentials - config/credentials.yml - --enable_api networks: - rasa rasa_nlu: image: rasa/rasa_nlu:stable-full volumes: - ./models/rasa_nlu:/app/models - ./config:/app/config command: - start - --path - models - -c - config/nlu_config.yml networks: - rasa mongo: image: mongo environment: MONGO_INITDB_ROOT_USERNAME: MONGO_INITDB_ROOT_PASSWORD: networks: - rasa volumes: - ./mongodb:/data/db mongo-express: depends_on: - mongo image: mongo-express ports: - 8081:8081 environment: ME_CONFIG_MONGODB_ADMINUSERNAME: ME_CONFIG_MONGODB_ADMINPASSWORD: networks: - rasa networks: rasa: ipam: driver: default config: - subnet: ``` **Content of domain file (endpoint.yml)** (if used & relevant): ```yaml nlu: url: http://rasa_nlu:5000 tracker_store: store_type: mongod url: mongodb://mongo:27017 username: password: ``` **Content of domain file (endpoint.yml)** (if used & relevant): ```yaml botframework: app_id: "" app_password: "" ```
akelad commented 5 years ago

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

paulaWesselmann commented 5 years ago

Hey @selphe What is your input message to the bot? Also what do you mean by this: From webchat (azure side), I see, what the message is out?

selphe commented 5 years ago

Hello @paulaWesselmann My input message to the bot is text: 'hi', 'hello', 'sad' etc, anyhing that triggers 'utters' from default config.

Azure web chat is my input channel, when message from web chat can't reach endpoint (e.g. rasa offline) it show me error in dialog window, something like 'message can't be delivered' or 'bad gateway' etc.

In my case, here is no error message, this means, i think, rasa's botframework connector successfuly authenticates at azure botframework portal, but bot just doesn't reply anything. Error at rasa side looks like rasa can't handle received message 'type'. Maybe something changed in microsoft api?

selphe commented 5 years ago

Hello @paulaWesselmann, any news? I did some research with core/channels/botframework.py Here is my tests:

  1. GET to http://server_name/webhooks/botframework Answer from rasa:
    {
    "status": "ok"
    }
  2. POST to http://server_name/webhooks/botframework/webhook Answer from rasa:
    success

Request from MS botframework, which I receive at nginx (rasa behind the proxy), at first looks correct:

{
    "text": "Hi",
    "textFormat": "plain",
    "type": "message",
    "timestamp": "2019-04-01T08:23:13.979Z",
    "localTimestamp": "2019-04-01T15:23:13.979+07:00",
    "id": "1554106993898",
    "channelId": "msteams",
    "serviceUrl": "https://smba.trafficmanager.net/emea/",
    "from": {
        "id": "29:1YaNK8IFAhKpkRohwsg1SXlbAqQUbEizQ7Ly20X56T7zJ-znPQK4F_M7JYHM24LnRh91GjaiL3MFiocLtUHnpHw",
        "name": "<full name>",
        "aadObjectId": "3a18afcc-8433-488b-92aa-a0fa2110b436"
    },
    "conversation": {
        "conversationType": "personal",
        "id": "a:1DvsYGaPdrB0UcT_PT8c3fVASc5kcSqvxvt-488HZGTEdIj3xvs7VsEv8ZV0kAtDlqZIzVX2rYIWbLjguCHmalx0enkoju7hoWg_wQtYuO0zo4n1JIf0NOyetaJd7N6Wq"
    },
    "recipient": {
        "id": "28:5d295fc8-9a6a-4b88-8697-2c87ff2be07c",
        "name": "<channel name from Azure portal>"
    },
    "entities": [{
            "locale": "en-US",
            "country": "US",
            "platform": "Web",
            "type": "clientInfo"
        }
    ],
    "channelData": {
        "tenant": {
            "id": "e1e69249-edd0-431d-93b5-a25d7d98e5d2"
        }
    },
    "locale": "en-US"
}

But rasa doesn't answer: https://imgur.com/428OJmG What could be wrong?

paulaWesselmann commented 5 years ago

@selphe awesome this output is very helpful! The BotFramework() expects following inputs:

 def __init__(self,
                 app_id: Text,
                 app_password: Text,
                 conversation: Dict[Text, Any],
                 bot_id: Text,
                 service_url: Text) -> None:

which are called like this:

BotFramework(self.app_id, self.app_password,
                                               postdata["conversation"],
                                               postdata["recipient"],
                                               postdata["serviceUrl"])

I think the type error is because it expects Text but gets a Dict for the recipient. This is fixed by changing the call in 'botframework.py` to

postdata["recipient"]["id"]

I am not sure if this is something that has to be fixed in the core code for everyone. I'll investigate and get back to you. Let me know if you have further questions.

paulaWesselmann commented 5 years ago

I'll make a PR for this.

paulaWesselmann commented 5 years ago

@selphe can you try out if this change fixes your issue and report back here?

paulaWesselmann commented 5 years ago

Hey @tupac56, Can you have a look at this issue? I'm not sure if this is usage dependent, or if the recipient always is a dictionary containing name and id. (I couldn't find other reports of people running into this error) Do you know what is the case here, is this something that should be fixed in the code?

"recipient": {
        "id": "28:5d295fc8-9a6a-4b88-8697-2c87ff2be07c",
        "name": "<channel name from Azure portal>"
    }
1tupac commented 5 years ago

Hey @paulaWesselmann!

You're right, in the response returned by the bot, the recipient should be a dict, I misnames the argument bot_id. https://github.com/RasaHQ/rasa_nlu/blob/719b2663652d949925de9a2dea1da83bbe3ea453/rasa/core/channels/botframework.py#L35

I guess this line should be replaced by something like this:

bot: Dict[Text, Any]

if you choose to give the integrality of postdata["recipient"] as argument to BotFramework.

The BotFramework API reference specify that the response from the bot payload should be formatted like this:

{
    "...": "...",
    "from": {
        "id": "12345678",
        "name": "bot's name"
    }
}

where in our case

postdata["recipient"] = {
    "id": "12345678",
    "name": "bot's name"
}

Hope it works out!

paulaWesselmann commented 5 years ago

Thank you @tupac56! That information about the botframework API is what I was looking for.

selphe commented 5 years ago

Hey @paulaWesselmann I can confirm, what @tupac56 suggestion almost works for me, but I'm not a developer, so please note at my steps:

  1. I've setup clean env on local machine under Windows:

    • rasa-core 0.13.7 (not 0.14.0a9, as I've reported above, since I can't replace version inside container)
    • rasa-core-sdk 0.12.2
    • rasa-nlu 0.14.6
  2. Changed botframework.py

From this:

bot_id: Text, 

To this:

bot_id: Dict[Text, Any], 

Now, I can communicate with the bot via botframework channels (tested MS Teams and Azure webchat). How to get it working with docker?

paulaWesselmann commented 5 years ago

Cool, I'm glad it's fixed! @selphe Please look at the Docs for the docker question and ask your questions about it in the Forum.