Difference between revisions of "Bot Playground/Examples/Webhooks"
From SmartBots Developers Docs
Line 1: | Line 1: | ||
{{DISPLAYTITLE:Playground webhook usage example}} | {{DISPLAYTITLE:Playground webhook usage example}} | ||
− | + | The following example demonstrates the use of a webhook: | |
# creating a webhook, | # creating a webhook, | ||
Line 19: | Line 19: | ||
// 2. Display its data | // 2. Display its data | ||
+ | // (You probably send this to your server but we just display the data) | ||
console.log("Webhook details:", webhook); | console.log("Webhook details:", webhook); | ||
</syntaxhighlight> | </syntaxhighlight> |
Latest revision as of 10:14, 11 August 2025
The following example demonstrates the use of a webhook:
- creating a webhook,
- displaying webhook details,
- sending data from a remote server,
- receiving these data in a script.
Playground script
Bot.on("playground_webhook", (event) => {
console.log("Webhook received:", event);
});
// 1. Create a webhook
const webhook = await http.requestWebhook(); // Requests the webhook URL and token
// 2. Display its data
// (You probably send this to your server but we just display the data)
console.log("Webhook details:", webhook);
Example output:
Webhook details:
{
url: "https://gate07.play.mysmartbots.com/userhook/ca4687a9-db28-43ee-9bb8-cf80100t41cf",
token: "PBubZ9CbPd9PWUm2n6L5ygfHkhCOUf8V"
}
Remote server simulation (curl)
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}'
Example output:
{
"success": true,
"correlationId": "bb980f2e-b3e0-4eee-acd0-f5041af6a449"
}
Playground webhook output
Webhook received:
{
"name": "playground_webhook",
"bot_slname": "smartbot Resident",
"hookId": "ca4687a9-db28-43ee-9bb8-cf80100t41cf",
"correlationId": "bb980f2e-b3e0-4eee-acd0-f5041af6a449",
"payload": {
"exampleData": 123456
}
}