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 on every script restart. Make sure to deliver them to your remote server.

For details on sending requests to 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 the complete example script and scenario.