Skip to content

Commit d7a857f

Browse files
committed
Example to test webhook update
1 parent 2158a19 commit d7a857f

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python
2+
import messagebird
3+
import argparse
4+
from messagebird.conversation_webhook import \
5+
CONVERSATION_WEBHOOK_EVENT_CONVERSATION_CREATED, \
6+
CONVERSATION_WEBHOOK_EVENT_CONVERSATION_UPDATED
7+
8+
9+
parser = argparse.ArgumentParser()
10+
parser.add_argument('--accessKey', help='access key for MessageBird API', type=str, required=True)
11+
parser.add_argument('--webhookId', help='webhook that you want to update', type=str, required=True)
12+
parser.add_argument('--url', help='url for the webhook', type=str)
13+
parser.add_argument('--status', help='Status of the webhook. Can be set to "enabled" or "disabled"', type=str, default='enabled')
14+
args = vars(parser.parse_args())
15+
16+
try:
17+
client = messagebird.Client(args['accessKey'])
18+
19+
update_request = {
20+
'events': [CONVERSATION_WEBHOOK_EVENT_CONVERSATION_CREATED, CONVERSATION_WEBHOOK_EVENT_CONVERSATION_UPDATED],
21+
'url': args['url'],
22+
'status': args['status']
23+
}
24+
webhook = client.conversation_update_webhook(args['webhookId'], update_request)
25+
26+
# Print the object information.
27+
print('The following information was returned as a Webhook object:')
28+
print(webhook)
29+
30+
except messagebird.client.ErrorException as e:
31+
print('An error occured while requesting a Webhook object:')
32+
33+
for error in e.errors:
34+
print(' code : %d' % error.code)
35+
print(' description : %s' % error.description)
36+
print(' parameter : %s\n' % error.parameter)

0 commit comments

Comments
 (0)