Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Will does not respond to slack webhooks #359

Open
Ashex opened this issue Jun 4, 2018 · 3 comments
Open

Will does not respond to slack webhooks #359

Ashex opened this issue Jun 4, 2018 · 3 comments
Labels

Comments

@Ashex
Copy link
Collaborator

Ashex commented Jun 4, 2018

I'm sending a notification to a channel like so:

curl -H "Content-type: application/json" -d '{
            "text": "'$COMMAND'"
        }' ${SLACK_WEBHOOK}

But will not does respond to the notification:

screen shot 2018-06-04 at 10 31 38

@Ashex
Copy link
Collaborator Author

Ashex commented Jun 4, 2018

The issue comes down to will passing on the subtype bot_message. The follow patch will allow will to respond to mentions from a bot message but it has not been properly validated:

diff --git a/will/backends/io_adapters/slack.py b/will/backends/io_adapters/slack.py
index 1d6f612..ef6f5c7 100644
--- a/will/backends/io_adapters/slack.py
+++ b/will/backends/io_adapters/slack.py
@@ -73,6 +73,7 @@ class SlackBackend(IOBackend, SleepMixin, StorageMixin):
             return True
 
     def normalize_incoming_event(self, event):
+        logging.info(event)
 
         if (
             "type" in event and
@@ -80,7 +81,7 @@ class SlackBackend(IOBackend, SleepMixin, StorageMixin):
             ("subtype" not in event or event["subtype"] != "message_changed") and
             # Ignore thread summary events (for now.)
             # TODO: We should stack these into the history.
-            ("subtype" not in event or ("message" in event and "thread_ts" not in event["message"]))
+            ("subtype" not in event or ("message" in event and "thread_ts" not in event["message"]) or event["subtype"] == "bot_message")
         ):
             # print("slack: normalize_incoming_event - %s" % event)
             # Sample of group message
@@ -104,7 +105,17 @@ class SlackBackend(IOBackend, SleepMixin, StorageMixin):
             # u'type': u'message', u'bot_id': u'B5HL9ABFE'},
             # u'type': u'message', u'hidden': True, u'channel': u'D5HGP0YE7'}
 
-            sender = self.people[event["user"]]
+            if event.get("subtype") == "bot_message":
+                sender = Person(
+                id=event["bot_id"],
+                mention_handle="<@%s>" % event["bot_id"],
+                handle=event["username"],
+                source=event,
+                name=event["username"],
+            )
+            else:
+                sender = self.people[event["user"]]
+
             try:
                 channel = clean_for_pickling(self.channels[event["channel"]])
             except KeyError:
@@ -143,7 +154,7 @@ class SlackBackend(IOBackend, SleepMixin, StorageMixin):
             if interpolated_handle in event["text"] or real_handle in event["text"]:
                 will_is_mentioned = True
 
-            if event["user"] == self.me.id:
+            if event.get("user") == self.me.id:
                 will_said_it = True
 
             m = Message(

@skoczen
Copy link
Owner

skoczen commented Jun 6, 2018

Hey @Ashex , would love to add support for bot_message - if you're keen to pull together a PR of the above, I'd be really happy to pull it in.

Thanks for all your contributions!!

@Ashex
Copy link
Collaborator Author

Ashex commented Jun 14, 2018

I'll prep a PR once I'm back from holiday. The main issue with the patch is I'm basically making up the handle details since webhooks don't have one. I'm open to suggestions on how to improve that, otherwise I'll leave that hack in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants