Skip to content

Commit

Permalink
Fixed crashing caused by missing text key in slack events like messag…
Browse files Browse the repository at this point in the history
…e_changed
  • Loading branch information
GregHilston committed Mar 22, 2018
1 parent fc1c484 commit 690e4b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion example_component.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def user_typing_callback(request):

@simple_slack_bot.register("message")
def pong_callback(request):
if request.message.lower() == "ping":
if request.message and request.message.lower() == "ping":
request.write("Pong")


Expand Down
14 changes: 8 additions & 6 deletions simple_slack_bot/slack_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,18 @@ def __init__(self, slacker, slack_event):
def type(self):
"""Gets the type of event from the underlying SlackEvent
:return: the type of event
:return: the type of event, if there is one
"""

return self._slack_event.event["type"]
if "type" in self._slack_event.event:
return self._slack_event.event["type"]

@property
def channel(self):
"""Gets the channel from the underlying SlackEvent
Note: This can be an empty String. For example, this will be an empty String for the 'Hello' event.
:return: the channel this SlackEvent originated from
:return: the channel this SlackEvent originated from, if there is one
"""

channel = ""
Expand All @@ -46,19 +47,20 @@ def channel(self):
@property
def message(self):
"""Gets the underlying message from the SlackEvent
Note: This can be an empty String. For example, this will be an empty String for the 'message_changed' event.
:return: the message this SlackEvent came with
:return: the message this SlackEvent came with, if there is one
"""

return self._slack_event.event["text"]
if "text" in self._slack_event.event:
return self._slack_event.event["text"]

def write(self, content, channel=None):
"""
Writes the content to the channel
:param content: The text you wish to send
:param channel: By default send to same channel request came from, if any
:param kwargs: any extra arguments you want to pass to chat.postMessage Slack API
"""

if channel is None and self.channel != "":
Expand Down

0 comments on commit 690e4b8

Please sign in to comment.