http.requestWebhookUrl

From SmartBots Developers Docs
Jump to: navigation, search

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.