|
1 | 1 | #!/usr/bin/env python |
2 | | - |
3 | | -import sys, os |
4 | | -sys.path.append(os.path.join(os.path.dirname(__file__), '..')) |
5 | | - |
| 2 | +import sys |
| 3 | +import argparse |
6 | 4 | import messagebird |
7 | 5 | from messagebird.conversation_message import MESSAGE_TYPE_TEXT |
8 | 6 |
|
9 | | -# ACCESS_KEY = '' |
10 | | -# CONVERSATION_ID = '' |
11 | | -# CHANNEL_ID = '' |
12 | | -# TEXT_MESSAGE = '' |
13 | | - |
14 | | -try: |
15 | | - ACCESS_KEY |
16 | | -except NameError: |
17 | | - print('You need to set an ACCESS_KEY constant in this file') |
18 | | - sys.exit(1) |
19 | | - |
20 | | -try: |
21 | | - CONVERSATION_ID |
22 | | -except NameError: |
23 | | - print('You need to set a CONVERSATION_ID constant in this file') |
24 | | - sys.exit(1) |
25 | | - |
26 | | -try: |
27 | | - CHANNEL_ID |
28 | | -except NameError: |
29 | | - print('You need to set a CHANNEL_ID constant in this file') |
30 | | - sys.exit(1) |
31 | | - |
32 | | -try: |
33 | | - TEXT_MESSAGE |
34 | | -except NameError: |
35 | | - print('You need to set a TEXT_MESSAGE constant in this file') |
36 | | - sys.exit(1) |
| 7 | +parser = argparse.ArgumentParser() |
| 8 | +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) |
| 10 | +parser.add_argument('--channelId', help='channel ID that you want to create a message for', type=str, required=True) |
| 11 | +parser.add_argument('--message', help='message that you want to send', type=str, required=True) |
| 12 | +args = vars(parser.parse_args()) |
37 | 13 |
|
38 | 14 | try: |
39 | | - client = messagebird.Client(ACCESS_KEY) |
| 15 | + client = messagebird.Client(args['accessKey']) |
40 | 16 |
|
41 | | - msg = client.conversation_create_message(CONVERSATION_ID, { 'channelId': CHANNEL_ID, 'type': MESSAGE_TYPE_TEXT, 'content': { 'text': TEXT_MESSAGE } }) |
| 17 | + msg = client.conversation_create_message(args['conversationId'], { 'channelId': args['channelId'], 'type': MESSAGE_TYPE_TEXT, 'content': { 'text': args['message'] } }) |
42 | 18 |
|
43 | 19 | # Print the object information. |
44 | 20 | print('\nThe following information was returned as a Conversation List object:\n') |
|
0 commit comments