Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save vvalorous/a84c0bf7f9bf732db5a84cda8fc110f6 to your computer and use it in GitHub Desktop.
Save vvalorous/a84c0bf7f9bf732db5a84cda8fc110f6 to your computer and use it in GitHub Desktop.
Use a Webhook to send a message to a Microsoft Teams channel using Connectors/Incoming Webhook
#!/usr/bin/python3
# https://gist.github.com/daniel-woods
# Use a Webhook to send a message to a Microsoft Teams channel using Connectors/Incoming Webhook
import json
from urllib2 import urlopen, HTTPError, Request
def post_message(url, data):
req = Request(url, data)
f = urlopen(req)
f.close()
def lambda_handler(event, context):
# Webhook URL, get this from Connectors/Incoming Webhook.
url = "https://outlook.office.com/webhook/xxxx/IncomingWebhook/xxxx/xxxx"
msg = {
"text": event['Records'][0]['Sns']['Message']
}
# Send the Message
post_message(url, json.dumps(msg))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment