Skip to Content

سرویس وب‌هوک

با استفاده از سرویس وب‌هوک، امکان دریافت اعلان‌های لحظه‌ای از رخدادهای مرتبط با حساب باسلام خود را خواهید داشت. ایجاد و مدیریت اشتراک‌های وب‌هوک، مدیریت انواع مختلف رخدادها، نظارت بر لاگ‌ها و وضعیت تحویل وب‌هوک و ایجاد و حذف کلاینت‌ها در وب‌هوک.

فهرست مطالب

متد‌های وب‌هوک

متدتوضیحاتپارامترها
getWebhookServices()دریافت سرویس‌های وب‌هوک-
createWebhookService()ایجاد یک سرویس وب‌هوک جدیدrequest
getWebhooks()دریافت لیست وب‌هوک‌هاserviceId, eventIds
createWebhook()ایجاد یک وب‌هوک جدیدrequest
updateWebhook()به‌روزرسانی یک وب‌هوکwebhookId, request
deleteWebhook()حذف یک وب‌هوکwebhookId
getWebhookEvents()دریافت رویدادهای قابل استفاده-
getWebhookCustomers()دریافت مشتریان متصل به وب‌هوکpage, perPage, webhookId
getWebhookLogs()دریافت لاگ‌های یک وب‌هوکwebhookId
registerWebhook()ثبت مشتری در یک وب‌هوکrequest
unregisterWebhook()لغو ثبت مشتری از یک وب‌هوکrequest
getRegisteredWebhooks()دریافت وب‌هوک‌هایی که مشتری در آن‌ها ثبت شده استpage, perPage, serviceId

مثال‌ها

پیکربندی اولیه

<?php use Basalam\SDK\BasalamClient; use Basalam\SDK\Auth\PersonalToken; $auth = new PersonalToken( token: 'your_access_token', refreshToken: 'your_refresh_token' ); $client = new BasalamClient($auth);

دریافت سرویس‌های وب‌هوک

<?php function getWebhookServicesExample(): array { global $client; $services = $client->getWebhookServices(); return $services; }

ایجاد سرویس وب‌هوک

<?php use Basalam\SDK\Webhook\Models\CreateServiceRequest; function createWebhookServiceExample(): object { global $client; $service = $client->createWebhookService( request: new CreateServiceRequest( title: 'My Webhook Service', description: 'Service for handling order notifications' ) ); return $service; }

دریافت وب‌هوک‌ها

<?php function getWebhooksExample(): array { global $client; $webhooks = $client->getWebhooks( serviceId: 1, eventIds: '1,2,3' ); return $webhooks; }

ایجاد وب‌هوک

<?php use Basalam\SDK\Webhook\Models\CreateWebhookRequest; use Basalam\SDK\Webhook\Enums\RequestMethodType; function createWebhookExample(): object { global $client; $webhook = $client->createWebhook( request: new CreateWebhookRequest( serviceId: 1, eventIds: [1, 2], requestHeaders: 'Content-Type: application/json', requestMethod: RequestMethodType::POST, // Enum: POST, PUT, PATCH url: 'https://your-app.com/webhook', isActive: true ) ); return $webhook; }

به‌روزرسانی وب‌هوک

<?php use Basalam\SDK\Webhook\Models\UpdateWebhookRequest; use Basalam\SDK\Webhook\Enums\RequestMethodType; function updateWebhookExample(): object { global $client; $updatedWebhook = $client->updateWebhook( webhookId: 123, request: new UpdateWebhookRequest( eventIds: [1, 2, 3], requestHeaders: 'Content-Type: application/json', requestMethod: RequestMethodType::POST, url: 'https://your-app.com/webhook', isActive: false ) ); return $updatedWebhook; }

حذف وب‌هوک

<?php function deleteWebhookExample(): object { global $client; $result = $client->deleteWebhook(webhookId: 123); return $result; }

دریافت رخدادهای وب‌هوک

<?php function getWebhookEventsExample(): object { global $client; $events = $client->getWebhookEvents(); return $events; }

نمونه پاسخ

new EventListResource( data: [ new EventResource( id: 1, name: 'CHAT_RECEIVED_MESSAGE', description: 'پیام دریافتی گفتگوی باسلام', sampleData: [ 'id' => 0, 'chat_id' => 0, 'message' => [ 'text' => 'string', 'files' => [ ['id' => 0, 'url' => 'string', 'width' => 0, 'height' => 0] ], 'links' => [], 'entity_id' => 0 ], 'seen_at' => null, 'sender_id' => 0, 'created_at' => 'string', 'updated_at' => 'string', 'message_type' => MessageTypeEnum::TEXT, 'message_source' => null ], scopes: 'customer.chat.read' ) ], resultCount: 9, totalCount: null, totalPage: null, page: 1, perPage: 10 )

برای مطالعه دسترسی موردنیاز برای هر نوع رخداد به این سند مراجعه کنید.

دریافت مشتریان وب‌هوک

<?php function getWebhookCustomersExample(): object { global $client; $customers = $client->getWebhookCustomers( page: 1, perPage: 10, webhookId: 123 ); return $customers; }

دریافت لاگ‌های وب‌هوک

<?php function getWebhookLogsExample(): object { global $client; $logs = $client->getWebhookLogs(webhookId: 123); return $logs; }

عضویت کاربر در وب‌هوک

<?php use Basalam\SDK\Webhook\Models\RegisterClientRequest; function registerWebhookExample(): object { global $client; $result = $client->registerWebhook( request: new RegisterClientRequest( webhookId: 123 ) ); return $result; }

لغو عضویت کاربر از وب‌هوک

<?php use Basalam\SDK\Webhook\Models\UnRegisterClientRequest; function unregisterWebhookExample(): object { global $client; $result = $client->unregisterWebhook( request: new UnRegisterClientRequest( webhookId: 123, customerId: 456 ) ); return $result; }

دریافت وب‌هوک‌های عضوشده

<?php function getRegisteredWebhooksExample(): object { global $client; $webhooks = $client->getRegisteredWebhooks( page: 1, perPage: 10, serviceId: 1 ); return $webhooks; }
Last updated on