채팅 웹후크 - 페이로드 구조 및 인증

채팅 설정
채팅 웹훅 - 페이로드 구조 및 인증

웹훅 페이로드

헤더

  • X-Retry-Count - 문자열
  • X-Freshchat-Payload-Version - 문자열
  • X-Freshchat-Signature - 문자열

이벤트

  • message_create
  • conversation_assignment
  • conversation_resolution
  • conversation_reopen

actor_type - 사용자, 에이전트, 시스템

Message_type - 일반, 비공개

message_create

    {
        "actor": {
            "actor_type": "user",
            "actor_id": "dbec0910-b4d6-4d81-8015-81f560a918de"
        },
        "action": "message_create",
        "action_time": "2018-10-19T10:16:08.013Z",
        "data": {
            "message": {
                "msg_parts": [{
                    "properties": {
                        "text": "사용자 메시지 - 포스트맨에서"
                    },
                    "part_type": "text"
                }],
                "app_id": "11de8840-6ce8-48ac-a418-7c2ae81a1b57",
                "user_id": "dbec0910-b4d6-4d81-8015-81f560a918de",
                "id": "ec0d0db6-55cc-46c7-aaa3-86ad1d9f8e39",
                "channel_id": "5c4d5425-e0e4-47be-a77d-cf81b9d34803",
                "conversation_id": "11de8840-6ce8-48ac-a418-7c2ae81a1b57_dbec0910-b4d6-4d81-8015-81f560a918de_feedback",
                "message_type": "normal",
                "actor_type": "user",
                "created_time": "2018-10-19T10:16:07.973Z"
            }
        }
    }
    

conversation_reopen

    {
        "actor": {
            "actor_type": "agent",
            "actor_id": "41c85e6d-cf41-4275-904d-545849e6f22b"
        },
        "action": "conversation_reopen",
        "action_time": "2018-10-22T15:31:41.858Z",
        "data": {
            "reopen": {
                "reopener": "agent",
                "reopener_id": "41c85e6d-cf41-4275-904d-545849e6f22b",
                "conversation": {
                    "conversation_id": "b6aa207e-b55a-4499-a6ab-f6393c44c68c_1154966d-9840-4b3d-b46e-6a3cf72af093_feedback",
                    "app_id": "b6aa207e-b55a-4499-a6ab-f6393c44c68c",
                    "status": "reopen",
                    "assigned_agent_id": "5cf047ca-e453-4d2e-9fba-46da60708e87"
                }
            }
        }
    }
    

conversation_resolution

    {
        "actor": {
            "actor_type": "agent",
            "actor_id": "41c85e6d-cf41-4275-904d-545849e6f22b"
        },
        "action": "conversation_resolution",
        "action_time": "2018-10-22T15:32:15.438Z",
        "data": {
            "resolve": {
                "resolver": "agent",
                "resolver_id": "41c85e6d-cf41-4275-904d-545849e6f22b",
                "conversation": {
                    "conversation_id": "b6aa207e-b55a-4499-a6ab-f6393c44c68c_1154966d-9840-4b3d-b46e-6a3cf72af093_feedback",
                    "app_id": "b6aa207e-b55a-4499-a6ab-f6393c44c68c",
                    "status": "resolve"
                }
            }
        }
    }
    

conversation_assignment

    {
        "actor": {
            "actor_type": "agent",
            "actor_id": "41c85e6d-cf41-4275-904d-545849e6f22b"
        },
        "action": "conversation_assignment",
        "action_time": "2018-10-22T15:33:10.917Z",
        "data": {
            "assignment": {
                "assignor": "agent",
                "assignor_id": "41c85e6d-cf41-4275-904d-545849e6f22b",
                "to_agent_id": "41b3e2f0-557a-4487-8e7f-bb9afdd23cf6",
                "to_group_id": "68ec7949-d092-4c54-b1d1-1f598f138f45",
                "from_agent_id": "dee4e84a-4aff-4521-8ab2-4e11f48aab4e",
                "from_group_id": "42b3e2f0-557a-5487-8e3f-bw9awqrb23ef",
                "conversation": {
                    "conversation_id": "b6aa207e-b55a-4499-a6ab-f6393c44c68c_1154966d-9840-4b3d-b46e-6a3cf72af093_feedback",
                    "app_id": "b6aa207e-b55a-4499-a6ab-f6393c44c68c",
                    "status": "assign",
                    "assigned_agent_id": "41b3e2f0-557a-4487-8e7f-bb9afdd23cf6"
                }
            }
        }
    }
    

