Forked from devStepsize/slack_webhook_post.py
Last active
January 15, 2020 17:33
POST a JSON payload to a Team's channel Incoming Webhook using Python requests
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
''' | |
This is an example of how to send data to Team's webhooks in Python with the | |
requests module. | |
Documentation for Team's Incoming Webhooks: | |
https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/what-are-webhooks-and-connectors | |
Card playground: | |
https://messagecardplayground.azurewebsites.net/ | |
''' | |
import json | |
import requests | |
import os | |
# Set the webhook_url to the one provided by creating a webhook connector. | |
webhook_url = 'https://outlook.office.com/webhook/*************************/IncomingWebhook/*************************' | |
Watchdog_data = os.environ['sitecheckdata'] #path to card's json file. use "set sitecheckdata '%userprofile%/desktop/path/to/file'" | |
response = requests.post( | |
webhook_url, data=json.dumps(Watchdog_data), | |
headers={'Content-Type': 'application/json'} | |
) | |
if response.status_code != 200: | |
raise ValueError( | |
'Request to Teams 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