Python - Send a message to MS channel
Steps
-
End result. A message on channel.
-
Join or create a team https://mail.google.com/chat/u/0/ and create a new space.
-
Create a team from scratch.
-
Team for either private or public.
-
Team name. eg) Demo
-
More options on channel. eg) Demo >> General >> More options
-
Connectors to add a new incoming webhook.
-
Add Incoming Webhook.
-
Connectors to configure the incoming webhook.
-
Configure Incoming Webhook.
-
Name of the webhook.
-
Copy the webhook url.
-
Create a new python file and paste below code. Update url to the webhook. eg) demo.py
# https://developers.google.com/chat/quickstart/incoming-bot-python from json import dumps from httplib2 import Http def main(): """Hangouts Chat incoming webhook quickstart.""" url = '<INCOMING-WEBHOOK-URL>' bot_message = { 'text' : 'Hello from a Python script!'} message_headers = {'Content-Type': 'application/json; charset=UTF-8'} http_obj = Http() response = http_obj.request( uri=url, method='POST', headers=message_headers, body=dumps(bot_message), ) print(response) if __name__ == '__main__': main()
-
Run demo.py. Ctrl + F5 or Right click >> "Run Python File in Terminal" within VS Code.