Lesson 4. Webhook — Real-Time Notifications#
Why This Matters#
A webhook is a way to receive notifications from a service when something happens. For example, when a client pays for an order, the payment system sends a webhook to your bot.
Key Idea#
Webhook = "call me when something happens"
Instead of constantly asking "is the order paid?", you give the service your address, and it notifies you itself.
How Webhooks Work (Analogy)#
Usual way (polling):
You call the store every 5 minutes: "Is my order ready?"
→ You waste time and nerves
Webhook:
You tell the store: "When the order is ready, call me at this number"
→ The store calls you when it's ready
Webhook Example in Integration#
Scenario: payment via Stripe → notification in Telegram
-
Client pays for an order on the website (via Stripe)
-
Stripe sends a webhook to your server:
- "Order #123 paid, client — Ivan, amount — 5000 rubles"
-
Your server receives the webhook and sends a notification to the manager in Telegram
-
The manager sees: "New payment! Order #123, Ivan, 5000 rubles"
Webhook vs API#
| Characteristic | API (request) | Webhook (notification) |
|---|---|---|
| Who initiates | You ask the service | The service notifies you |
| When it triggers | When you send a request | When an event occurs |
| Example | "Show me the list of orders" | "New order created" |
What You Need for Webhooks#
-
Receiving URL — address where the service will send notifications
Example:
https://your-bot.com/webhook -
Service configuration — specify which events to send
Example: "Send webhook on new order, payment, cancellation"
-
Webhook handler — code or automation that reacts to the notification
Webhook Use Cases#
In business:
-
Client paid → send receipt and start order fulfillment
-
New form submission on website → create lead in CRM
-
Product out of stock → notify manager
In AI agents:
-
Client messaged the bot → webhook activates the agent
-
Agent collected data → webhook sends it to CRM
-
Lead qualified → webhook notifies manager