Difference between revisions of "Bot Playground/Examples/Webhooks"
From SmartBots Developers Docs
Line 1: | Line 1: | ||
+ | {{DISPLAYTITLE:Playground webhook usage example}} | ||
+ | |||
Example of using a webhook: | Example of using a webhook: | ||
Revision as of 10:13, 11 August 2025
Example of using 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
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
}
}