Netflix / hubcommander

A Slack bot for GitHub organization management -- and other things too

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

KeyError: 'text' in process_message

jrm16020 opened this issue · comments

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'

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

@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.

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 :-)

@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.

That's perfect! Thank you @mikegrima.