Introduction

  • This guide assumes you have an approved bot on top.gg and are using either Node.js or Python for your project.
  • Next, you will need to create an account on Square Cloud, which can be done through the sign up page. You can use your email to create an account.
  • Finally, you need to have an active paid plan on your account. You can view our plans and purchase one according to your needs here.

Setting Up the Environment

  1. Before you begin, make sure you have Node.js and npm installed on your system. If you don’t have them yet, you can download them from the official Node.js website.
  2. Start a new Node.js project with the following command:
Terminal
npm init -y
This command creates a package.json file in the current directory.
  1. Install the necessary libraries:
Terminal
npm install @top-gg/sdk express

Setting Up the Project

1. Get your webhook authentication:
  • Go to your Top.gg profile here.
  • Click “edit” on the bot you want to receive notifications for votes.
  • Under “GENERAL”, choose the “webhook” option.
  • Set the webhook authentication in “Authorization”. In this example, we used “myappsquare”.
2. Implement the webhook listener: The following sections provide code examples for both Javascript and Python:
We will use the example provided by the top.gg documentation here, with some modifications.
index.js
// Import libraries
const Topgg = require("@top-gg/sdk");
const express = require("express");

// Create Express app and Top.gg webhook instances
const app = express();
const webhook = new Topgg.Webhook("YOUR_AUTHORIZATION_TOKEN");

// Define route for '/topgg' endpoint (POST requests)
app.post("/topgg", webhook.listener((vote) => {
  // Log vote received message with user ID
  console.log(`Vote received successfully! User ID: ${vote.user}`);
}));

// Start server on port 80 (default HTTP)
app.listen(80);

Creating the squarecloud config file

Learn about: how to make the configuration file for Square Cloud.

The squarecloud.app file is a configuration file that will be used to configure your application; it will be used to define the name, description, version, main file, among other things.

Uploading Your Application to Square Cloud

After following all the steps, put your application files into a .zip file, including the configuration file. If your application is a Node.js project, take a look at our article on Node.js. If your application is a Python project, take a look at our article on Python.
Access the Square Cloud Dashboard and upload your project files.

Starting Tests

If you have done everything correctly, try accessing your site using the subdomain defined in the configuration file. If you defined it as “mysite”, to access it will be https://mysite.squareweb.app/. After you access and only “Cannot GET /” or “Method Not Allowed” appears, everything is okay. Now, you need to go back to the previous page where the authorization was defined. In the Webhook URL field, you should put the URL of your site with the route that will receive the votes.
  • For the JavaScript code we created with app.post("/topgg", webhook.listener((vote) => {...}), the route that will receive the votes is “/topgg”. So, if your website is “https://mysite.squareweb.app”, you should put “https://mysite.squareweb.app/topgg” as the Webhook URL.
  • For the Python code we created with @app.route("/topgg", methods=["POST"]), the route that will receive the votes is also “/topgg”. So, the Webhook URL would be the same “https://mysite.squareweb.app/topgg”.
Finally, click on the “Send Test” button. After that, check the terminal. If everything went well, the message you defined in console.log or print should appear in the terminal.
And with that, if everything has been configured correctly, your webhook will be ready to send notifications when your bot receives a vote on top.gg.

Troubleshooting

Custom Domain

To use a custom domain (e.g., mysite.com) instead of the default URL https://mysite.squareweb.app/, you need the Standard plan or higher. The subdomain is defined by the SUBDOMAIN field in the configuration file. See: How to set up your custom domain.

Minimum RAM Requirements

Minimum: 512MB RAM for simple websites/APIs. For sites with frameworks (Next.JS, React, Vue, Angular, etc.), we always recommend at least 1GB RAM. For larger applications, use more RAM to avoid LACK_OF_RAM error and ensure performance.

Could not find this site.

Check if the subdomain/domain matches what's configured in the SUBDOMAIN field or in the custom domain settings. If you just uploaded the site, wait up to 60 seconds for Square to enable first access.

Site took too long to respond...

Check if you correctly configured port 80 and host 0.0.0.0 in the application. We recommend using Square's forced environment variables: PORT and HOST from the .env file.
If you continue facing technical difficulties, our specialized support team is available to assist you. Contact us and we'll be happy to help you resolve any issue.