Difference between revisions of "Bot Playground/Events/playground webhook"
From SmartBots Developers Docs
Line 16: | Line 16: | ||
{{API Variables Table End}} | {{API Variables Table End}} | ||
− | == Important | + | == Important notes == |
− | If the payload on the request is not valid JSON, the payload object will come through as an empty object. | + | # If the payload on the request is not valid JSON, the payload object will come through as an empty object. |
− | + | # To send string payload set "Content-Type: text/plain" on a remote server. | |
− | It is best practice to place the event above the http.requestWebhook() command, to catch any early requests. | + | # It is best practice to place the event above the http.requestWebhook() command, to catch any early requests. |
== Example == | == Example == | ||
Line 39: | Line 39: | ||
--header 'Authorization: Bearer PBubZ9CbPd9PWUm2n6L5ygfHkhCOUf8V' \ | --header 'Authorization: Bearer PBubZ9CbPd9PWUm2n6L5ygfHkhCOUf8V' \ | ||
--data '{"exampleData": 123456}' | --data '{"exampleData": 123456}' | ||
+ | |||
+ | # Use --header 'Content-Type: text/plain' to send text string instead of JSON. | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Revision as of 10:17, 11 August 2025
Fires when the script’s webhook receives an HTTP request from your server.
Bot.on("playground_webhook", function(event) { ... });
Reference
This event comes with the following event object:
Variable | Required | Description | |
---|---|---|---|
event object properties: | |||
name | string | The name of the event | |
bot_slname | string | Your bot’s Second Life name (e.g. "smartbots Resident"). | |
hookId | string | Identifier of the current webhook (also visible at the end of the request’s URL). | |
correlationId | string | A unique identifier for this request. | |
payload | object | Parsed JSON data from the request. |
Important notes
- If the payload on the request is not valid JSON, the payload object will come through as an empty object.
- To send string payload set "Content-Type: text/plain" on a remote server.
- It is best practice to place the event above the http.requestWebhook() command, to catch any early requests.
Example
Bot.on("playground_webhook", (event) => {
console.log("Webhook received:", event);
});
Sending a request from a remote server
Sending a POST request to the webhook URL, and including the Authorization and Content-Type headers. The payload is JSON.
curl --location 'https://gate07.play.mysmartbots.com/userhook/ca4687a9-db28-43ee-9bb8-cf80100t41cf' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer PBubZ9CbPd9PWUm2n6L5ygfHkhCOUf8V' \
--data '{"exampleData": 123456}'
# Use --header 'Content-Type: text/plain' to send text string instead of JSON.
Example response:
{
"success": true,
"correlationId": "bb980f2e-b3e0-4eee-acd0-f5041af6a449"
}
Example playground_webhook event:
{
"name": "playground_webhook",
"bot_slname": "smartbot Resident",
"hookId": "ca4687a9-db28-43ee-9bb8-cf80100t41cf",
"correlationId": "bb980f2e-b3e0-4eee-acd0-f5041af6a449",
"payload": {
"exampleData": 123456
}
}
Check the complete example script and scenario.