Using ngrok
Testing out SendBlocks functions
The simplest way to test out SendBlocks functions is to use ngrok. ngrok is a tool that allows you to expose a local web server to the internet. This is useful for testing webhooks, which we use to communicate with your server.
Starting a local web server
First, you will need a local web server running to accept the webhook requests from SendBlocks. You can use any web server you like, but we recommend using Express. If you don't have Express installed, you can install it with the following command:
npm install express
Once you have Express installed, create a file called server.js
and add the following code:
const express = require("express");
const app = express();
// Listen on port 8000
const LISTEN_PORT = 8000;
app.listen(LISTEN_PORT, () => {
console.log("Listening on port " + LISTEN_PORT);
});
// Parse request body as JSON
app.use(express.json());
// Print body of webhook requests and return 200 OK
app.post("/", (req, res) => {
console.log("Received webhook");
console.log(req.body);
res.sendStatus(200);
});
Use the following command to run the web server:
node server.js
Test your server using curl:
curl -X POST http://localhost:8000/webhook -H "Content-Type: application/json" -d '{"hello": "world"}'
Exposing your local web server with ngrok
Now that you have a local web server running, you can use ngrok to expose it to the internet. To do this, you will need to download and install ngrok. Once you have ngrok installed, run the following command to start forwarding requests to your local web server:
ngrok http 8000
You will find the forwarded URL in the Forwarding
field in the output of the command.
ngrok
Session Status online
Account ...
Version ...
Region ...
Latency ...
Web Interface http://127.0.0.1:4040
Forwarding https://1234-12-34-56-789.eu.ngrok.io -> http://localhost:8000
Copy the URL into the url
field in Create Webhook, then provide the returned webhook ID to Create Function.
Updated about 1 month ago