Skip to content

yTax/webhook-protector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


🔐 {Webhook Protector} 🔐

A simple way to avoid hard-coding your webhooks or risking a deletion.
Request Feature or report a bug

⭐ 〢 Usage

This is a very simple script written in python that you can host anywhere, it has a very simple purpose which is ratelimitting and protecting your discord webhook from being deleted, this script will also be compatible with any other webhook integration if you make some small tweaks to it. It is implemented in a very basic way using Flask.

To understand how to use this read Getting Started

🚀 〢 Getting Started

The easiest way to install this for free is on Render (Lifetime free hosting).

If you want to install it on your own server you can simply download the files. Dont forget to edit main.py to setup your webhook and key or to hook it up to a .env file!

💻 〢 Installation on Render

  1. Setup a Render account.
  2. Fork this repository.
  3. Go to the Dashboard and click connect github. Dashboard Connection
  4. Write python main.py as your start up command. Select Free as the instance type. Dashboard Settings
  5. Click Enviroment and setup the environment variables like this: Env Variables
DISCORD_WEBHOOK_URL : Write your webhook here.
SECRET_KEY : Write your key here, this is the key you will use to send requests to your render API. It can be whatever you want.
  1. Press "Deploy Web Service"
  2. After your service is deployed grab it's URL on the dashboard, it should look something like: https://webhook-protectorbzx4y.onrender.com Webserver URL
  3. Now we need to keep our Render server alive 24/7, to do this make an account on CronJob
  4. After creating your account, go to the Dashboard and click Create CronJob. Create Cron
  5. Type whatever you want for the title and set your Render URL as the CrobJob URL.
  6. Set the execution schedule to every 5 minutes.
  7. Go into the Advanced tab and set a header with the key Authorization and value KeepAlive, finally change your request method to POST. Advanced Tab
  8. Done! Your webhook is now protected. The cronjob will keep the render server alive 24/7.

📄 〢 Documentation

There are 2 example scripts on this repository that show you how to POST to your API and the main.py code is very well commented. If you have any questions feel free to open an issue or contact me!

Example on how to send a message containing files:

This script is inside SendJsonAndFiles.py

import requests

url = "render URL" # URL TO YOUR RENDER


payload = {
    "payload_json": '{"username": "test", "content": "hello"}' # your JSON payload, like an embed or a message, this is obviously optional if u just want to send a file
}

# Files to send
with open(r"PATH TO FILE ") as file: # here we use r"" to prevent python from fucking up the string
    files = {"file1": file} 

    # header with ur key
    headers = {"Authorization": "yourkey",}
    response = requests.post(url, data=payload, files=files, headers=headers)

    print(response.text)

Example on how to send a message:

This script is inside SendJson.py

import requests

url = "your URL" # URL TO YOUR RENDER


payload = {"username": "test", "content": "hello"} # your JSON payload



# header with ur key
headers = {"Authorization": "yourkey",}
response = requests.post(url, json=payload, headers=headers)

print(response.text)

📋 〢 To-do List

  • Possibly make a web-ui for this and an account system.
  • Feel free to give any suggestions!

About

A simple way to avoid hard-coding your webhook or risking a deletion.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages