Webhooks
Webhooks आपको अपने WhatsApp instances पर events होने पर real-time HTTP callbacks प्राप्त करने की सुविधा देते हैं। API को poll करने के बजाय, Wappfy events को आपके server पर push करता है जैसे ही वे होते हैं।Supported Events
Wappfy 12 webhook event types को support करता है:Message Events
Message Events
| Event | विवरण |
|---|---|
message.received | एक नया inbound message प्राप्त हुआ। |
message.sent | एक outbound message सफलतापूर्वक भेजा गया। |
message.delivered | भेजा गया message प्राप्तकर्ता के device पर deliver हुआ (double check mark)। |
message.read | भेजा गया message प्राप्तकर्ता द्वारा पढ़ा गया (blue check marks)। |
message.failed | एक outbound message भेजने में विफल रहा। |
message.reaction | किसी ने message पर emoji से react किया। |
Instance Events
Instance Events
| Event | विवरण |
|---|---|
instance.connected | एक instance सफलतापूर्वक WhatsApp से connect हो गया। |
instance.disconnected | एक instance ने अपना WhatsApp connection खो दिया। |
instance.qr | Scanning के लिए एक नया QR code उपलब्ध है। |
Group और Contact Events
Group और Contact Events
| Event | विवरण |
|---|---|
group.joined | एक participant group में शामिल हुआ (bot स्वयं सहित)। |
group.left | एक participant ने group छोड़ा। |
contact.created | एक नया contact save या detect किया गया। |
एक Webhook बनाएं
Events प्राप्त करना शुरू करने के लिए webhook endpoint register करें।Configuration Options
| Field | Type | Default | विवरण |
|---|---|---|---|
url | string | आवश्यक | वह HTTPS URL जो webhook POST requests प्राप्त करेगा। |
events | string[] | आवश्यक | Subscribe करने के लिए event types की array। |
instance_id | string | null | Webhook को किसी specific instance तक सीमित करें। यदि null है, तो सभी instances से events प्राप्त होंगे। |
secret | string | null | Payload verification के लिए HMAC signatures generate करने में उपयोग किया जाने वाला secret। |
retry_count | number | 3 | Delivery failure पर retry attempts की संख्या (0-5)। |
timeout_ms | number | 10000 | Milliseconds में request timeout (1000-30000)। |
instance_id field वैकल्पिक है। यदि छोड़ दिया जाए, तो webhook आपके account की सभी instances से events प्राप्त करेगा।Webhooks की सूची
एक Webhook Update करें
किसी मौजूदा webhook का URL, events, या configuration update करें।एक Webhook Delete करें
Delivery Payload Format
जब कोई event होता है, Wappfy आपके webhook URL पर निम्न structure के साथ एक POST request भेजता है:Payload Fields
| Field | विवरण |
|---|---|
id | Unique delivery ID। Deduplication के लिए इसका उपयोग करें। |
event | वह event type जिसने इस delivery को trigger किया। |
instance_id | वह instance जिसने event generate किया। |
timestamp | ISO 8601 timestamp जब event हुआ। |
data | Event-specific payload। सामग्री event type के अनुसार भिन्न होती है। |
HMAC Signature Verification
यदि आपने webhook बनाते समयsecret प्रदान किया है, तो प्रत्येक delivery में X-Wappfy-Signature header शामिल होगा जिसमें request body का HMAC-SHA256 signature होगा।
यह सुनिश्चित करने के लिए हमेशा इस signature को verify करें कि request Wappfy से आई है और उसमें छेड़छाड़ नहीं की गई है।
Verification उदाहरण
Retry Behavior
यदि आपका server configuredtimeout_ms के भीतर 2xx status code से respond नहीं करता, तो Wappfy delivery को retry करेगा।
| Attempt | Delay |
|---|---|
| पहला retry | 10 seconds |
| दूसरा retry | 60 seconds |
| तीसरा retry | 5 minutes |
| चौथा retry | 30 minutes |
| पांचवां retry | 2 hours |
2xx response प्राप्त होने या retry_count समाप्त होने पर retries रुक जाते हैं। Default retry count 3 है।Delivery History देखना
पिछले delivery attempts और उनके results देखने के लिए webhook का delivery log जांचें।Event Payload उदाहरण
message.received
message.received
message.delivered
message.delivered
message.read
message.read
message.reaction
message.reaction
instance.connected
instance.connected
instance.qr
instance.qr
group.joined
group.joined
सर्वोत्तम प्रथाएं
तेजी से respond करें
5 seconds के भीतर
200 status लौटाएं। Timeouts से बचने के लिए event को asynchronously process करें।Deduplicate करें
Retries के कारण duplicate deliveries को detect और skip करने के लिए delivery
id का उपयोग करें।Signatures verify करें
यदि आपने secret configure किया है तो हमेशा
X-Wappfy-Signature header को validate करें।HTTPS उपयोग करें
Webhook URLs को HTTPS उपयोग करना अनिवार्य है। HTTP endpoints reject कर दिए जाएंगे।