Skip to content
This repository was archived by the owner on Jun 29, 2021. It is now read-only.

Commit 6c3ae7c

Browse files
author
Devin McGloin
committed
Fixed webhook exists logic
1 parent 8cdef54 commit 6c3ae7c

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

smooch/webhooks.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import logging
2+
23
from .endpoint import ask
34
from .exceptions import InvalidWebhookTrigger
45

5-
possible_triggers = ["message", "message:appUser", "message:appMaker", "postback"]
6+
possible_triggers = [
7+
"message", "message:appUser", "message:appMaker", "postback"
8+
]
69

710

811
def valid_triggers(triggers):
@@ -23,7 +26,8 @@ def create_webhook(target, triggers=None):
2326
if triggers:
2427
if not valid_triggers(triggers):
2528
raise InvalidWebhookTrigger(triggers)
26-
return ask('webhooks', {"target": target, "triggers": triggers}, 'post')
29+
return ask('webhooks', {"target": target,
30+
"triggers": triggers}, 'post')
2731
else:
2832
return ask('webhooks', {"target": target}, 'post')
2933

@@ -33,9 +37,12 @@ def update_webhook(webhook_id, target, triggers=None):
3337
if triggers:
3438
if not valid_triggers(triggers):
3539
raise InvalidWebhookTrigger(triggers)
36-
return ask('webhooks/{0}'.format(webhook_id), {"target": target, "triggers": triggers}, 'put')
40+
return ask('webhooks/{0}'.format(webhook_id),
41+
{"target": target,
42+
"triggers": triggers}, 'put')
3743
else:
38-
return ask('webhooks/{0}'.format(webhook_id), {"target": target}, 'put')
44+
return ask('webhooks/{0}'.format(webhook_id), {"target": target},
45+
'put')
3946

4047

4148
def delete_webhook(webhook_id):
@@ -73,15 +80,15 @@ def ensure_webhook_exist(target, trigger):
7380
break
7481

7582
logging.debug("message_webhook_id: %s", message_webhook_id)
76-
logging.debug("message_webhook_needs_updating: %s", message_webhook_needs_updating)
83+
logging.debug("message_webhook_needs_updating: %s",
84+
message_webhook_needs_updating)
7785
if not message_webhook_id:
7886
logging.debug("Creating webhook")
7987
r = create_webhook(target, [trigger])
8088
data = r.json()
8189
message_webhook_id = data["webhook"]["_id"]
8290
webhook_secret = data["webhook"]["secret"]
83-
84-
if message_webhook_needs_updating:
91+
elif message_webhook_needs_updating:
8592
logging.debug("Updating webhook")
8693
update_webhook(message_webhook_id, target, [trigger])
8794

0 commit comments

Comments
 (0)