Skip to content

Instantly share code, notes, and snippets.

@wiljdaws
Created August 14, 2023 19:26
Show Gist options
  • Save wiljdaws/76e1053a8ee46901e7f473640c4c556a to your computer and use it in GitHub Desktop.
Save wiljdaws/76e1053a8ee46901e7f473640c4c556a to your computer and use it in GitHub Desktop.
Send dictionary to slackbot
def send_to_slackbot(dictionary_object: dict, webhook_string: str):
'''
This function sends the dictionary object to the slackbot
Args:
- dictionary_object (dict): dictionary object
- webhook_string (str): webhook string
Raises:
ValueError: if response status code is not 200
Return type: None
'''
data=json.dumps(dictionary_object)
response = requests.post(
webhook_string, data,
headers={'Content-Type': 'application/json'}
)
if response.status_code != 200:
raise ValueError(
'Request to slack returned an error %s, the response is:\n%s'
% (response.status_code, response.text)
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment