Difference between revisions of "Bot Playground/Built-in Functions/http.requestWebhookUrl"
From SmartBots Developers Docs
(Created page with "{{DISPLAYTITLE:{{SUBPAGENAME}}}} <onlyinclude>Allocates a new, per-run webhook URL and authorization token for the current script instance.</onlyinclude> <syntaxhighlight lan...") |
|||
Line 39: | Line 39: | ||
console.log("Webhook:", webhook); | console.log("Webhook:", webhook); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | Check the [[Bot_Playground/Examples/Webhooks|complete example script]] and scenario. | ||
{{NavMenu}} | {{NavMenu}} | ||
__NOTOC__ | __NOTOC__ |
Revision as of 10:12, 11 August 2025
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.