참고: from_agent_id와 to_agent_id가 채워지거나 from_group_id와 to_group_id가 채워집니다.

에이전트의 일반 메시지

    {
        "actor": {
            "actor_type": "agent",
            "actor_id": "ae72b467-a0d2-43a6-a1c7-8cf33d68c7c4"
        },
        "action": "message_create",
        "action_time": "2020-04-06T15:59:44.725Z",
        "data": {
            "message": {
                "message_parts": [
                    {
                        "text": {
                            "content": "안녕하세요!!! 에이전트입니다"
                        }
                    }
                ],
                "app_id": "87f6d88a-3921-4515-8acf-18fe4d2b4149",
                "actor_id": "ae72b467-a0d2-43a6-a1c7-8cf33d68c7c4",
                "id": "35814612-97f6-43bb-9266-cf6cd7cf6a0e",
                "channel_id": "c5456f9e-9131-43aa-b3ec-29535bc7691d",
                "conversation_id": "aecf3cc7-138a-4b40-9723-5bf4d1abb97b",
                "message_type": "normal",
                "actor_type": "agent",
                "created_time": "2020-04-06T15:59:44.709Z",
                "user_id": "5cac723a-13aa-473e-846b-9cdb7d2c41a5",
                "message_source": "web"
            }
        }
    }
    

에이전트의 비공개 메모

    {
        "actor": {
            "actor_type": "agent",
            "actor_id": "999abdc6-e4b1-4944-a246-86f63109df7e"
        },
        "action": "message_create",
        "action_time": "2020-04-07T13:26:27.646Z",
        "data": {
            "message": {
                "message_parts": [
                    {
                        "text": {
                            "content": "이 고객은 이메일을 통해서도 연락하고 있습니다. 양쪽 모두를 팔로우하세요."
                        }
                    }
                ],
                "app_id": "c2bf4b15-38c5-49d1-b0d5-a2b86caac2b7",
                "actor_id": "999abdc6-e4b1-4944-a246-86f63109df7e",
                "id": "2c22af23-41bb-431d-a906-efe33a7294c6",
                "channel_id": "8dfdec10-1c12-48d6-9889-40fba30daefa",
                "conversation_id": "40c15ddf-74e0-41e5-870e-69187d085778",
                "message_type": "private",
                "actor_type": "agent",
                "created_time": "2020-04-07T13:26:27.625Z",
                "user_id": "a6ef2b6b-3fda-497e-bf3e-560b6f9612cd",
                "message_source": "web"
            }
        }
    }
    

사용자의 메시지

    {
        "actor": {
            "actor_type": "user",
            "actor_id": "5cac723a-13aa-473e-846b-9cdb7d2c41a5"
        },
        "action": "message_create",
        "action_time": "2020-04-06T15:59:29.981Z",
        "data": {
            "message": {
                "message_parts": [
                    {
                        "text": {
                            "content": "사용자입니다, 가고 있습니다"
                        }
                    }
                ],
                "app_id": "87f6d88a-3921-4515-8acf-18fe4d2b4149",
                "actor_id": "5cac723a-13aa-473e-846b-9cdb7d2c41a5",
                "id": "ae46748d-daea-44ae-bd41-11eb4797853d",
                "channel_id": "c5456f9e-9131-43aa-b3ec-29535bc7691d",
                "conversation_id": "aecf3cc7-138a-4b40-9723-5bf4d1abb97b",
                "message_type": "normal",
                "actor_type": "user",
                "created_time": "2020-04-06T15:59:29.971Z",
                "message_source": "web"
            }
        }
    }
    

