Created
May 10, 2020 02:25
-
-
Save wesleyit/47e6a1bc78391a52196de657e9646f2b to your computer and use it in GitHub Desktop.
This code will post a message to an Amazon Chime chat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import requests | |
import sys | |
bot_id = '' | |
token = '' | |
base_url = f'https://hooks.chime.aws/incomingwebhooks/{bot_id}?token={token}' | |
def post_message(msg): | |
response = None | |
try: | |
response = requests.post( | |
url=base_url, | |
json={"Content": msg}) | |
return json.loads(response.text) | |
except Exception: | |
return response.text | |
# Check for a message as runtime parameter | |
if len(sys.argv) != 2: | |
print('\n\tIncorrect usage!') | |
print('\n\tExample Usage:') | |
print('\tpython3 ' + sys.argv[0] + ' \"Hello world\"\n') | |
exit() | |
# Get the message to send as a parameter | |
message = sys.argv[1] | |
# Post the message | |
req_res = post_message(message) | |
print(json.dumps(req_res, indent=2)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment