Ping Alert Bot Using Mule 4 and Google Chat API
These 8 steps will help you set up an automated alert bot with Mule 4 to ping a channel in the Google Chat app, letting you keep support personnel on notice.
Join the DZone community and get the full member experience.Join For Free
In this article, we will explore how we can send asynchronous messages in Google chat rooms with the help of Mule 4 and Google Chat API. The Anypoint Studio version used will be version 7.6, and the Mule runtime version will be 4.3 for this demonstration. It will be better to use the same version of Anypoint Studio and Mule runtime if you are planning to try to build the project.
- Gmail Business Account
- Anypoint Studio 7.6
- ObjectStore Connector
This comes with a Gmail business account, or you can get a trial on this feature for 14 days.
From direct messages to group conversations, Google Chat helps teams and businesses collaborate fluidly and efficiently from anywhere. Securely connect with anyone you work with, and take group work to the next level with shared chat, files and tasks.
Step 1: Create a Google chat room in the Google Chat app. Instructions from Google:
- Sign in to Chat or Gmail.
- Next to Rooms, click Create or Find a room > Create room.
- Enter a room name.
- (Optional) In the top left, click Choose an emoji . If you don't select an emoji, a default avatar is used.
- Enter names or email addresses of people and groups you want to add. You can also select from suggestions. Suggestions include everyone in your organization, even if they don't have Chat.
Step 2: Create a webhook and copy the incoming webhook URL to use in our flow to send messages asynchronously.
Step 3: Add Object Store Connector in your studio from exchange if it's not already present.
Step 4: Add NetworkUtils.java class in the src/main/java folder of the project. The java file is provided by Mulesoft in net-tools-v2.2.0. You can download the java file from here [github-repository] and place it in your project location.
Step 5: Call the java function inside your transform message component, which will ping the URL you want to access and give the ping output (if packet loss is there or not).
Step 6: Extract the packet loss from the ping-output (text format) into a number.
Step 7: Validate if the packet loss is greater than 50% with the help of the validation module and if yes, then trigger a request to our Google chat room with ping output using incoming webhook URL.
Step 8: Configure an Object Store to store the thread name to post the ping alerts in the same thread when sending the message and configure HTTP request connector to push messages with incoming webhook URL.
- You can use these types of bots to send alerts to on-call personnel or a support person to take proactive action.
- This bot can also be used to send alerts into chats when certain business transactions complete.
To download the project, you can use this GitHub URL.
Let's give to the community.
Opinions expressed by DZone contributors are their own.