Webhooks lib
Integration with external services can be possible with webhooks notifications. This lib generate url for webhooks.
Example bot
See example bot
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
This code will generate Webhook url.
After loading page via this url:
web page with cat will be loaded (Thank for cat to https://cataas.com)
command
/onWebhook
will be execute on Bot for user with user.idcontent "Did you see the cat?" will be passed for command
/onWebhook
Receive webhook for user
As a rule, the webhook URL must be set from the admin panel on the external service. So we can not set it for just one user:
Webhooks can be with GET and POST methods only. All passed data contains on content variable
On command /onWebhook
we can get posted content from external service
As a rule, external service must pass useful data on webhook. For example info about payments: order_id, user_id. Use it!
Receive global webhook for bot
On command /onWebhook
for bot's webhook we do not have user:
Call options
You can use options on BJS on webhook request
/onWebhook
command:
Key | Value |
---|---|
| webhook url |
| request method ("GET" or "POST") |
| request params |
| headers for this request like Ip, User-Agent, Accept-Language and etc |
| client IP |
Webhook response
1. Content response with bot answer
2. Content response without bot answer
You can use WebApp render - it is not produce message from bot.
Code response
Webhook response can be:
200 - BJS is runned, no errors
503 - we have errors in BJS
you can throw error in BJS:
throw new Error("Error on webhook")
Possible issues
In the case of a large number of requests from an external web service, such a web service may be subject to ban filters.
Please provide an external IP address and we will add it to the White List.
Last updated