Webhooks lib
Last updated
Was this helpful?
Last updated
Was this helpful?
Integration with external services can be possible with webhooks notifications. This lib generate url for webhooks.
See
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.
This code will generate Webhook url.
After loading page via this url:
command /onWebhook
will be execute on Bot for user with user.id
content "Did you see the cat?" will be passed for command /onWebhook
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!
On command /onWebhook
for bot's webhook we do not have user:
You can use options on BJS on webhook request
/onWebhook
command:
options.url
webhook url
options.method
request method ("GET" or "POST")
options.params
request params
options.headers
headers for this request like Ip, User-Agent, Accept-Language and etc
options.ip
client IP
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")
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.
web page with cat will be loaded (Thank for cat to )
You can use render - it is not produce message from bot.