Discord Governance Alerts Bot
Prerequisites
Before we begin, make sure you have the following:
- A Leap webhooks (opens in a new tab) account.
- A Discord (opens in a new tab) account
- A Replit (opens in a new tab) account
- Familiarity with Python
Overview
Here's a brief outline of the steps we'll cover in this guide:
- Creating a new webhook!
- Configuring Leap’s Notifications Webhook
- Writing the Python code for the bot
- Setting up the Discord bot
Let's dive in!
Step 1: Setting up the Python App on Replit
- Log into Replit and click the "Create Repl" button in your menu.
- Search and select the Flask template. Name the project whatever you like.
- Write the following code in yourÂ
main.py
 file. This script is tailored to Governance notifications.
import os
from flask import Flask, request, Response
import requests
import traceback
import sys
import json
app = Flask(__name__)
# Set up discord Webhook url in order to send message to your discord server
DISCORD_WEBHOOK_URL = os.environ["DISCORD_WEBHOOK_URL"]
def get_parsed_message(event):
event_type = event.get("__type", None)
text = None
if event_type == "cosmos.gov.deposit":
text = "Deposit for chain:{},proposalID: {} {}{}, ".format(
event["blockchain"],
event["proposalId"],
event["tokens"][0]["quantity"],
event["tokens"][0]["denomination"],
)
elif event_type == "cosmos.gov.vote":
text = "Vote:{} received for chain:{},proposalID: {}".format(
event["option"], event["blockchain"], event["proposalId"])
elif event_type == "cosmos.gov.submitProposal":
text = "Governance Proposal Submitted chain:{},proposalID: {}, {}{}".format(
event["option"],
event["blockchain"],
event["proposalId"],
event["tokens"][0]["quantity"],
event["tokens"][0]["denomination"],
)
return text
def send_discord_message(message):
# Send a message to Telegram using Telegram API
url = DISCORD_WEBHOOK_URL
payload = json.dumps({"content": message})
headers = {"Content-Type": "application/json"}
response = requests.request("POST", url, headers=headers, data=payload)
print(response.text)
return
def handler(event):
# Handle the event and send a message to Telegram
print(event)
message = get_parsed_message(event)
if message is None:
print("Event is not parsed")
return
send_discord_message(message)
@app.route("/", methods=["GET"])
def main():
# Return a success response to the request
return Response(status=200)
@app.route("/", methods=["POST"])
def webhook():
# Handle incoming webhook requests
handler(request.json)
# Return a success response to the request
return Response(status=200)
# Start Flask app
if __name__ == "__main__":
app.run(host="0.0.0.0", port=81)
Step 2: Create Webhook URL for your Discord server and link it to server
- Follow through Create Discord Webhook (opens in a new tab) to create your webhook url.
- Copy the webhook url generated from step 1.
- Open the Secrets tool in Replit. Store the API token in an environment variable DISCORD_WEBHOOK_URL. This ensures the token remains secure and accessible to your Python script.
Step 3: Create a new webhook
The server’s URL will follow the pattern <project_name>.<user_name>.repl.co
 . Once you've entered the URL, click "Create Webhook" to activate it, and your bot will start receiving data from Alchemy whenever the specified event takes place.
Your Telegram bot is now set up and ready to send notifications for Governance events or any other event you've tailored the handler to process.
Turn off your Alchemy webhook when you're not using it in order to preserve your credits.
-
Log in to your Leap webhooks (opens in a new tab) account.
-
Click "New Webhook" and fill in the following details. Name of the web : Give the webhook you have created a name Select Chain from the dropdown : We have selected osmosis for this example. Refer to the docs (opens in a new tab) to get list of chains supporter *Transaction type(s) : Multi-Select from the drop down all the transactions you want to listen to. For the purpose of setting up Governance alerts you can select “Gov Deposit”, “Submit Proposal” and “Vote”. Refer to the docs (opens in a new tab) to get a list of transaction types supports
Webhook URL:* Paste the webhook url which you copied from replit, it will be of the format <project_name>.<user_name>.repl.co
- Click on “Create” once you have entered all details.
- Verification code is sent to your python server hosted on replit, just copy the verification code that is printed on the terminal in replit, and paste it in the dialog box asking for Verification key in leap notifications portal.
- Your bot is ready to receive and start sending notifications to Discord now.
Production
Your development server will stop running when you close the Replit window. To keep it live all the time, you can use Replit Deployments.
If you use a Deployment, make sure to use the Deployment URL in your Alchemy webhook instead of the development URL.