پیکربندی Webhook
ثبت آدرس Webhook و ساختار رویدادهای ارسالی.
آدرس Webhook را از پنل کاربری (بخش «Webhookها») ثبت کنید. با وقوع هر رویداد،
یک درخواست POST با بدنهٔ JSON به آدرس شما ارسال میشود:
{
"event": "sms.delivered",
"message_id": "msg_9f2c1a",
"recipient": "09123456789",
"occurred_at": "2026-03-21T09:31:04+03:30"
}
رویدادهای موجود: sms.sent، sms.delivered، sms.failed، sms.inbound،
payment.completed.
بررسی صحت امضا
هر درخواست دارای هدر X-Irnoti-Signature است که مقدار
HMAC-SHA256(body, webhook_secret) را در خود دارد. پیش از پردازش، این امضا را
بررسی کنید.
نمونه کد
PHP
<?php
$payload = file_get_contents('php://input');
$signature = $_SERVER['HTTP_X_IRNOTI_SIGNATURE'] ?? '';
$expected = hash_hmac('sha256', $payload, getenv('IRNOTI_WEBHOOK_SECRET'));
if (! hash_equals($expected, $signature)) {
http_response_code(401);
exit;
}
$event = json_decode($payload, true);
// ... پردازش رویداد
http_response_code(200);
Laravel
public function handle(Request $request)
{
$expected = hash_hmac(
'sha256',
$request->getContent(),
config('services.irnoti.webhook_secret'),
);
abort_unless(
hash_equals($expected, $request->header('X-Irnoti-Signature', '')),
401,
);
match ($request->input('event')) {
'sms.delivered' => /* ... */ null,
'sms.failed' => /* ... */ null,
default => null,
};
return response()->noContent();
}