Grafana-Webhook & WhatsApp-API to get alert message on WhatsApp

Hello Community,
Grafana is really a great art developed by the team.
Alert messages from Grafana panel can be sent on WhatsApp opting any WhatsApp API service provider. Text in “message” portion of alert panel can be sent on WhatsApp

In this example, Chat-API is used as WhatsApp API service provider. Free for first 3 days. After creating account notedown https APIURL and token.
Steps:

  1. Install Flask dependencies, Create Flask webserver use below py script(app.py)
from flask import Flask, request, jsonify
from wabot import WABot
import json

app = Flask(__name__)

@app.route('/', methods=['POST'])
def home():
    if request.method == 'POST':
        print(request.json)
        bot = WABot(request.json)
        return bot.processing()

if(__name__) == '__main__':
    app.run(host="localhost", port=8000)
  1. In another py script (wabot.py) enter details of your Chat-API APIURL and token. At the end, enter details of country code and phone number
import json
import requests
import datetime

class WABot():
    def __init__(self, json):
        self.json = json
        self.dict_messages = json
		# Chat-API Details
        self.APIURL = 'https://api.chat-api.com/instance......./'
        self.token = '.....................'

    def send_requests(self, method, data):
        url = f"{self.APIURL}{method}?token={self.token}"
        headers = {'Content-type': 'application/json'}
        answer = requests.post(url, data=json.dumps(data), headers=headers)
        return answer.json
  
    def send_message_with_phone(self, phoneNumber, text):
        data = {"phone": phoneNumber,
                "body": text}
        answer = self.send_requests('sendMessage', data)
        return answer

    def processing(self):
     #  print("messages = ",self.dict_messages)
        if self.dict_messages != []:
           for message in self.dict_messages:
            #   print("message = ",message)
                if message == "message":
                    text =  self.dict_messages[message]
                    return self.send_message_with_phone('91xxxxxxxxxx',text)
  1. Create notification channel of type - webhook, url - http://localhost:8000/, Http Method - POST
  2. Add this notification channel in your Grafana alert panel. In alerting state, Grafana Webhook will ping flask webserver and expose message through WhatsApp API.
  3. Keep app.py running
    Explore Grafana!!!

Hi there
is this Script also work with WhatsApp modified version’s like this GB WhatsApp?

I am trying to integrate WhatsApp API with this modified application which failed me again and again.

Hi @ethanmiles,

you can give a try to this method. It’s free and easy to configure.

1 Like

You are there are too many apps that are modified versions of original apps. And whatsapp also have modified version like this GBWhatsapp. I have try this many time but I can’t.

Hi @lu4t lu4t ,

thanks for the last video on “Grafana WhatsApp”.
I did everything as in the video, but the error message always comes up when creating the URL:
“This endpoint is disabled for your subscription”.
I took the Basic because 10/day is enough for me.

Why does the error always come up?

Best regards
netzkeks

Hi,
the webhook listener is not part of the Basic plan since we included the ability to send whatsapp alerts to whatsapp groups:

We found that, even if you don’t have the intention of getting more than 10 alerts/day, this is something totally out of your control… sometimes resulting in a back-end flooded with alerts that need to be delivered

I hope it makes sense. :slight_smile:

Thanks for this API. I will try

The release date of Titli has been postponed by a week and will now air on 6th June 2023.
Here is a detailed description of the serial Titlii on Star Plus full episodes online free.
Desi Serial

I was already able to make the connection, but, anyone know how to simplify the messages that send grafana by the Webhook?