From wikipedia: a webhook is a method of augmenting or altering the behavior of bot, with custom callbacks.
These callbacks may be maintained, modified, and managed by third-party users and developers who may not necessarily be affiliated with the originating website or application.
The term "webhook" was coined by Jeff Lindsay in 2007 from the computer programming term hook.
Webhooks is more simple way for integration. Other libs also use webhooks notifications already: CoinPayments, FreeKassa.
Webhook link have public_user_token - it is public secret.
User can't modify user_id, command because it is protected with public_user_token.
Get Webhook Url
// user's webhookletwebhookUrl=Libs.Webhooks.getUrlFor({ // this command will be runned on webhookcommand:"/onWebhook", // this text will be passed to commandcontent:"Did you see the cat?", // execute for this (current) useruser_id:user.id, // redirect to page with cat after calling webhook // you need remove this for external serviceredirect_to:"https://cataas.com/cat"})Bot.inspect(webhookUrl);
// global bot webhook
let webhookUrl = Libs.Webhooks.getUrlFor({
// this command will be runned on webhook
command: "/onWebhook",
user_id: user.id
})
// for user's webhook
Bot.sendMessage(inspect(content))
// also you can read data with Bot.getProperty - you need store it before
// for bot's webhook
// this is not worked - because no current user on bot's webhook
// Bot.sendMessage(inspect(content))
// make any not specific user code
// ...
// We can pass user_id in content (it is depend from external service)
Bot.run({
command: "/userCommand",
user_id: JSON.parse(content).user_id
})
// in /userCommand we can now use Bot.sendMessage function
Bot.sendMessage(
JSON.stringify(options)
);
// call user's webhook
// first message sending appears on bot
Bot.sendMessage("This answer will be in bot");
//...
// last message sending
// will be on bot and on web page
// you can open this web page on your browser via webhook url
Bot.sendMessage("Hello in browser!");
// in web page you will have:
// { answer: "Hello in browser!" }
// render this command in web
WebApp.render({ content: "Hello from bot " + bot.name });