Difference between revisions of "Bot Playground/Examples/Webhooks"
From SmartBots Developers Docs
(Created page with "Example of using a webhook: # creating a webhook, # displaying its details, # sending data from a remote server, # receiving these data in a script. == Playground script ==...") |
|||
Line 2: | Line 2: | ||
# creating a webhook, | # creating a webhook, | ||
− | # displaying | + | # displaying webhook details, |
# sending data from a remote server, | # sending data from a remote server, | ||
# receiving these data in a script. | # receiving these data in a script. | ||
Line 18: | Line 18: | ||
// 2. Display its data | // 2. Display its data | ||
console.log("Webhook details:", webhook); | console.log("Webhook details:", webhook); | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | Example output: | ||
+ | |||
+ | <syntaxhighlight lang="json"> | ||
+ | Webhook details: | ||
+ | { | ||
+ | url: "https://gate07.play.mysmartbots.com/userhook/ca4687a9-db28-43ee-9bb8-cf80100t41cf", | ||
+ | token: "PBubZ9CbPd9PWUm2n6L5ygfHkhCOUf8V" | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | == Remote server simulation (curl) == | ||
+ | |||
+ | <syntaxhighlight lang="bash"> | ||
+ | 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}' | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | <syntaxhighlight lang="json"> | ||
+ | { | ||
+ | "success": true, | ||
+ | "correlationId": "bb980f2e-b3e0-4eee-acd0-f5041af6a449" | ||
+ | } | ||
+ | </syntaxhighlight> | ||
+ | |||
+ | == Playground webhook output == | ||
+ | |||
+ | <syntaxhighlight lang="json"> | ||
+ | Webhook received: | ||
+ | { | ||
+ | "name": "playground_webhook", | ||
+ | "bot_slname": "smartbot Resident", | ||
+ | "hookId": "ca4687a9-db28-43ee-9bb8-cf80100t41cf", | ||
+ | "correlationId": "bb980f2e-b3e0-4eee-acd0-f5041af6a449", | ||
+ | "payload": { | ||
+ | "exampleData": 123456 | ||
+ | } | ||
+ | } | ||
</syntaxhighlight> | </syntaxhighlight> |
Revision as of 10:10, 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}'
{
"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
}
}