Если у вас еще нет amoCRM
Создать прямо сейчасДанный пример демонстрирует возможность импорта в amoCRM существующей переписки на стороне интеграции между клиентом и менеджером.
С точки зрения бизнес логики клиент уже существующий, поэтому нам не нужно что бы создавалось неразобранное.
Контакт для клиента создадим для наглядности процесса.
POST https://amojo.amocrm.ru/v2/origin/custom/f90ba33d-c9d9-44da-b76c-c349b0ecbe41/connect
Date: Mon, 03 Oct 2020 15:11:21 +0000
Content-Type: application/json
Content-MD5: a5e8ae04332a6d0aac15f01ad05d40e3
X-Signature: 85d94e7f21bdd3971c2721ca22793e45a96d0c75
{
"account_id": "af9945ff-1490-4cad-807d-945c15d88bec",
"scope_id": "f90ba33d-c9d9-44da-b76c-c349b0ecbe41_af9945ff-1490-4cad-807d-945c15d88bec",
"title": "ChatIntegration",
"hook_api_version": "v2"
}
POST https://amojo.amocrm.ru/v2/origin/custom/f90ba33d-c9d9-44da-b76c-c349b0ecbe41_af9945ff-1490-4cad-807d-945c15d88bec/chats
Date: Mon, 03 Oct 2020 15:17:55 +0000
Content-Type: application/json
Content-MD5: 28623103cc158fde408e6ecd1965d437
X-Signature: 7cc462e28eadbb842a2a49edb469f15f24c56676
{
"conversation_id": "skc-8e3e7640-49af-4448-a2c6-d5a421f7f217",
"user": {
"id": "sk-1376265f-86df-4c49-a0c3-a4816df41af9",
"avatar": "https:/example.com/users/avatar.png",
"name": "Example Client",
"profile": {
"phone": "79151112233",
"email": "example.client@example.com"
},
"profile_link": "https://example.com/profile/example.client"
}
}
POST /api/v4/contacts HTTP/1.1
Host: https://onlinechat.amocrm.ru
Content-Type: application/json
Authorization: Bearer xxxx
[
{
"first_name": "Jack200803",
"last_name": "Tester"
}
]
{
"_links": {
"self": {
"href": "https://onlinechat.amocrm.ru/api/v4/contacts"
}
},
"_embedded": {
"contacts": [
{
"id": 3102959,
"request_id": "0",
"_links": {
"self": {
"href": "https://onlinechat.amocrm.ru/api/v4/contacts/3102959"
}
}
}
]
}
}
POST /api/v4/contacts/chats HTTP/1.1
Host: https://onlinechat.amocrm.ru
[
{
"contact_id": 3102959,
"chat_id":"6cbab3d5-c4c1-46ff-b710-ad59ad10805f"
}
]
{
"_total_items": 1,
"_embedded": {
"chats": [
{
"chat_id": "6cbab3d5-c4c1-46ff-b710-ad59ad10805f",
"contact_id": 3102959,
"id": 26219,
"request_id": "0"
}
]
}
}
Этот шаг необязателен, только для демонстрации возможности получить привязку по чата к контактам. Подробнее можно ознакомится на странице метода
POST /api/v4/contacts/chats HTTP/1.1
Host: https://onlinechat.amocrm.ru
[
{
"contact_id": 3102959,
"chat_id":"6cbab3d5-c4c1-46ff-b710-ad59ad10805f"
}
]
{
"_total_items": 1,
"_embedded": {
"chats": [
{
"chat_id": "6cbab3d5-c4c1-46ff-b710-ad59ad10805f",
"contact_id": 3102959,
"id": 26219,
"request_id": "0"
}
]
}
}
POST https://amojo.amocrm.ru/v2/origin/custom/f90ba33d-c9d9-44da-b76c-c349b0ecbe41_af9945ff-1490-4cad-807d-945c15d88bec
Date: Mon, 03 Oct 2020 16:06:48 +0000
Content-Type: application/json
Content-MD5: 204dc99bcaa899db72954f16de987022
X-Signature: 6201ab8b5154bfa2af847920f1dfeab74b125489
{
"account_id": "af9945ff-1490-4cad-807d-945c15d88bec",
"event_type": "new_message",
"payload": {
"timestamp": 1596470808,
"msgid": "5f283618af2c8",
"conversation_id": "skc-8e3e7640-49af-4448-a2c6-d5a421f7f217",
"sender": {
"id": "sk-1376265f-86df-4c49-a0c3-a4816df41af9",
"avatar": "https:/example.com/users/avatar.png",
"name": "Example Client",
"profile": {
"phone": "79151112233",
"email": "example.client@example.com"
},
"profile_link": "https://example.com/profile/example.client"
},
"message": {
"type": "text",
"text": "Можно ли оплатить заказ при получении ?"
},
"silent": true
}
}
{
"new_message": {
"msgid": "1bf6a765-ec6f-4680-8cd5-6f2d31f78ebc"
}
}
POST https://amojo.amocrm.ru/v2/origin/custom/f90ba33d-c9d9-44da-b76c-c349b0ecbe41_af9945ff-1490-4cad-807d-945c15d88bec
Date: Mon, 03 Oct 2020 16:09:12 +0000
Content-Type: application/json
Content-MD5: 671efccd7cedf63b72823faf9a8037ff
X-Signature: 61a129968e586e8a021c2dfcc6be08e896a4fd77
{
"account_id": "af9945ff-1490-4cad-807d-945c15d88bec",
"event_type": "new_message",
"payload": {
"timestamp": 1596470952,
"msgid": "skm-5f2836a8ca468",
"conversation_id": "skc-8e3e7640-49af-4448-a2c6-d5a421f7f217",
"sender": {
"id": "sk-e1982bb8-bdf1-4fa5-841d-7d5cebd77f7b",
"ref_id": "d8d9f9c4-9611-4794-a136-a253a13e1bb5",
"name": "Менеджер Василий"
},
"receiver": {
"id": "sk-1376265f-86df-4c49-a0c3-a4816df41af9",
"avatar": "https:/example.com/users/avatar.png",
"name": "Example Client",
"profile": {
"phone": "79151112233",
"email": "example.client@example.com"
},
"profile_link": "https://example.com/profile/example.client"
},
"message": {
"type": "text",
"text": "Да, конечно. Вы можете оплатить наличными и картой курьеру при получении."
},
"silent": true
}
}
{
"new_message": {
"msgid": "3985523d-78b3-45b7-aeaf-142405bbf1dc"
}
}
GET https://amojo.amocrm.ru/v2/origin/custom/f90ba33d-c9d9-44da-b76c-c349b0ecbe41_af9945ff-1490-4cad-807d-945c15d88bec/chats/6cbab3d5-c4c1-46ff-b710-ad59ad10805f/history?limit=50&offset=0
Date: Mon, 03 Oct 2020 16:23:14 +0000
Content-Type: application/json
Content-MD5: d41d8cd98f00b204e9800998ecf8427e
X-Signature: 5693447e362dcb3bc77abeb27888ff4a0ca53a1c
{
"messages": [
{
"timestamp": 1596470953,
"sender": {
"id": "d8d9f9c4-9611-4794-a136-a253a13e1bb5",
"name": "Менеджер Василий"
},
"receiver": {
"id": "86a0caef-41ec-49ac-814b-b27da2cea267",
"client_id": "sk-1376265f-86df-4c49-a0c3-a4816df41af9",
"avatar": "https:/example.com/users/avatar.png",
"name": "Example Client",
"phone": "79151112233",
"email": "example.client@example.com"
},
"message": {
"id": "3985523d-78b3-45b7-aeaf-142405bbf1dc",
"client_id": "skm-5f2836a8ca468",
"type": "text",
"text": "Да, конечно. Вы можете оплатить наличными и картой курьеру при получении."
"media": "",
"thumbnail": "",
"file_name": "",
"file_size": 0
}
},
{
"timestamp": 1596470809,
"sender": {
"id": "86a0caef-41ec-49ac-814b-b27da2cea267",
"client_id": "sk-1376265f-86df-4c49-a0c3-a4816df41af9",
"avatar": "https:/example.com/users/avatar.png",
"name": "Example Client",
"phone": "79151112233",
"email": "example.client@example.com"
},
"message": {
"id": "1bf6a765-ec6f-4680-8cd5-6f2d31f78ebc",
"client_id": "5f283618af2c8",
"type": "text",
"text": "Можно ли оплатить заказ при получении ?"
"media": "",
"thumbnail": "",
"file_name": "",
"file_size": 0
}
}
]
}