http.requestWebhookUrl
From SmartBots Developers Docs
Allocates a new, per-run webhook URL and authorization token for the current script instance.
const webhook = await http.requestWebhook(); // Requests the webhook URL and token
console.log("Webhook details:", webhook);
Reference
This command accepts the following parameters:
Variable | Required | Description
| |
---|---|---|---|
Input: | |||
Output: | |||
Function returns a Promise with the following data: | |||
success | bool | true if command completed successfully | |
error | string | error string if command has failed | |
url | string | Endpoint that accepts your server’s POST requests. | |
token | string | Bearer token you must include in the Authorization header. |
Comments
It is good practice to register the the event first: Put Bot.on("playground_webhook", …) before http.requestWebhook() to avoid missing early responses.
For details on sending requests to the webhook, see (link to playground_webhook event page).
Example
A simple demonstration of obtaining a webhook URL and token, and listening for the playground_webhook event:
//Event should be placed first, to catch any early requests.
Bot.on("playground_webhook", (event) => {
console.log("Webhook request received:", event);
});
//Request the webhook URL and token.
const webhook = await http.requestWebhook();
console.log("Webhook:", webhook);
Check the complete example script and scenario.