I’ve written before about how you can use webhooks with Runscope to extend the functionality of Runscope. In case you missed that post, Runscope has a number of built-in integrations, but some users want custom notifications with apps that we may not currently support. Webhook notifications are POST requests that are made at the completion of a test, and include a payload with details about the test run. If you can listen for these notifications, you can write your own code to deliver Runscope notifications anywhere that has an API you can use.
One service we don’t yet have a built-in integration is Google Hangouts Chat, the GSuite tool that facilitates group communication. In this blog post, I am going to describe how you can integrate Runscope with Hangouts Chat so you can get your team notified about Runscope tests in this GSuite tool.
Here is a snippet of what the webhook JSON data looks like:
{ "test_id": "76598752-cbda-4e1d-820f-6274a62f74ff", "test_name": "Buckets Test", "team_name": "Acme Inc.", "environment_uuid": "98290cfc-a008-4ab7-9ea4-8906f12b228f", "environment_name": "Staging Settings", "bucket_name": "Rocket Sled", "bucket_key": "bucket_key", "test_run_url": "https://www.runscope.com/radar/bucket_key/76598752-cbda-4e1d-820f-6274a62f74ff/results/9c15aa62-21f0-48f2-a819-c99bdf8e4543", "result": "pass", "started_at": 1384281308.548077, "finished_at": 1384281310.680218, "region_name": "US East - Northern Virginia", }
You can also check out our webhooks documentation for a more detailed look.
To create the integration with Hangouts Chat, we are going to use EventN, an HTTP microservices platform specifically designed for data processing and analytical workloads. You can use it to launch microservices, and each one you create provides a Node.js JavaScript function runtime that executes when an HTTP request is made. EventN allows you to create services that execute code you specify, much like AWS Lambda or Google Cloud Functions. (For a more in-depth look at EventN, we had an earlier guest post from EventN about storing Runscope test results to a database.)
Create an EventN service to send Runscope webhoooks to Google Hangouts Chat
To get started, first we need to create a free account at https://eventn.com. To make it easy, rather than manually configuring your service in EventN, we’ve created a Runscope Test you can use to create the EventN Service using the EventN API. All you need to do is download this file and then import it into your Runscope account as a new test. Next, open the test and add two initial variables to your environment -- email (the email address you used to create your EventN account) and password (your EventN password):

Now, you can run this test just once and it will create a microservice in EventN that can receive a Runscope webhook and send a notification to a Google Hangouts Chat room. On the test results page, make sure to save the serviceId and serviceToken variables values for later, as we will use them to configure the Runscope integration part:

Add an Incoming Webhook to Hangouts Chat
To add an incoming webhook to Hangouts Chat, start by creating a room (or take an existing room) and then from the top menu select “Configure webhooks”:

On the subsequent page, give your bot a name (“Runscope Notifications”) and assign an icon (you can use this image file if you want the Runscope logo!):

Click save, and Hangouts Chat is now ready to receive notifications from Runscope. Copy the URL provided to use in our next step:

(For more detailed instructions, you can find the Hangouts Chat incoming webhook docs here.)
Configure Runscope Advanced Webhook
The last step is to configure the integration on the Runscope side. To do this, we will need the information we’ve collected in earlier steps:
eventN service id (EVENTN_SERVICE_ID)
eventN service token (EVENTN_SERVICE_TOKEN)
Hangouts Chat webhook URL (CHAT_WEBHOOK_URL)
Click on the top right icon in Runscope and then choose “Connected Services". Scroll down until you find the “Customized webhook notifications” and then click “Connect” to add our service:

Add a description for your integration, e.g. “Google Chat - Runscope Room (Failures)” and specify whether you want to be notified on all test runs or only after failures.
For the URL, you will use https://service.eventn.com/{EVENTN_SERVICE_ID}, making sure to replace {EVENTN_SERVICE_ID} with the ID you got from the earlier steps.
We then need to add three headers:
Content-Type - application/json
chaturl - CHAT_WEBHOOK_URL
Authorization - Bearer EVENTN_SERVICE_TOKEN
Again, making sure that we replace CHAT_WEBHOOK_URL and EVENTN_SERVICE_TOKEN with the values that we got from earlier steps:

Click “Save Changes” and your integration should be ready to go.
Now, when you create a test, you can simply switch on our custom webhooks integration, and notifications will now go to Google Hangouts Chat based on the settings you specified!

And here's what the notification should look like:

If you want to further customize the notification, you can just edit the EventN service you’ve created from the EventN dashboard. You can also find more information about how to format Hangouts Chat messages here.