-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdrip_message.py
executable file
·84 lines (72 loc) · 1.96 KB
/
drip_message.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/usr/bin/env python
"""
Testing the webhook, or manually send a message as DripBot
"""
import argparse
from matterhook import Webhook
# -------------------------
# Argument setup
# -------------------------
parser = argparse.ArgumentParser(
prog='python3 dripmessage.py',
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description='Send a message to Mattermost as DripBot.')
parser.add_argument(
'-m',
'--message',
type=str,
help='Message to be sent to the channel',
required=True,
)
parser.add_argument(
'-c',
'--channel',
type=str,
default="CHANNEL_NAME",
help='Mattermost channel to send the message to',
)
parser.add_argument(
'-u',
'--username',
type=str,
default="DripBot",
help='User name whence the message came',
)
parser.add_argument(
'-i',
'--iconurl',
type=str,
default="location/of/CoffeePot.png",
help='URL for the icon to display as the user avatar',
)
parser.add_argument(
'-t',
'--test',
action="store_true",
help='Test mode: send the message to the "TEST_CHANNEL_NAME"\nchannel as user "DripBot Test"',
)
args = parser.parse_args()
if args.test is True:
args.channel = "TEST_CHANNEL_NAME"
args.username = "DripBot Test"
# -------------------------
# Webhook setup
# -------------------------
# mandatory parameters are url and your webhook API key
dripbot = Webhook('https://mattermost.example.com', 'API_KEY_HERE')
dripbot.username = args.username
dripbot.icon_url = args.iconurl
# -------------------------
# Test log prints
# -------------------------
# print(f"Message: {args.message}")
# print(f"Channel: {args.channel}")
# print(f"User name: {args.username}")
# print(f"Icon Url: {args.iconurl}")
# print(f"Test: {args.test}")
# -------------------------
# Send the message
# -------------------------
# send a message to the API_KEY's channel
# "scratch-area" for testing
dripbot.send(args.message, channel=args.channel)