|
1 | 1 | #!/usr/bin/env python |
2 | | -import sys |
3 | 2 | import argparse |
4 | 3 | import messagebird |
5 | 4 | from messagebird.conversation_message import MESSAGE_TYPE_TEXT |
6 | 5 |
|
7 | 6 | parser = argparse.ArgumentParser() |
8 | 7 | parser.add_argument('--accessKey', help='access key for MessageBird API', type=str, required=True) |
9 | | -parser.add_argument('--conversationId', help='conversation ID that you want to create a message for', type=str, required=True) |
| 8 | +parser.add_argument('--conversationId', help='conversation ID that you want to create a message for', type=str, |
| 9 | + required=True) |
10 | 10 | parser.add_argument('--channelId', help='channel ID that you want to create a message for', type=str, required=True) |
11 | 11 | parser.add_argument('--message', help='message that you want to send', type=str, required=True) |
12 | 12 | args = vars(parser.parse_args()) |
13 | 13 |
|
14 | 14 | try: |
15 | | - client = messagebird.Client(args['accessKey']) |
| 15 | + client = messagebird.Client(args['accessKey']) |
16 | 16 |
|
17 | | - msg = client.conversation_create_message(args['conversationId'], { 'channelId': args['channelId'], 'type': MESSAGE_TYPE_TEXT, 'content': { 'text': args['message'] } }) |
| 17 | + msg = client.conversation_create_message(args['conversationId'], |
| 18 | + {'channelId': args['channelId'], 'type': MESSAGE_TYPE_TEXT, |
| 19 | + 'content': {'text': args['message']}}) |
18 | 20 |
|
19 | | - # Print the object information. |
20 | | - print('\nThe following information was returned as a Conversation List object:\n') |
21 | | - print(' message id : %s' % msg.id) |
22 | | - print(' channel id : %s' % msg.channelId) |
23 | | - print(' direction : %s' % msg.direction) |
24 | | - print(' content : %s' % msg.content) |
25 | | - print(' content : %s' % msg.content) |
26 | | - print(' status : %s' % msg.status) |
27 | | - print(' type : %s' % msg.type) |
28 | | - print(' created date : %s' % msg.createdDatetime) |
29 | | - print(' updated date : %s' % msg.updatedDatetime) |
| 21 | + # Print the object information. |
| 22 | + print('\nThe following information was returned as a Conversation List object:\n') |
| 23 | + print(' message id : %s' % msg.id) |
| 24 | + print(' channel id : %s' % msg.channelId) |
| 25 | + print(' direction : %s' % msg.direction) |
| 26 | + print(' content : %s' % msg.content) |
| 27 | + print(' content : %s' % msg.content) |
| 28 | + print(' status : %s' % msg.status) |
| 29 | + print(' type : %s' % msg.type) |
| 30 | + print(' created date : %s' % msg.createdDatetime) |
| 31 | + print(' updated date : %s' % msg.updatedDatetime) |
30 | 32 |
|
31 | 33 | except messagebird.client.ErrorException as e: |
32 | | - print('\nAn error occured while requesting a Message object:\n') |
| 34 | + print('\nAn error occured while requesting a Message object:\n') |
33 | 35 |
|
34 | | - for error in e.errors: |
35 | | - print(' code : %d' % error.code) |
36 | | - print(' description : %s' % error.description) |
37 | | - print(' parameter : %s\n' % error.parameter) |
| 36 | + for error in e.errors: |
| 37 | + print(' code : %d' % error.code) |
| 38 | + print(' description : %s' % error.description) |
| 39 | + print(' parameter : %s\n' % error.parameter) |
0 commit comments