# Webhook

CareSoft cung cấp tính năng hỗ trợ các webhook để nhận thông tin cập nhật người dùng, tổ chức, phiếu ghi, các sự kiện realtime cho cuộc gọi vào, sự kiện kết thúc cuộc gọi trên smartdialer.

Để thực hiện các kịch bản webhook nâng cao như tuỳ chỉnh nội dung đầu ra, gọi API ngoài bằng POST/GET, kiểm tra phản hồi để chọn Outputs, và định dạng dữ liệu trước khi cập nhật CRM, bạn tham khảo thêm tại: Workflow CareSoft: [Gửi Webhook (POST/GET), Test Webhook và Định dạng dữ liệu (Data Ops)](https://doc.caresoft.vn/danh-sach-tinh-nang/workflow/nhom-hanh-dong-gui-webhook-test-webhook-va-dinh-dang-du-lieu-data-ops)

## I. Chuẩn bị thông tin

#### Khách hàng gửi thông tin server webhook cho support hỗ trợ cấu hình bao gồm:

* Callback Url  (*VD: <http://sample.com/api/webHook>*)
* SecretKey (option)
* Các sự kiện hỗ trợ đăng ký: \
  \&#xNAN;**`Người dùng:`**`user`\
  \&#xNAN;**`Tổ chức:`**` ``organization`\
  \&#xNAN;**`Phiếu ghi:`**` ``ticket.voice, ticket.voice_out, ticket.ivr, ticket.voicemail, ticket.voice_campaign, ticket.email, ticket.email_out, ticket.web, ticket.api, ticket.sms_out, ticket.ticket_form, ticket.ticket_sharing, ticket.chat, ticket.facebook, ticket.inbox_facebook, ticket.inbox_facebook_out, ticket.facebook_rating, ticket.facebook_lead_ads, ticket.instagram, ticket.chat_instagram, ticket.inbox_zalo, ticket.inbox_zalo_out, ticket.inbox_zalo_zns, ticket.zalo_lead_form`\
  \&#xNAN;**`Lead:`**` ``lead`\
  \&#xNAN;**`Deal:`**` ``deal`\
  \&#xNAN;**`SmartDialer:`**` ``smart_dialer`\
  \&#xNAN;**`Cuộc gọi vào:`**` ``call_in`

{% hint style="info" %}
**LƯU Ý:** Event sẽ được trả về theo method POST. Request body dạng application/json. Header bao gồm X-Hub-Signature được mã hoá body theo chuẩn HmacSHA1 với secret key đã được cấu hình (Kết quả mã hoá ở dạng uppercase)

Link test mã hoá Signature: \
<https://tools.onecompiler.com/hmac-sha1>

VD:

Request Body: {"ticket\_id":1}\
SecretKey: CS123

Signature: 420A69CE7D3C36559E9828D6361530DF30065D37
{% endhint %}

## II. Các sự kiện webhook

### 1. Sự kiện trên người dùng

{% code title="Sự kiện người dùng" %}

```json
// Sự kiện người dùng được tạo
{
  "object": "user",
  "action": "create",
  "user": {
       "id": 0,
       "username": "",
       "account_id": 0,
       "email": "",
       "email2": "",
       "phone_no": "",
       "phone_no2": "",
       "phone_no3": "",
       "role_id": 3,
       "facebook": "",
       "note": "",
       "gender": 0,
       "organization_id": 0,
       "detail": "",
       "avatar": "",
       "user_info1": "", //facebook name
       "user_info5": "", //address
       "user_info10": "", //instagram name
       "user_info12": "", //instagram link
       "user_info16": "", //zalo name
       "follower_id": 0,
       "updated_at": 0, //Time in millis
       "created_at": 0, //Time in millis
       "addition_fields":
     [
       {
         "id": 0, //id trường động
         "field": "addition_field1", //Mã trường động
         "label": "", //Tên trường động
         "type": 0|1|2|3|4|6|7, //String|Number|DateTime|SingleSelect|MultiSelect|TextArea|Stage
         "value": "", //value in string
         "value_id": 0 //value id
       }
     ]
   }
}

```

{% endcode %}

{% code title="Sự kiện người dùng" %}

```json
// Sự kiện cập nhật người dùng
{
  "object": "user",
  "action": "update",
  "user": {
       "id": 0,
       "username": "",
       "account_id": 0,
       "email": "",
       "email2": "",
       "phone_no": "",
       "phone_no2": "",
       "phone_no3": "",
       "role_id": 3,
       "facebook": "",
       "note": "",
       "gender": 0,
       "organization_id": 0,
       "detail": "",
       "avatar": "",
       "user_info1": "", //facebook name
       "user_info5": "", //address
       "user_info10": "", //instagram name
       "user_info12": "", //instagram link
       "user_info16": "", //zalo name
       "follower_id": 0,
       "updated_at": 0, //Time in millis
       "created_at": 0, //Time in millis
       "addition_fields":
     [
       {
         "id": 0, //id trường động
         "field": "addition_field1", //Mã trường động
         "label": "", //Tên trường động
         "type": 0|1|2|3|4|6|7, //String|Number|DateTime|SingleSelect|MultiSelect|TextArea|Stage
         "value": "", //value in string
         "value_id": 0 //value id
       }
     ]
   }
}
```

{% endcode %}

### 2. Sự kiện trên tổ chức

{% code title="Tổ chức" %}

```json
// Sự kiện tổ chức được tạo
{
  "object": "organization",
  "action": "create",
  "organization": {
    "organization_id": 0,
    "account_id": 0,
    "organization_name": "",
    "organization_domain": "",
    "details": "",
    "note": "",
    "created_at": 0, //Time in millis
    "updated_at": 0, //Time in millis,
    "addition_fields":
     [
       {
         "id": 0, //id trường động
         "field": "addition_field1", //Mã trường động
         "label": "", //Tên trường động
         "type": 0|1|2|3|4|6|7, //String|Number|DateTime|SingleSelect|MultiSelect|TextArea|Stage
         "value": "", //value in string
         "value_id": 0 //value id
       }
     ]
  }
}
```

{% endcode %}

<pre class="language-json" data-title="Tổ chức"><code class="lang-json"><strong>// Sự kiện tổ chức được cập nhật
</strong>{
  "object": "organization",
  "action": "update",
  "organization": {
    "organization_id": 0,
    "account_id": 0,
    "organization_name": "",
    "organization_domain": "",
    "details": "",
    "note": "",
    "created_at": 0, //Time in millis
    "updated_at": 0, //Time in millis,
    "addition_fields":
     [
       {
         "id": 0, //id trường động
         "field": "addition_field1", //Mã trường động
         "label": "", //Tên trường động
         "type": 0|1|2|3|4|6|7, //String|Number|DateTime|SingleSelect|MultiSelect|TextArea|Stage
         "value": "", //value in string
         "value_id": 0 //value id
       }
     ]
  }
}
</code></pre>

### 3. Sự kiện trên phiếu ghi

Khi có sự kiện xảy ra trên phiếu ghi, nguồn của sự kiện này sẽ phân biệt bằng giá trị của thuộc tính **`source`** trong **`ticket_comment.`**&#x20;

Ví dụ để phân biệt sự kiện là cuộc gọi vào hay cuộc gọi ra:&#x20;

Các giá trị source cuộc gọi vào: `Voice`, `IVR`, `ZCC In`, `MissCall`, `VoiceMail`, `Voicemail`

Các giá trị source cho gọi ra: `Voice Out`, `ZCC Out`, `Voice Campaign`

Xem đầy đủ danh sách các giá trị của nguồn tại [Danh sách nguồn](https://docs.caresoft.vn/danh-muc/restful-api-cua-caresoft/phieu-ghi/danh-sach-nguon).

{% code title="Phiếu ghi" %}

```json
// Phiếu ghi được tạo
{
 "object": "ticket",
 "action": "create",
 "ticket": {
   "ticket_id": 0,
   "ticket_no": 0,
   "assignee_id": 0,
   "service_id": 0,
   "ticket_priority": "normal",
   "ticket_source": "web",
   "ticket_source_end_status": 0,
   "ticket_status": "open",
   "ticket_subject": "",
   "created_at": 0, //Time in millis
   "updated_at": 0, //Time in millis,
   "last_change_status_at": 0, //Time in millis
   "campaignId": 0,
   "addition_fields":
     [
       {
         "id": 0, //id trường động
         "field": "addition_field1", //Mã trường động
         "label": "", //Tên trường động
         "type": 0|1|2|3|4|6|7, //String|Number|DateTime|SingleSelect|MultiSelect|TextArea|Stage
         "value": "", //value in string
         "value_id": 0 //value id
       }
     ]
   "ticket_comment": 
     {
       "ticket_id": 0,
       "comment": "",
       "addition_details": "",
       "commentator_id": 0,
       "source": "web",
       "is_public": 0,
       "type": 0,
       "created_at": 0, //Time in millis
       "updated_at": 0, //Time in millis,
     }
  }
}
```

{% endcode %}

{% code title="Phiếu ghi" %}

```json
// Phiếu ghi được cập nhật
{
 "object": "ticket",
 "action": "update",
 "ticket": {
   "ticket_id": 0,
   "ticket_no": 0,
   "assignee_id": 0,
   "service_id": 0,
   "ticket_priority": "normal",
   "ticket_source": "web",
   "ticket_source_end_status": 0,
   "ticket_status": "open",
   "ticket_subject": "",
   "created_at": 0, //Time in millis
   "updated_at": 0, //Time in millis,
   "last_change_status_at": 0, //Time in millis
   "campaignId": 0,
   "addition_fields":
     [
       {
         "id": 0, //id trường động
         "field": "addition_field1", //Mã trường động
         "label": "", //Tên trường động
         "type": 0|1|2|3|4|6|7, //String|Number|DateTime|SingleSelect|MultiSelect|TextArea|Stage
         "value": "", //value in string
         "value_id": 0 //value id
       },
       {
       }
     ]
   "ticket_comment": 
     {
       "ticket_id": 0,
       "comment": "",
       "addition_details": "",
       "commentator_id": 0,
       "source": "web",
       "is_public": 0,
       "type": 0,
       "created_at": 0, //Time in millis
       "updated_at": 0, //Time in millis,
     }
  },
  "call_info":  //Thông tin cuộc gọi nếu có
  {    
    "call_id": "",
    "caller": "", //SĐT khách hàng
    "called": "", //Đầu số
    "status_code": "200",
    "start_time": 000 //Time in millis
    "answer_time": 000 //Time in millis
    "end_time": 000 //Time in millis
  }
}
```

{% endcode %}

```json
// Phiếu bị bị xoá
{
 "object": "ticket",
 "action": "delete",
 "ticket": {
    "ticket_id": 0
  }
}
```

{% code title="Phiếu ghi" %}

```json
// Phiếu ghi bị ghép
{
 "object": "ticket",
 "action": "merge",
  "mergeOption":
  {
    "primaryTicket": 0,
    "secondaryTickets": 1,
    "primaryComment": "",
    "primaryIsPublic": 0,
    "secondaryComment": "",
    "secondaryIsPublic": 0,
    "addCC": 0,
    "addFollow": 0,
    "copyComments": 0,
  }
}
```

{% endcode %}

### 4. Sự kiện trên SmartDialer

{% code title="SmartDialer" %}

```json
// Cuộc gọi kết thúc từ chiến dịch auto call
{
  "object": "smart_dialer",
  "action": "ad_end_call",
  "call_info": {
    "call_id": "",
    "line": "",
    "phone_number": "",
    "call_attempt_index": 0,
    "max_attempt": 1,
    "campaign_id": 0,
    "customer_id": 0,
    "customer_name": "",
    "campaign_data_id": 0,
    "start_time": 0, //Time in millis
    "connect_time": 0, //Time in millis
    "end_time": 0, //Time in millis
    "ring_customer_duration": 0, //seconds
    "call_duration": 0, //seconds
    "status_code": "",
    "customer_input_dtmf": "", //dữ liệu bấm phím ivr nếu có
  }
}
```

{% endcode %}

{% code title="SmartDialer" %}

```json
//Cuộc gọi kết thúc từ chiến dịch predictive call
{
  "object": "smart_dialer",
  "action": "pd_end_call",
  "call_info": {
    "call_id": "",
    "line": "",
    "phone_number": "",
    "call_attempt_index": 0,
    "max_attempt": 1,
    "campaign_id": 0,
    "customer_id": 0,
    "customer_name": "",
    "campaign_data_id": 0,
    "start_time": 0, //Time in millis
    "connect_time": 0, //Time in millis
    "end_time": 0, //Time in millis
    "ring_customer_duration": 0, //seconds
    "call_duration": 0, //seconds
    "agent_user_id": 0,
    "agent_id": 0, 
    "agent_ring_time": 0, //Time in millis
    "agent_connect_time": 0, //Time in millis
    "ring_agent_duration": 0, //seconds
    "status_code": ""
  }
}
```

{% endcode %}

### 5. Sự kiện cập nhật trạng thái cuộc gọi vào

Đăng ký nhận sự kiện này nếu bạn muốn tích hợp chi tiết tất cả các sự kiện xảy ra trong quá trình gọi vào từ lúc cuộc gọi bắt đầu, tới lúc đổ chuông chuyên viên và kết thúc cuộc gọi.

{% code title="Cuộc gọi vào" %}

```json
//1. Sự kiện bắt đầu cuộc gọi
{
  "object": "call_in",
  "action": "call_in_start",
  "call_info": 
  {
    "event_name": "call_in_start",
    "call_id": "",
    "account_id": 0,
    "direction": "inbound",
    "caller": "", //SĐT khách hàng
    "called": "", //Đầu số
    "event_time": 000 //Time in millis
  }
}
```

{% endcode %}

{% code title="Cuộc gọi vào" %}

```json
//2. Sự kiện đổ chuông tới Agent
{
  "object": "call_in",
  "action": "call_in_agent_ring",
  "call_info": 
  {
    "event_name": "call_in_agent_ring",
    "call_id": "",
    "account_id": 0,
    "direction": "inbound",
    "caller": "", //SĐT khách hàng
    "called": "", //Đầu số
    "agent_id": "",
    "event_time": 000 //Time in millis
  }
}
```

{% endcode %}

{% code title="Cuộc gọi vào" %}

```json
//3. Sự kiện trượt qua Agent
{
  "object": "call_in",
  "action": "call_in_agent_miss",
  "call_info": 
  {
    "event_name": "call_in_agent_miss",
    "call_id": "",
    "account_id": 0,
    "direction": "inbound",
    "caller": "", //SĐT khách hàng
    "called": "", //Đầu số
    "agent_id": "",
    "event_time": 000 //Time in millis
  }
}
```

{% endcode %}

{% code title="Cuộc gọi vào" %}

```json
//4. Sự kiện Agent bắt máy
{
  "object": "call_in",
  "action": "call_in_agent_answer",
  "call_info": 
  {
    "event_name": "call_in_agent_answer",
    "call_id": "",
    "account_id": 0,
    "direction": "inbound",
    "caller": "", //SĐT khách hàng
    "called": "", //Đầu số
    "agent_id": "",
    "event_time": 000 //Time in millis
  }
}
```

{% endcode %}

{% code title="Cuộc gọi vào" %}

```json
//5. Sự kiện Agent kết thúc cuộc gọi
{
  "object": "call_in",
  "action": "call_in_agent_end",
  "call_info": 
  {
    "event_name": "call_in_agent_end",
    "call_id": "",
    "account_id": 0,
    "direction": "inbound",
    "caller": "", //SĐT khách hàng
    "called": "", //Đầu số
    "agent_id": "",
    "event_time": 000 //Time in millis
  }
}
```

{% endcode %}

{% code title="Cuộc gọi vào" %}

```json
//6. Sự kiện Khách hàng kết thúc cuộc gọi
{
  "object": "call_in",
  "action": "call_in_customer_end",
  "call_info": 
  {
    "event_name": "call_in_customer_end",
    "call_id": "",
    "account_id": 0,
    "direction": "inbound",
    "caller": "", //SĐT khách hàng
    "called": "", //Đầu số
    "agent_id": "",
    "event_time": 000 //Time in millis
  }
}
```

{% endcode %}

{% code title="Cuộc gọi vào" %}

```json
//7. Sự kiện cuộc gọi kết thúc
{
  "object": "call_in",
  "action": "call_in_end",
  "call_info": 
  {
    "event_name": "call_in_end",
    "call_id": "",
    "account_id": 0,
    "direction": "inbound",
    "caller": "", //SĐT khách hàng
    "called": "", //Đầu số  
    "event_time": 000 //Time in millis
    "call_start_time": 0, //Time in millis
    "call_answer_time": 0, //Time in millis
    "call_end_time": 0, //Time in millis
    "call_end_time": 0, //Time in millis
    "call_duration": 0, //Time in seconds
    "status": "answered|miss", //Trạng thái gặp agent hay không
    "answer_duration": 0, //Time in seconds - status answered
    "record_url": "" //Link file ghi âm - status answered
  }
}
```

{% endcode %}

### 6. Sự kiện trên Lead

#### 6.1. Lead được tạo

```json
// lead created event payload
{
  "account_id": 1,
  "activity_source": "AGENT",
  "action": "create",
  "lead": {
    "lead_id": 414856712,
    "name": "Lead name",
    "last_change_status_at": 1713150362091,
    "lead_status_id": 525,
    "estimated_closed_date": 1713200399000,
    "addition_fields": [
      {
        "field": "addition_field6",
        "id": 4373,
        "label": "Reasons Unqualified",
        "value_id": "",
        "type": 3,
        "value": ""
      }
    ],
    "source": "Web",
    "created_at": 1713150362013,
    "updated_at": 1713150362091,
    "activity": {
      "updated_at": 1713150362124,
      "commentator_id": 63216138,
      "is_public": 0,
      "created_at": 1713150362124,
      "comment": "first comment",
      "ticket_id": 414856712,
      "type": 0
    },
    "requester_id": 63216138,
    "assignee_id": 1
  },
  "object": "lead"
}
```

#### 6.2. Lead được convert từ đối tượng khác

```json
// Lead converted from Ticket payload
{
  "account_id": 1,
  "activity_source": "AGENT",
  "action": "convert",
  "updated_properties": [
    {
      "field": "lead_status_id",
      "value": 525
    }
  ],
  "convert_from_object": "ticket",
  "lead": {
    "lead_id": 414856714,
    "name": "Lead name sample",
    "last_change_status_at": 1713153062000,
    "lead_status_id": 525,    
    "addition_fields": [
      {
        "field": "addition_field9",
        "id": 4376,
        "label": "Custom field abc",
        "type": 2,
        "value": ""
      }
    ],
    "source": "Web",
    "created_at": 1713153062000,
    "updated_at": 1713153076734,
    "activity": {
      "updated_at": 1713153076732,
      "commentator_id": 1,
      "is_public": 0,
      "created_at": 1713153076732,
      "comment": "Chuyển đổi dữ liệu thành dạng Lead",
      "source": "Web",
      "lead_id": 414856714,
      "type": 1
    },
    "requester_id": 1,
    "assignee_id": 1
  },
  "object": "lead"
}
```

6.3. Lead được cập nhật

```json
// lead updated event payload
{
  "account_id": 1,
  "activity_source": "AGENT",
  "action": "update",
  "updated_properties": [
    {
      "field": "addition_field19",
      "value": "value sample"
    }
  ],
  "lead": {
    "lead_id": 414856712,
    "name": "Lead name",
    "last_change_status_at": 1713150362000,
    "lead_status_id": 525,
    "estimated_closed_date": 1713200399000,    
    "addition_fields": [
      {
        "field": "addition_field6",
        "id": 4373,
        "label": "Reasons  Unqualified",
        "value_id": "",
        "type": 3,
        "value": ""
      },
      {
        "field": "addition_field19",
        "id": 4406,
        "label": "Kí tự nhỏ hơn 20",
        "type": 0,
        "value": "value sample"
      }
    ],
    "source": "Web",
    "created_at": 1713150362000,
    "updated_at": 1713152406418,
    "activity": {
      "updated_at": 1713152406442,
      "commentator_id": 1,
      "is_public": 0,
      "created_at": 1713152406442,
      "comment": "update",
      "ticket_id": 414856712,
      "type": 1
    },
    "requester_id": 63216138,
    "assignee_id": 1
  },
  "object": "lead"
}
```

Sự kiện Lead chuyển đổi thành Deal xem tại Sự kiện 7.2. Deal được convert từ đối tượng khác

### 7. Sự kiện trên Deal

#### 7.1. Deal được tạo mới

<pre class="language-json"><code class="lang-json">// Deal created event payload
{
  "deal": {
    "deal_id": 414856715,
    "name": "New sample deal",
    "last_change_status_at": 1713153881216,   
    "probability": 5,
    "addition_fields": [
      {
        "field": "addition_field1",
        "id": 4380,
        "label": "Sample custom field",
        "value_id": "",
        "type": 7,
        "value": ""
      }
    ],
    "source": "Web",
    "created_at": 1713153881152,
    "updated_at": 1713153881216,
    "activity": {
      "updated_at": 1713153881253,
      "commentator_id": 1,
      "is_public": 0,
      "created_at": 1713153881253,
      "comment": "first comment",
<strong>      "deal_id": 414856715,
</strong>      "type": 0
    },
    "pipeline_id": 56,    
    "value": 0,
    "last_change_stage_at": 1713153881216,
    "requester_id": 1,
    "assignee_id": 1,
    "pipeline_stage_id": 376
  },
  "account_id": 1,
  "activity_source": "AGENT",
  "action": "create",
  "object": "deal"
}
</code></pre>

#### 7.2. Deal được chuyển đổi từ đối tượng khác

```json
// Deal converted from object (Lead) event payload
{
  "deal": {
    "deal_id": 414856712,
    "name": "Deal name",
    "last_change_status_at": 1713150362000,
    "estimated_closed_date": 1713200399000,    
    "closed_type": 1,
    "addition_fields": [
      {
        "field": "addition_field1",
        "id": 4380,
        "label": "sample custom field",
        "value_id": "",
        "type": 7,
        "value": ""
      }
    ],
    "source": "Web",
    "created_at": 1713150362000,
    "updated_at": 1713154107391,
    "activity": {
      "updated_at": 1713154107417,
      "commentator_id": 1,
      "is_public": 0,
      "created_at": 1713154107417,
      "comment": "Chuyển đổi Lead thành Deal",
      "deal_id": 414856712,
      "type": 1
    },
    "pipeline_id": 56,
    "value": 0,
    "last_change_stage_at": 1713154107391,
    "requester_id": 63216138,
    "assignee_id": 1,
    "pipeline_stage_id": 376
  },
  "account_id": 1,
  "activity_source": "AGENT",
  "action": "convert",
  "convert_from_object": "lead"
  "updated_properties": [
    {
      "field": "value",
      "value": 0
    },
    {
      "field": "converted_at",
      "value": 1713154107391
    },
    {
      "field": "converted_by",
      "value": 1
    },
    {
      "field": "converted_type",
      "value": 1
    }
  ],
  "agent_submit": {
    "from_object": "lead"
  },
  "object": "deal"
}
```

#### 7.3. Deal được cập nhật

```json
// Deal updated event payload
{
  "deal": {
    "deal_id": 414856712,
    "name": "Deal name",
    "last_change_status_at": 1713150362000,
    "estimated_closed_date": 1713200399000,    
    "closed_type": 1,
    "addition_fields": [
      {
        "field": "addition_field1",
        "id": 4380,
        "label": "Sample custom field",
        "value_id": "",
        "type": 7,
        "value": ""
      },
      {
        "field": "addition_field22",
        "id": 6999,
        "label": "Custom field single select",
        "value_id": "92942",
        "type": 3,
        "value": "123a"
      },
      {
        "field": "addition_field16",
        "id": 4385,
        "label": "invoice_field",
        "type": 0,
        "value": "sample text custom field"
      }
    ],
    "source": "Web",
    "created_at": 1713150362000,
    "updated_at": 1713154405236,
    "activity": {
      "updated_at": 1713154405251,
      "commentator_id": 1,
      "is_public": 0,
      "created_at": 1713154405251,
      "comment": "update deal value",
      "ticket_id": 414856712,
      "type": 1
    },
    "pipeline_id": 56,
    "value": 1000000,
    "last_change_stage_at": 1713154107000,
    "requester_id": 63216138,
    "assignee_id": 1,
    "pipeline_stage_id": 376
  },
  "account_id": 1,
  "activity_source": "AGENT",
  "action": "update",
  "updated_properties": [
    {
      "field": "value",
      "value": 1000000
    },
    {
      "field": "addition_field16",
      "value": "sample text custom field"
    },
    {
      "field": "addition_field22",
      "value": "92942"
    }
  ],
  "object": "deal"
}
```

## III. Mô tả tham số

### 1. Tham số phân loại sự kiện

<table><thead><tr><th width="235.33333333333334">Tham số </th><th>Mô tả</th><th>Giá trị</th></tr></thead><tbody><tr><td>object</td><td>Loại đối tượng</td><td><code>ticket</code>: Phiếu ghi<br><code>user</code>: Khách hàng<br><code>organization</code>: Tổ chức<br><code>smart_dialer</code>: Smartdialer<br><code>call_in</code>: Cuộc gọi vào</td></tr><tr><td>action</td><td>Hành động</td><td><p>Các loại sự kiện xảy ra trên đối tượng: Ví dụ:<br><code>create</code>: Tạo mới</p><p><code>update</code>: Cập nhật </p><p><code>delete</code>: Xóa</p><p><code>ad_end_call</code>: Kết thúc cuộc gọi AutoCall của SmartDialer<br><code>pd_end_call</code>: Kết thúc cuộc gọi PredictiveCall của SmartDialer,<br></p></td></tr></tbody></table>

### 2. Tham số phiếu ghi `ticket`

<table><thead><tr><th width="242.33333333333331">Tham số</th><th width="256">Mô tả</th><th>Giá trị</th></tr></thead><tbody><tr><td>ticket_id</td><td>ID phiếu ghi</td><td></td></tr><tr><td>ticket_no</td><td>Số phiếu ghi</td><td></td></tr><tr><td>requester_id</td><td>ID người yêu cầu</td><td></td></tr><tr><td>assignee_id</td><td>ID người xử lý</td><td></td></tr><tr><td>service_id</td><td>ID dịch vụ</td><td></td></tr><tr><td>ticket_priority</td><td>Độ ưu tiên</td><td>High, Low, Normal</td></tr><tr><td>ticket_source</td><td>Nguồn phiếu ghi</td><td>Các giá trị từ <a data-mention href="restful-api-cua-caresoft/phieu-ghi/danh-sach-nguon">danh-sach-nguon</a></td></tr><tr><td>ticket_source_end_status</td><td>Trạng thái kết thúc phiếu</td><td></td></tr><tr><td>ticket_status</td><td>Trạng thái phiếu ghi</td><td>new, open, pending, closed, solved</td></tr><tr><td>ticket_subject</td><td>Tiêu đề phiếu ghi</td><td></td></tr><tr><td>addition_fields</td><td>Trường động phiếu ghi.  </td><td>Định dạng json array. VD: [{id:1234, field:addition_field1", label: "Tên trường động", value: "Giá trị dạng text"},...]</td></tr><tr><td>created_at</td><td>Thời điểm tạo phiếu ghi</td><td></td></tr><tr><td>updated_at</td><td>Thời điểm cập nhật phiếu ghi</td><td></td></tr></tbody></table>

### 3. Tham số comment phiếu ghi `ticket.ticket_comment`

<table><thead><tr><th width="243">Tham số </th><th>Mô tả</th></tr></thead><tbody><tr><td>ticket_id</td><td>ID phiếu ghi</td></tr><tr><td>commentator_id</td><td>ID người comment</td></tr><tr><td>source</td><td>Nguồn comment</td></tr><tr><td>is_public</td><td>Loại comment:  Công khai (1) hoặc ghi chú nội bộ (0).</td></tr><tr><td>created_at</td><td>Thời điểm comment</td></tr><tr><td>updated_at</td><td>Thời điểm update comment</td></tr></tbody></table>

### 4. Tham số cuộc gọi `call_info`

Đối với cuộc gọi thông thường object cuộc gọi sẽ là  `ticket`

<table><thead><tr><th width="244">Tham số</th><th>Mô tả</th></tr></thead><tbody><tr><td>caller</td><td>SĐT khách hàng</td></tr><tr><td>called</td><td>Hotline tổng đài</td></tr><tr><td>call_id</td><td>ID cuộc gọi</td></tr><tr><td>start_time</td><td>Thời điểm bắt đầu cuộc gọi</td></tr><tr><td>answer_time</td><td>Thời điểm bắt máy</td></tr><tr><td>end_time</td><td>Thời điểm kết thúc</td></tr><tr><td>status_code</td><td>Mã trả về từ đầu số <a href="https://kb.caresoft.vn/support/hc#/?type=article&#x26;id=4">(một số mã thường gặp)</a></td></tr></tbody></table>

### 5. Tham số người dùng `user`

<table><thead><tr><th width="250">Tham số người dùng</th><th>Mô tả</th><th>Giá trị</th></tr></thead><tbody><tr><td>username</td><td>Tên người dùng</td><td></td></tr><tr><td>email</td><td>Email chính</td><td></td></tr><tr><td>email2</td><td>Email phụ</td><td></td></tr><tr><td>phone_no</td><td>SĐT chính</td><td></td></tr><tr><td>phone_no2</td><td>SĐT phụ 2</td><td></td></tr><tr><td>phone_no3</td><td>SĐT phụ 3</td><td></td></tr><tr><td>note</td><td>Ghi chú</td><td></td></tr><tr><td>gender</td><td>Giới tính (0 - Nam, 1 - Nữ, 2 - Khác)</td><td></td></tr><tr><td>organization_id</td><td>ID tổ chức</td><td></td></tr><tr><td>detail</td><td>Mô tả</td><td></td></tr><tr><td>avatar</td><td>Đường dẫn ảnh đại diện</td><td></td></tr><tr><td>user_info5</td><td>Địa chỉ</td><td></td></tr><tr><td>addition_fields</td><td>Trường động người dùng</td><td>Định dạng json array. VD: [{id:1234, field:addition_field1", label: "Tên trường động", value: "Giá trị dạng text"},...]</td></tr><tr><td>follower_id</td><td>ID nhân viên xử lý</td><td></td></tr><tr><td>created_from</td><td>Nguồn tạo KH</td><td></td></tr><tr><td>city_id</td><td>ID tỉnh / thành phố</td><td></td></tr><tr><td>district_id</td><td>ID quận / huyện</td><td></td></tr></tbody></table>

### 6. Tham số tổ chức `organization`

| Tham số tổ chức (organization) | Mô tả               | Ghi chú                                                                                                                   |
| ------------------------------ | ------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| organization\_id               | ID tổ chức          |                                                                                                                           |
| organization\_name             | Tên tổ chức         |                                                                                                                           |
| organization\_domain           | Website             |                                                                                                                           |
| details                        | Chi tiết            |                                                                                                                           |
| note                           | Ghi chú             |                                                                                                                           |
| addition\_fields               | Trường động tổ chức | Định dạng json array. VD: \[{id:1234, field:addition\_field1", label: "Tên trường động", value: "Giá trị dạng text"},...] |

### 7. Tham số cuộc gọi SmartDialer `call_info`

Đối với cuộc gọi smart dialer. Khi object trả về "`smart_dialer`" thì dữ liệu đối tượng `call_info` theo thông tin mô tả dưới đây.&#x20;

<table><thead><tr><th width="251">Tham số </th><th>Mô tả</th></tr></thead><tbody><tr><td>campaign_id</td><td>ID chiến dịch</td></tr><tr><td>customer_id</td><td>ID khách hàng</td></tr><tr><td>customer_name</td><td>Tên khách hàng</td></tr><tr><td>campaign_data_id</td><td>ID Data</td></tr><tr><td>call_id</td><td>Mã cuộc gọi</td></tr><tr><td>line</td><td>Đầu số gọi ra</td></tr><tr><td>phone_number</td><td>SĐT nhận cuộc gọi</td></tr><tr><td>call_attempt_index</td><td>Số lần retry hiện tại</td></tr><tr><td>max_attempt</td><td>Số lần retry tối đa</td></tr><tr><td>start_time</td><td>Thời điểm bắt đầu cuộc gọi (millis)</td></tr><tr><td>connect_time</td><td>Thời điểm bắt máy</td></tr><tr><td>end_time</td><td>Thời điểm kết thúc</td></tr><tr><td>ring_customer_duration</td><td>Thời gian đổ chuông (giây)</td></tr><tr><td>call_duration</td><td>Thời lượng cuộc gọi (giây)</td></tr><tr><td>status_code</td><td>Mã lỗi cuộc gọi (Thành công = 200)</td></tr><tr><td>customer_input_dtmf</td><td>Dữ liệu bấm phím (nếu cuộc gọi là IVR)</td></tr><tr><td>agent_user_id</td><td>ID chuyên viên (Cuộc gọi predictive call - object = pd_end_call)</td></tr><tr><td>agent_id</td><td>IP Phone chuyên viên (Cuộc gọi predictive call)</td></tr><tr><td>agent_ring_time</td><td>Thời điểm đổ chuông tới chuyên viên (Preditive call)</td></tr><tr><td>agent_connect_time</td><td>Thời điểm kết nối tới chuyên viên (Predictive call)</td></tr><tr><td>ring_agent_duration</td><td>Thời lượng chuông tới chuyên viên (Predictive call)</td></tr></tbody></table>

## IV. Mẫu sự kiện

### 1. Ticket Cuộc gọi vào nhỡ

```json
{
   "account_id": 9999,
   "ticket": {
       "ticket_status": "new",
       "ticket_subject": "Cuộc gọi nhỡ từ 0889999999",
       "ticket_priority": "Normal",
       "ticket_source": "Voice",
       "created_at": 1633489861000,
       "ticket_id": 9999,
       "updated_at": 1633489912859,
       "ticket_comment": {
           "updated_at": 1633489912859,
           "commentator_id": 666,
           "is_public": 1,
           "created_at": 1633489861017,
           "comment": "<b>Cuộc gọi vào<\/b><br/>ID cuộc gọi: 20211006101009-HRFZNHMV-9999<br/>Số điện thoại gọi tới: 0889999999<br/>Đầu số gọi: 1019002267<br/>Dịch vụ: Gọi vào 1999999- Gặp NV hỗ trợ<br/>Thời gian bắt đầu: 2021-10-06 10:11:00<br/>Thời gian kết thúc: 2021-10-06 10:11:52<br/>Thời gian gọi: 00:00:51<br/>Cuộc gọi bị nhỡ",
           "source": "MissCall",
           "ticket_id": 9999,
           "type": 0
       },
       "ticket_no": 888,
       "ticket_source_end_status": 1,
       "service_id": 9999,
       "requester_id": 999,
       "assignee_id": -1
   },
   "action": "update",
   "call_info": {
       "answer_time": 0,
       "start_time": 1633489860000,
       "caller": "0889999999",
       "status_code": 0,
       "called": "1999999",
       "end_time": 1633489912861,
       "call_id": "20211006101009-HRFZNHMV-9999"
   },
   "object": "ticket"
}

```

### 2. Cuộc gọi vào IVR (Không chuyển ACD):

```json
{
   "account_id": 9999,
   "ticket": {
       "ticket_status": "new",
       "updated_at": 1633488353675,
       "ticket_comment": {
           "updated_at": "Wed Oct 06 09:45:53 ICT 2021",
           "commentator_id": 123391762,
           "created_at": "Wed Oct 06 09:45:53 ICT 2021",
           "comment": "Cuộc gọi vào IVR <\/br>Số gọi đến: 0889999999<\/br>Đầu số: 19009999<\/br>Id cuộc gọi: 20211006094514-HRFZNHMV-9999<\/br>Thời gian bắt đầu: 2021-10-06 09:45:14<\/br>Thời gian kết thúc: 2021-10-06 09:45:53<\/br>NodeName: Gọi vào<\/br>Dtmf: -2-#",
           "source": "IVR",
           "ticket_id": 259312810,
           "type": 0
       },
       "ticket_subject": "Cuộc gọi vào IVR từ : 0889999999",
       "ticket_no": 45028,
       "service_id": 0,
       "ticket_priority": "Normal",
       "ticket_source": "IVR",
       "created_at": 1633488353675,
       "ticket_id": 259312810,
       "requester_id": 123391762
   },
   "action": "update",
   "call_info": {
       "start_time": 1633488314064,
       "caller": "0889999999",
       "called": "19009999",
       "dtmf": "-2-#",
       "end_time": 1633488353669,
       "node_name": "Gọi vào",
       "call_id": "20211006094514-HRFZNHMV-9999"
   },
   "object": "ticket"
}
```

### 3. Ticket Cuộc gọi ra

```json
{   
   "account_id": 9999,
   "ticket": {
       "ticket_status": "solved",
       "ticket_subject": "Cuộc gọi ra gặp khách hàng tới 0889999999",
       "ticket_priority": "Normal",
       "ticket_source": "Voice Out",
       "created_at": 1633489494000,
       "ticket_id": 9999,
       "updated_at": 1633489530561,
       "ticket_comment": {
           "updated_at": 1633489530561,
           "commentator_id": 4444,
           "is_public": 1,
           "created_at": 1633489494488,
           "comment": "<b>Cuộc gọi ra<\/b><br/>Người gọi ra:  (admin@caresoft.vn)<br/>ID cuộc gọi: 20211006100454-EXGPSDDQ-9999<br/>Số điện thoại gọi tới: 0889999999<br/>Đầu số gọi ra: 1999999<br/>Thời gian bắt đầu: 2021-10-06 10:04:54<br/>Khách hàng trả lời cuộc gọi<br/>Thời gian trả lời: 2021-10-06 10:05:01<br/>Agent kết thúc cuộc gọi<br/>Thời gian kết thúc: 2021-10-06 10:05:30<br/>Thời lượng cuộc gọi: 00:00:29",
           "source": "Voice Out",
           "ticket_id": 9999,
           "type": 0
       },
       "ticket_no": 9999,
       "ticket_source_end_status": 0,
       "service_id": 8888,
       "requester_id": 113245755,
       "assignee_id": 3333
   },
   "action": "update",
   "call_info": {
       "answer_time": 1633489501551,
       "start_time": 1633489494000,
       "caller": "0889999999",
       "status_code": 200,
       "called": "1999999",
       "end_time": 1633489530561,
       "call_id": "20211006100454-EXGPSDDQ-9999"
   },
   "object": "ticket"
}
```

### 4. Tạo mới người dùng

```json
{
   "account_id": 1,
   "action": "create",
   "user": {
       "phone_no": "0889999999",
       "account_id": 1,
       "updated_at": 1633511901679,
       "role_id": 3,
       "created_at": 1633511901679,
       "id": 63203837,
       "username": "Tan Le"
   },
   "object": "user"
}
```

### 5. Cập nhật người dùng

```json
{
   "account_id": 1,
   "action": "update",
   "user": {
       "updated_at": 1633510473715,
       "changes": [
           {
               "field": "addition_field13",
               "value": "x123x"
           }
       ],
       "id": 63203835,
       "username": "Tan9999"
   },
   "object": "user"
}
```

### 6. Tạo mới tổ chức

```json
{
   "account_id": 1,
   "organization": {
       "note": "",
       "account_id": 1,
       "updated_at": 1633590006206,
       "organization_domain": "dev.caresoft.vn",
       "organization_id": 126,
       "created_at": 1633590006206,
       "details": "",
       "organization_name": "Công ty bột giặt"
   },
   "action": "create",
   "object": "organization"
}
```

### 7. Cập nhật tổ chức

```json
{
   "account_id": 1,
   "organization": {
       "updated_at": 1633589854414,
       "organization_id": 10,
       "changes": [
           {
               "field": "organization_name",
               "value": "Công ty cổ phần CareSoft"
           }
       ]
   },
   "action": "update",
   "object": "organization"
}
```

### 8. Tạo mới phiếu ghi

```json
{
  "account_id": 171,
  "ticket": {
    "ticket_comment": {
      "updated_at": 1684384652149,
      "commentator_id": 63215882,
      "is_public": 0,
      "created_at": 1684384652149,
      "comment": "Sample Internal note",
      "ticket_id": 322677,
      "type": 0
    },
    "ticket_no": 5,
    "ticket_status": "new",
    "last_change_status_at": 1684384652133,
    "addition_fields": [
      {
        "field": "addition_field1",
        "id": 6956,
        "label": "Abc",
        "value": "b",
         "value_id":"1242",
        "type":3
      },
      {
        "field": "addition_field2",
        "id": 6957,
        "label": "Phân loại phiếu ghi",
        "value": "Chưa phân loại",
        "value_id":"1222",
        "type":3
        
      },
      {
        "field": "addition_field3",
        "id": 6958,
        "label": "Ghi chú",
        "value": "",
        "type":"0"
      }
    ],
    "requester_id": 63215882,
    "ticket_subject": "Sample Ticket",
    "ticket_priority": "Normal",
    "ticket_source": "Web",
    "created_at": 1684384615500,
    "updated_at": 1684384652133,
    "ticket_id": 322677
  },
  "action": "create",
  "object": "ticket"
}
```

### 9. Cập nhật phiếu ghi

```json
{
  "account_id": 171,
  "ticket": { 
    "ticket_comment": {
      "updated_at": 1684385486529,
      "commentator_id": 63215882,
      "is_public": 0,
      "created_at": 1684385486529,
      "comment": "UpdateTicket",
      "ticket_id": 322677,
      "type": 1
    },
    "addition_field42": "",
    "ticket_no": 5,
    "ticket_status": "new",
    "last_change_status_at": 1684384652000,
    "addition_fields": [
      {
        "field": "addition_field1",
        "id": 6956,
        "label": "Abc",
        "value": "b",
         "value_id":"1242",
        "type":3
      },
      {
        "field": "addition_field2",
        "id": 6957,
        "label": "Phân loại phiếu ghi",
        "value": "Chưa phân loại",
        "value_id":"1222",
        "type":3
        
      },
      {
        "field": "addition_field3",
        "id": 6958,
        "label": "Ghi chú",
        "value": "",
        "type":"0"
      }
    ],
    "requester_id": 63215882,
    "ticket_subject": "Sample Ticket",
    "ticket_priority": "Normal",
    "ticket_source": "Web",
    "created_at": 1684384616000,
    "updated_at": 1684385486519,
    "assignee_id": 63215882,
    "ticket_id": 322677
  },
  "action": "update",
  "object": "ticket"
}
```

### 10.  Xóa phiếu ghi

```json
{
   "account_id": 1,
   "ticket": {"ticket_id":316702},
   "action": "delete",
   "object": "ticket"
}
```

### 11.  Ghép phiếu ghi

```json
{
   "account_id": 1,
   "mergeOption": {"copyComments":0,"secondaryTickets":[316708],"addCC":1,"primaryComment":"Phiếu ghi #220760 đã được đóng và hợp nhất vào phiếu ghi này","addFollow":1,"primaryIsPublic":0,"primaryTicket":316707,"secondaryComment":"Phiếu ghi này đã được đóng và hợp nhất vào phiếu ghi #220759","secondaryIsPublic":0},
   "action": "merge",
   "object": "ticket"
}
```

### 12. Phiếu ghi được gán

```json
{
    "object": "ticket",
    "action": "acd_assign",
    "data": {
        "assignee_id": 0,
        "ticket_id":316702,
        "assign_at": 1704961720473
    }
}
```