시스템 메시지 (영업시간 외 메시지)

    {
        "actor": {
            "actor_type": "agent",
            "actor_id": "999abdc6-e4b1-4944-a246-86f63109df7e"
        },
        "action": "message_create",
        "action_time": "2020-04-07T13:23:05.351Z",
        "data": {
            "message": {
                "message_parts": [
                    {
                        "text": {
                            "content": "지금은 자리를 비웠습니다"
                        }
                    }
                ],
                "app_id": "c2bf4b15-38c5-49d1-b0d5-a2b86caac2b7",
                "actor_id": "999abdc6-e4b1-4944-a246-86f63109df7e",
                "id": "5ea7ea3d-5bb3-4f78-8e11-15cad506b213",
                "channel_id": "8dfdec10-1c12-48d6-9889-40fba30daefa",
                "conversation_id": "40c15ddf-74e0-41e5-870e-69187d085778",
                "actor_type": "agent",
                "created_time": "2020-04-07T13:23:05.328Z",
                "user_id": "a6ef2b6b-3fda-497e-bf3e-560b6f9612cd",
                "message_source": "system"
            }
        }
    }
    

에이전트에게 대화 할당

    {
        "actor": {
            "actor_type": "agent",
            "actor_id": "999abdc6-e4b1-4944-a246-86f63109df7e"
        },
        "action": "conversation_assignment",
        "action_time": "2020-04-07T13:35:18.622Z",
        "data": {
            "assignment": {
                "assignor": "agent",
                "assignor_id": "999abdc6-e4b1-4944-a246-86f63109df7e",
                "to_agent_id": "999abdc6-e4b1-4944-a246-86f63109df7e",
                "to_group_id": "f8552a49-e96d-400f-bea0-add54b5ba6fc",
                "from_agent_id": "",
                "from_group_id": "f8552a49-e96d-400f-bea0-add54b5ba6fc",
                "conversation": {
                    "conversation_id": "40c15ddf-74e0-41e5-870e-69187d085778",
                    "app_id": "c2bf4b15-38c5-49d1-b0d5-a2b86caac2b7",
                    "status": "assigned",
                    "channel_id": "8dfdec10-1c12-48d6-9889-40fba30daefa",
                    "assigned_agent_id": "999abdc6-e4b1-4944-a246-86f63109df7e",
                    "assigned_group_id": "f8552a49-e96d-400f-bea0-add54b5ba6fc"
                }
            }
        }
    }
    

그룹에 대화 할당

    {
        "actor": {
            "actor_type": "agent",
            "actor_id": "999abdc6-e4b1-4944-a246-86f63109df7e"
        },
        "action": "conversation_assignment",
        "action_time": "2020-04-07T13:35:16.800Z",
        "data": {
            "assignment": {
                "assignor": "agent",
                "assignor_id": "999abdc6-e4b1-4944-a246-86f63109df7e",
                "to_agent_id": "",
                "to_group_id": "f8552a49-e96d-400f-bea0-add54b5ba6fc",
                "from_agent_id": "",
                "from_group_id": "",
                "conversation": {
                    "conversation_id": "40c15ddf-74e0-41e5-870e-69187d085778",
                    "app_id": "c2bf4b15-38c5-49d1-b0d5-a2b86caac2b7",
                    "status": "new",
                    "channel_id": "8dfdec10-1c12-48d6-9889-40fba30daefa",
                    "assigned_group_id": "f8552a49-e96d-400f-bea0-add54b5ba6fc"
                }
            }
        }
    }
    

