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

botframework channel does not work with Microsoft Bot Emulator without credentials #9318

Closed peter-wimsey closed 1 year ago

peter-wimsey commented 3 years ago

Rasa version : 2.8.0

Python version : 3.8.10

Operating system : GNU/Linux

Bot Framework Emulator version : 4.14.0

Issue :

Running the [Microsoft Bot Emulator| https://github.com/microsoft/BotFramework-Emulator] locally does not require credentials. Sending messages from the emulator to rasa works but sending messages from rasa back to the emulator fails with 400 Bad Request.

I believe this is because the Content-Type header is not properly set when authorization with microsoftonline.com fails. Here is a workaround:

#!/usr/bin/env python

from rasa.__main__ import main

from rasa.core.channels.botframework import BotFramework

1.  Skip Microsoft login - authorization not needed but Content-Type header is
     async def _get_headers(self):
     return {"Content-Type": "application/json"}

BotFramework._get_headers = _get_headers

if __name__ == "__main__":
 main()

Error (including full traceback) :

Credentials are left empty:

# credentials.yml
 botframework:
 app_id:
 app_password:

Before sending the response to the emulator Rasa tries and fails to log into microsoftonline.com

2021-08-10 12:31:28 DEBUG urllib3.connectionpool - https://login.microsoftonline.com:443 "POST /botframework.com/oauth2/v2.0/token HTTP/1.1" 401 538 2021-08-10 12:31:28 ERROR rasa.core.channels.botframework - Could not get BotFramework token

Rasa send the message anyway:

POST /v3/conversations/c427c3b0-f9d6-11eb-a1af-977ddf2bfc11%7Clivechat/activities HTTP/1.1 Host: localhost:46725 User-Agent: python-requests/2.25.1 Accept-Encoding: gzip, deflate Accept: / Connection: keep-alive Content-Length: 294

{ "type": "message", "recipient":

{ "id": "dc6940cb-7e04-4757-bbbe-8ae1d7a2248b" }

, "from":

{ "id": "c4270060-f9d6-11eb-8ad1-fd7e20e5c723", "name": "Bot", "role": "bot" }

, "channelData": { "notification":

{ "alert": "true" }

}, "text": "Hi, I am John! How can I help you with your enquiry?" }

The emulator replies with 400:

HTTP/1.1 400 Bad Request Server: Emulator Content-Type: application/json Content-Length: 83 Date: Tue, 10 Aug 2021 12:31:28 GMT Connection: keep-alive

{ "error":

{ "code": "ServiceError", "message": "Cannot set property 'id' of undefined" }

}

Command or request that led to error :

Download the relevant file from [[https://github.com/Microsoft/BotFramework-Emulator/releases/|| https://github.com/Microsoft/BotFramework-Emulator/releases/%7C] https://github.com/Microsoft/BotFramework-Emulator/releases/]

Run the emulator, for example chmod +x ~/Downloads/*.AppImage && ~Downloads/BotFramework-Emulator-4.14.0-linux-x86_64.AppImage

Run rasa

In the emulator click "Open Bot" and enter the Bot URL [http://localhost:5005/webhooks/botframework/webhook](http://localhost:5005/webhooks/botframework/webhook). Leave all other fields blank.

Send a message - the message will be send successfully but the response will fail

sara-tagger commented 3 years ago

Thanks for the issue, @jupyterjazz will get back to you about it soon!

You may find help in the docs and the forum, too 🤗
stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

m-vdb commented 1 year ago

Closing as stale