Для получения уведомлений о событиях, происходящих в компании, можно подписаться на вебхуки. Это рекомендуемый способ получения уведомлений.
Для подписки на вебхуки необходимо задать адрес, на который они будут приходить, указать, для какого из подключений вы хотите получать вебхуки и указать список типов событий (event_type, описаны ниже), уведомления о которых вам нужны.
Copy {
"company_id" : 123 ,
"event_type" : "string" ,
"event" : {}
}
Copy {
"connection_id" : 12345 ,
"contact_id" : 12345 ,
"chat_id" : "string" ,
"message" : {}
}
Copy {
"connection_id" : 12345 ,
"contact_id" : 12345 ,
"chat_id" : "string" ,
"message_id" : "string"
}
Copy // Текстовое сообщение
{
"company_id" : 510 ,
"event_type" : "messages.create" ,
"event" : {
"connection_id" : 6466 ,
"contact_id" : 1183 ,
"chat_id" : 452764 ,
"chat" : {
"id" : 452764 ,
"name" : "A" ,
"is_group" : false ,
"avatar_url" : null
} ,
"message" : {
"message_id" : "1a1937d6-bf4c-4269-b5a3-7a8c02c3aba2" ,
"source_message_id" : "false_79000000000@c.us_CD0E4C02A58334A581CDE1976E952A32" ,
"chat_id" : "79000000000@c.us" ,
"direction" : "inbound" ,
"message_type" : "text" ,
"author" : null ,
"created_at" : "2024-02-07T13:28:05+00:00" ,
"delivered_at" : null ,
"read_at" : null ,
"error_at" : null ,
"text" : {
"text" : "6"
}
}
}
}
// Сообщение с файлом (с картинкой)
{
"company_id" : 510 ,
"event_type" : "messages.create" ,
"event" : {
"connection_id" : 6466 ,
"contact_id" : 1183 ,
"chat_id" : 452764 ,
"chat" : {
"id" : 452764 ,
"name" : "A" ,
"is_group" : false ,
"avatar_url" : null
} ,
"message" : {
"message_id" : "0e476e42-014d-499b-9755-c60499884ec6" ,
"source_message_id" : "false_79000000000@c.us_06721C8DAA4798EB67A6F8943E273E87" ,
"chat_id" : "79000000000@c.us" ,
"direction" : "inbound" ,
"message_type" : "image" ,
"author" : null ,
"created_at" : "2024-02-07T13:45:20+00:00" ,
"delivered_at" : null ,
"read_at" : null ,
"error_at" : null ,
"image" : {
"caption" : "Demo" ,
"name" : "3a5891c7-5c8b-4793-9eff-9f77782e0c07.jpg" ,
"size" : 73065 ,
"mime_type" : "image/jpeg" ,
"url" : "https://example.org/image.jpg"
}
}
}
}
// Сообщение с корзиной waba
{
"company_id" : 12345 ,
"event_type" : "messages.create" ,
"event" : {
"connection_id" : 123123 ,
"contact_id" : 1 ,
"chat_id" : 186008 ,
"chat" : {
"id" : 186008 ,
"name" : "Demo" ,
"is_group" : false ,
"avatar_url" : "https://example.org/avatar.jpg"
} ,
"message" : {
"message_id" : "3a830de8-5b5f-480d-a821-49e9b14f9a7e" ,
"source_message_id" : "ABGGeRclMZhPAhBMMpdb-YwGu6DPc-XuT08H" ,
"chat_id" : "79000000000" ,
"direction" : "inbound" ,
"message_type" : "waba_order" ,
"created_at" : "2023-08-25T10:09:53+00:00" ,
"delivered_at" : null ,
"read_at" : null ,
"error_at" : null ,
"waba_order" : {
"currency" : "RUB" ,
"amount" : 6000 ,
"items" : [
{
"name" : "WhatsApp + amoCRM" ,
"price" : 3000 ,
"quantity" : 1 ,
"image_url": "https://radist2.cdn.radist.online/facebook/products/241352448870357/4y7fbkr62n/image.jpg",
"retailer_id" : "4y7fbkr62n"
} ,
{
"name" : "Телегомагазин" ,
"price" : 1500 ,
"quantity" : 2 ,
"image_url": "https://radist2.cdn.radist.online/facebook/products/241352448870357/psgsvcmha7/image.jpg",
"retailer_id" : "psgsvcmha7"
}
] ,
"comment" : "" ,
"catalog_id" : 241352448870357
}
}
}
}
// Сообщение в групповом чате (chat.is_group=true и есть message.author)
{
"company_id" : 510 ,
"event_type" : "messages.create" ,
"event" : {
"connection_id" : 6466 ,
"contact_id" : 1225 ,
"chat_id" : 452784 ,
"chat" : {
"id" : 452784 ,
"name" : "A" ,
"is_group" : true ,
"avatar_url" : null
} ,
"message" : {
"message_id" : "1b92db5f-0214-4641-b524-e5386a964800" ,
"source_message_id" : "false_120361213164524017@g.us_05CFE59C2F17C02ED9EC462A7E561DC3" ,
"chat_id" : "120363233164524017@g.us" ,
"direction" : "inbound" ,
"message_type" : "text" ,
"author" : {
"id" : "e6f74a69-c7a9-4b72-ae64-c2d6473b201a" ,
"name" : "A" ,
"external_id" : "79000000000@c.us" ,
"phone" : "+79000000000"
} ,
"created_at" : "2024-02-07T13:29:23+00:00" ,
"delivered_at" : null ,
"read_at" : null ,
"error_at" : null ,
"text" : {
"text" : "2"
}
}
}
}
// Сообщение доставлено
{
"company_id" : 12345 ,
"event_type" : "messages.delivery.delivered" ,
"event" : {
"connection_id" : 123123 ,
"contact_id" : 217140 ,
"chat_id" : 1036686 ,
"message_id" : "3fe648ad-fbb4-4412-9081-2ee31b02a164"
}
}
// Сообщение прочитано
{
"company_id" : 12345 ,
"event_type" : "messages.delivery.read" ,
"event" : {
"connection_id" : 123123 ,
"contact_id" : 217140 ,
"chat_id" : 1036686 ,
"message_id" : "3fe648ad-fbb4-4412-9081-2ee31b02a164"
}
}