에이전트가 대화를 해결

    {
        "actor": {
            "actor_type": "agent",
            "actor_id": "ae72b467-a0d2-43a6-a1c7-8cf33d68c7c4"
        },
        "action": "conversation_resolution",
        "action_time": "2020-04-06T15:59:46.407Z",
        "data": {
            "resolve": {
                "resolver": "agent",
                "resolver_id": "ae72b467-a0d2-43a6-a1c7-8cf33d68c7c4",
                "conversation": {
                    "conversation_id": "aecf3cc7-138a-4b40-9723-5bf4d1abb97b",
                    "app_id": "87f6d88a-3921-4515-8acf-18fe4d2b4149",
                    "status": "resolved",
                    "channel_id": "c5456f9e-9131-43aa-b3ec-29535bc7691d"
                }
            }
        }
    }
    

에이전트가 대화를 다시 엶

    {
        "actor": {
            "actor_type": "agent",
            "actor_id": "999abdc6-e4b1-4944-a246-86f63109df7e"
        },
        "action": "conversation_reopen",
        "action_time": "2020-04-07T13:28:49.194Z",
        "data": {
            "reopen": {
                "reopener": "agent",
                "reopener_id": "999abdc6-e4b1-4944-a246-86f63109df7e",
                "conversation": {
                    "conversation_id": "40c15ddf-74e0-41e5-870e-69187d085778",
                    "app_id": "c2bf4b15-38c5-49d1-b0d5-a2b86caac2b7",
                    "status": "reopened",
                    "channel_id": "8dfdec10-1c12-48d6-9889-40fba30daefa"
                }
            }
        }
    }
    

사용자가 대화를 다시 엶

    {
        "actor": {
            "actor_type": "user",
            "actor_id": "5cac723a-13aa-473e-846b-9cdb7d2c41a5"
        },
        "action": "conversation_reopen",
        "action_time": "2020-04-06T15:59:50.314Z",
        "data": {
            "reopen": {
                "reopener": "user",
                "reopener_id": "5cac723a-13aa-473e-846b-9cdb7d2c41a5",
                "conversation": {
                    "conversation_id": "aecf3cc7-138a-4b40-9723-5bf4d1abb97b",
                    "app_id": "87f6d88a-3921-4515-8acf-18fe4d2b4149",
                    "status": "reopened",
                    "channel_id": "c5456f9e-9131-43aa-b3ec-29535bc7691d"
                }
            }
        }
    }
    

인증

모든 웹훅 호출에는 헤더 X-Freshchat-Signature가 포함됩니다. 제공된 공개 키를 사용하여 서명을 확인하고 웹훅 호출을 인증할 수 있습니다.

아래는 Java로 구현된 웹훅 호출을 인증하는 예제 코드 스니펫입니다:

    // 일부 언어에서는 "--BEGIN PRIVATE KEY--" 및 "--END PRIVATE KEY--" 부분을 잘라내야 합니다.

    public static PublicKey loadPublicKey(String publicKeyString) throws Exception {
        byte[] data = Base64.getDecoder().decode(publicKeyString);
        X509EncodedKeySpec spec = new X509EncodedKeySpec(data);
        KeyFactory fact = KeyFactory.getInstance(RSA);
        return fact.generatePublic(spec);
    }

    // 위에서 가져온 publicKey를 이 메서드에 전달하고, 서명 및 평문은 웹훅 페이로드입니다.
    // 페이로드와 서명이 일치하는지 확인합니다.

    public static boolean verify(String plainText, String signature, PublicKey publicKey)
    throws Exception {
        Signature publicSignature = Signature.getInstance("SHA256withRSA");
        publicSignature.initVerify(publicKey);
        publicSignature.update(plainText.getBytes(UTF_8));
        byte[] signatureBytes = Base64.getDecoder().decode(signature);
        return publicSignature.verify(signatureBytes);
    }
    

서명 및 암호화 로직에 대한 자세한 설명은 여기를 참조하세요.

이 문서가 도움이 되었나요?

Freshdesk Omni AI 도우미

채팅 웹후크 - 페이로드 구조 및 인증

AI 어시스턴트 초기화 중...