Netflix / hubcommander

A Slack bot for GitHub organization management -- and other things too
Apache License 2.0
1.28k stars 156 forks source link

KeyError: 'text' in process_message #41

Closed jrm16020 closed 7 years ago

jrm16020 commented 7 years ago

I noticed this error in rtmbot.log while testing locally. The link is being posted by my bot in response to it taking action. When it parses the link that it sends, this error is produced.

2017-05-13 14:16:02,909 Problem in Plugin Class: HubCommander: process_message
{'type': 'message', 'subtype': 'message_changed', 'message': {'type': 'message', 'text': '<https://www.youtube.com/watch?v=dNB_RjpWnsI>', 'ts': '1494684962.122327', 'attachment
Traceback (most recent call last):
  File "/usr/lib/python3.5/site-packages/rtmbot/core.py", line 205, in do
    func(data)
  File "/usr/lib/python3.5/site-packages/hubcommander/hubcommander.py", line 53, in process_message
    command_prefix = data["text"].split(" ")[0].lower()
KeyError: 'text'
mikegrima commented 7 years ago

Hello @jrm16020 : Is this when responding to message change events?

jrm16020 commented 7 years ago

@mikegrima I've customized the Github plugin a bit to give the bot a personality. For example, the function list_pull_requests for !ListPRs sends these two messages when it's successfully listed pull requests:

# Done:
send_raw(data["channel"], text="Repository: *{}* \n\n```{}```".format(reponame, tabulate(rows, headers=headers, tablefmt='orgtbl')))
send_raw(data["channel"], "https://www.youtube.com/watch?v=dNB_RjpWnsI")

It's in processing the Youtube link that the error is thrown.

jrm16020 commented 7 years ago

Sorry for the false alarm, but I think you can disregard. I realized I tested with the wrong branch so I updated my Dockerfile, rebuilt the container and got updated code this time. Now I can't reproduce the error but my change definitely breaks things :-)

mikegrima commented 7 years ago

@jrm16020 : So I actually used to do something similar internally before OSSing it. It used to add Metalocalypse GIFs.

In #40 , I'm working on adding decorators to perform much of the heavy lifting for doing things like arg parsing, authentication, and other validations.

I have also been toying around with the idea of having a callback function being set where you can define custom behavior like that (perhaps in the config.py of the plugin). This would perform custom pre and post actions before and after the said command is executed. I think that would be the most appropriate place for it.

jrm16020 commented 7 years ago

That's perfect! Thank you @mikegrima.