Utter_button_message exceptions using rocketchat channel

I am using a custom action to generate a dynamic array of buttons and while this works as expected using other output channels, I receive the following exception when this exchange is made using a rocketchat endpoint:

[2019-07-10 10:18:58 +0000] [1] [ERROR] Exception occurred while handling uri: 'http://rasa:5005/webhooks/rocketchat/webhook'
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/sanic/app.py", line 917, in handle_request
    response = await response
  File "/usr/local/lib/python3.6/site-packages/rasa/core/channels/rocketchat.py", line 151, in webhook
    await self.send_message(text, sender_name, recipient_id, on_new_message)
  File "/usr/local/lib/python3.6/site-packages/rasa/core/channels/rocketchat.py", line 128, in send_message
    await on_new_message(user_msg)
  File "/usr/local/lib/python3.6/site-packages/rasa/core/channels/channel.py", line 65, in handler
    await app.agent.handle_message(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/rasa/core/agent.py", line 448, in handle_message
    return await processor.handle_message(message)
  File "/usr/local/lib/python3.6/site-packages/rasa/core/processor.py", line 84, in handle_message
    await self._predict_and_execute_next_action(message, tracker)
  File "/usr/local/lib/python3.6/site-packages/rasa/core/processor.py", line 350, in _predict_and_execute_next_action
    action, tracker, message.output_channel, self.nlg, policy, confidence
  File "/usr/local/lib/python3.6/site-packages/rasa/core/processor.py", line 460, in _run_action
    await self._send_bot_messages(events, tracker, output_channel)
  File "/usr/local/lib/python3.6/site-packages/rasa/core/processor.py", line 382, in _send_bot_messages
    await output_channel.send_response(tracker.sender_id, e.message())
  File "/usr/local/lib/python3.6/site-packages/rasa/core/channels/channel.py", line 169, in send_response
    recipient_id, message.pop("text"), message.pop("buttons"), **message
  File "/usr/local/lib/python3.6/site-packages/rasa/core/channels/rocketchat.py", line 67, in send_text_with_buttons
    button_attachment = [{"actions": self._convert_to_rocket_buttons(buttons)}]
  File "/usr/local/lib/python3.6/site-packages/rasa/core/channels/rocketchat.py", line 30, in _convert_to_rocket_buttons
    for b in buttons
  File "/usr/local/lib/python3.6/site-packages/rasa/core/channels/rocketchat.py", line 30, in <listcomp>
    for b in buttons
KeyError: 'payload'

and the relevant code snippet:

        srv = client.service_check()
        buttons = []
        for host in srv:
            buttons.append({"title": host["name"], "payload": host["name"]})
            "On which hosts should I {} the {} service?".format(state, service), buttons

        return []

I can’t find any outstanding issues related to this. Any help would be appreciated.

Thanks in advance

Hm this is strange, I cant see any immediate reason why your code wouldn’t work. What versions of rasa and rasa-sdk are you on?

Can you put in a debugging statement and tell me the value of buttons at this point: rasa/rocketchat.py at master · RasaHQ/rasa · GitHub

I’m using the latest docker image for both.

Buttons would look something like this: [{"title": "server1", "payload": "server1"}, {"title": "server2", "payload": "server2"}]

Thinking the error could have been caused by the lookup used in generating the buttons array I tested with static values and got the same result; however, using a button template renders as expected.

I’ve tested this on rocketchat version 1.2.1 and 1.0.3

Regretfully, the action file contained some code left over from testing and was not reflecting my local changes.

The bad code caused the buttons array to contain an item without a payload.

Thanks for your time @erohmensing and for being my rubber duck. :duck:

1 Like

Ah no worries. I’m glad you got it figured out in any case!

The buttons dosen’t work for me , slashcommand Help