Hey guys.
As you know at the moment Slack buttons don’t work when integrating the bot with Slack. I’ve done some reading on the issue and this seems to be the latest:
opened 07:32AM - 23 Apr 20 UTC
closed 09:56PM - 27 Jul 20 UTC
type:bug
area:rasa-oss
<!-- THIS INFORMATION IS MANDATORY - YOUR ISSUE WILL BE CLOSED IF IT IS MISSING.… If you don't know your Rasa version, use `rasa --version`.
Please format any code or console output with three ticks ``` above and below.
If you are asking a usage question (e.g. "How do I do xyz") please post your question on https://forum.rasa.com instead -->
**Rasa version**: 1.9.6
**Python version**: Python 3.7.6
**Operating system** (windows, osx, ...): windows
**Issue**: The Slack connector is not able to handle the button payload response from the slack.
**Error (including full traceback)**:
```
File "c:\users\jitesh\appdata\local\programs\python\python37\lib\site-packages\sanic\request.py", line 173, in load_json
self.parsed_json = loads(self.body)
ValueError: Expected object or value
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\users\jitesh\appdata\local\programs\python\python37\lib\site-packages\sanic\app.py", line 976, in handle_request
response = await response
File "c:\users\jitesh\appdata\local\programs\python\python37\lib\site-packages\rasa\core\channels\slack.py", line 356, in webhook
metadata = self.get_metadata(request)
File "c:\users\jitesh\appdata\local\programs\python\python37\lib\site-packages\rasa\core\channels\slack.py", line 329, in get_metadata
slack_event = request.json
File "c:\users\jitesh\appdata\local\programs\python\python37\lib\site-packages\sanic\request.py", line 167, in json
self.load_json()
File "c:\users\jitesh\appdata\local\programs\python\python37\lib\site-packages\sanic\request.py", line 177, in load_json
raise InvalidUsage("Failed when parsing body as json")
sanic.exceptions.InvalidUsage: Failed when parsing body as json
```
Below is the output of the error in slack:
![issue_1](https://user-images.githubusercontent.com/49223934/80071475-535b4100-8562-11ea-80c1-846ae1a06f3e.PNG)
when I tried to find where the issue lies, I got to know that the `request` object that was received from slack was in the `req.form` and the issue occurs when getting the `metadata` value on the below line:
https://github.com/RasaHQ/rasa/blob/002b892f573541b42a05b783df64424f959ff9e8/rasa/core/channels/slack.py#L356
since the `get_metadata` function uses `req.json` to set the values for `metadata` and `req.json` isn't there so it throws the above error.
So as a workaround, I tried to update the connector and it worked for me:
```
@slack_webhook.route("/webhook", methods=["GET", "POST"])
async def webhook(request: Request) -> HTTPResponse:
if request.form:
output = request.form
payload = json.loads(output["payload"][0])
if self._is_interactive_message(payload):
sender_id = payload["user"]["id"]
text = self._get_interactive_response(payload["actions"][0])
if text is not None:
# metadata = self.get_metadata(request)
out_channel = payload["channel"]["id"]
users = payload["user"]["id"]
metadata = {'out_channel': out_channel, 'users': users}
return await self.process_message(
request, on_new_message, text, sender_id, metadata
)
elif payload["actions"][0]["type"] == "button":
# link buttons don't have "value", don't send their clicks to bot
return response.text("User clicked link button")
return response.text(
"The input message could not be processed.", status=500
)
```
I am getting the values for `metadata` from the `payload`.
Below is the output from the slack after updating the connector:
![issue-2](https://user-images.githubusercontent.com/49223934/80071558-7554c380-8562-11ea-9386-0a5952dcee4b.PNG)
I don't know whether it's a reliable workaround solution😅 would like to know your thoughts on this 😄
It’s a known issue with the get_metadata
function and the request object.
I can apply the workaround on my local machine, but our Rasa X implementation still suffers from the problem. Any update on when the fix will be released?
akelad
(Akela Drissner)
June 15, 2020, 11:08am
2
1 Like