Sending Messages to Hangout Chat Room from a Server using Webhook URL

Gimhan Dissanayake
3 min readJun 10, 2021

--

This article describes how to send a Text message from a Ubuntu Server to a Google Hangout Chat (Google’s paid team chat service, provided as part of Google Workspace) using a Webhook URL by executing a Python Script over the command line.

Let’s start with Prerequisites

  1. Gmail Account from a Google workspace(Previously G Suite Team).

Example: user@examplepvtltd.com

2. Ubuntu Server. (You may follow this on any Linux based server using appropriate package managers)

Step 1 — Create a Google Hangout Group and Webhook URL

  1. Open Google Hangout Chat Application
  2. Create a Chat Room to get the Alert
Adding Chat Room
Name the Chat Group and Create

2. Create Webhook URL

Select Created Chat Room and Create Webhook
Name the Webhook and Copy Webhook URL

Step 2 — Set up the Ubuntu Server to Run a Python Script

Now we are done with the Google Hangout Chat App side configuration. Let’s Install the Python, pip(Package manager for python), and other required packages.

# Update the packages list and install the prerequisites:

sudo apt install software-properties-common

sudo add-apt-repository ppa:deadsnakes/ppa

sudo apt update

# Install Python

sudo apt install python3.8

python — version

# Install pip3

sudo apt update

sudo apt install python3-pip

pip3 — version

# Install Required Modules to run the python script

pip install httplib2

Step 3 — Create the Python Script

Now our server is ready to execute the script. Let’s add the Webhook URL and Text Message we need to send to our Google Hangout Chat Room.

Get the Python script from here

Edit the script and change URL and message:

vim send_message.py

url = 'Copy and Pase Webhook URL here'
message = {
'text' : 'This is a test message from your server'}

Step 4 — Execute the Python Script

# Make the file executable

sudo chmod +x send_message.py

# Execute the script

python3 send_message.py

👏👏👏 Check your Google Hangout chat Room:

END

Sign up to discover human stories that deepen your understanding of the world.

--

--

No responses yet

Write a response