Difference between revisions of "Bot Playground/Built-in Functions/http.requestWebhookUrl"

From SmartBots Developers Docs
Jump to: navigation, search
(Created page with "{{DISPLAYTITLE:{{SUBPAGENAME}}}} <onlyinclude>Allocates a new, per-run webhook URL and authorization token for the current script instance.</onlyinclude> <syntaxhighlight lan...")
 
 
(3 intermediate revisions by the same user not shown)
Line 3: Line 3:
  
 
<syntaxhighlight lang="javascript">
 
<syntaxhighlight lang="javascript">
const webhook = await http.requestWebhook(); // Requests the webhook URL and token
+
const webhook = await http.requestWebhook();
console.log("Webhook details:", webhook);
+
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Line 23: Line 22:
 
It is good practice to register the the event first: Put Bot.on("playground_webhook", …) before http.requestWebhook() to avoid missing early responses.
 
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).
+
Hook URL and token change ("release") on every script restart. Make sure to deliver them to your remote server.
 +
 
 +
The consequent calls to __requestWebhook()__ return the same url/token. These values persist while script is running. There's no system-wide limits on number of webhooks (in a contrary to [https://wiki.secondlife.com/wiki/LlRequestSecureURL LLRequestURL]).
 +
 
 +
For details on calling the webhook, see [[Bot_Playground/Events/playground_webhook|playground_webhook event]].
  
 
== Example ==
 
== Example ==
Line 39: Line 42:
 
console.log("Webhook:", webhook);
 
console.log("Webhook:", webhook);
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
Check a [[Bot_Playground/Examples/Webhooks|complete example script]] and scenario.
  
 
{{NavMenu}}
 
{{NavMenu}}
 
__NOTOC__
 
__NOTOC__

Latest revision as of 10:53, 11 August 2025

Allocates a new, per-run webhook URL and authorization token for the current script instance.

const webhook = await http.requestWebhook();

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.

Hook URL and token change ("release") on every script restart. Make sure to deliver them to your remote server.

The consequent calls to __requestWebhook()__ return the same url/token. These values persist while script is running. There's no system-wide limits on number of webhooks (in a contrary to LLRequestURL).

For details on calling the webhook, see playground_webhook event.

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 a complete example script and scenario.