Webhook 및 전달
Webhook 수신
HIOBuy Developer Center → Webhooks 에서 같은 App과 HTTPS URL을 설정합니다. 철회 활성화 전 모든 수신기를 수정하고 아래 4개 이벤트를 구독하세요. 기존 구독은 자동 확대되지 않습니다. 창고 또는 HIOAsk 직접 등록은 필요 없습니다. inquiry.webhook_configured=true는 기본 3개 created/updated/closed 중 하나의 구독 검사이며 철회·이미지 지원, 전체 구독, 전달 성공을 의미하지 않습니다.
| Event | |
|---|---|
ask.message.created | 공개된 상담원 답변으로 data.message를 포함합니다. |
ask.message.recalled | 답변 철회. 생성보다 먼저 도착해도 최종 철회 기록을 저장합니다. |
ask.conversation.updated | 공개 상태/담당 스냅샷 변경입니다. |
ask.conversation.closed | 대화 종료로 평가 가능 여부를 조회합니다. |
한 번 표시되는 서명 비밀은 API Key와 별도로 서버에 보관합니다. 봉투 필드는 id, type, created_at, livemode, app_id, data입니다. 외부 app_id는 HIOBuy App이며 내부 data.conversation.external_app_id는 HIOBuy 관리 값입니다. 포털 테스트는 livemode=false입니다.
{
"id": "evt_example_001",
"type": "ask.message.created",
"created_at": "2026-11-13T13:01:01.000Z",
"livemode": true,
"app_id": "app_example",
"data": {
"conversation": {
"id": "11111111-1111-4111-8111-111111111111",
"external_app_id": "hiobuy:app_example",
"external_conversation_id": "customer-42-1688-673124809943-1",
"external_user_id": "customer-42",
"language": "en",
"context": {
"type": "product",
"product_url": "https://detail.1688.com/offer/673124809943.html",
"product_id": "673124809943",
"product_title": "Knitted shoulder bag"
},
"target_language": "en",
"status": "waiting_customer",
"created_at": "2026-11-13T13:00:00.000Z",
"updated_at": "2026-11-13T13:00:00.000Z"
},
"message": {
"id": "22222222-2222-4222-8222-222222222222",
"conversation_id": "11111111-1111-4111-8111-111111111111",
"client_message_id": "22222222-2222-4222-8222-222222222222",
"sender_type": "staff",
"type": "text",
"content": "We can help you confirm neutral packaging with the supplier.",
"language": "en",
"status": "accepted",
"translation_status": "translated",
"created_at": "2026-11-13T13:01:00.000Z",
"attachments": []
}
}
}전달 검증
HioBuy-Signature: t=<unix_seconds>,v1=<hex_hmac_sha256>를 HMAC-SHA256(secret, timestamp + ”.” + rawBody)로 검증합니다. JSON 파싱 전에 원시 바이트, 일정 시간 비교, ±300초 허용 범위를 적용하고 잘못된 App/서명을 거부하세요. 예시는 크기 제한 Buffer를 받으며 비밀을 로그에 남기지 않습니다.
import { createHmac, timingSafeEqual } from "node:crypto";
export function verifyHioBuyWebhook(rawBody, signature, secret, expectedAppId) {
if (!Buffer.isBuffer(rawBody) || rawBody.length > 256 * 1024) throw new Error("Invalid body");
const match = /^t=([0-9]{1,12}),v1=([a-f0-9]{64})$/.exec(signature ?? "");
if (!match || Math.abs(Date.now() / 1000 - Number(match[1])) > 300) {
throw new Error("Invalid signature timestamp");
}
const expected = createHmac("sha256", secret).update(match[1] + ".").update(rawBody).digest();
const actual = Buffer.from(match[2], "hex");
if (actual.length !== expected.length || !timingSafeEqual(actual, expected)) {
throw new Error("Invalid signature");
}
const event = JSON.parse(rawBody.toString("utf8"));
if (event.app_id !== expectedAppId || typeof event.id !== "string") throw new Error("Invalid event App");
if (!["ask.message.created", "ask.message.recalled", "ask.conversation.updated", "ask.conversation.closed"].includes(event.type)) {
throw new Error("Unsupported event");
}
return event;
}한 번 이상 전달되며 지연/순서 변경이 가능합니다. 이벤트 id로 영구 중복 제거하고 수신/메시지를 트랜잭션에 저장한 뒤 2xx를 반환합니다. 같은 ID에 다른 내용은 거부합니다. 오래된 상태가 종료 대화를 다시 열면 안 됩니다. 저장 실패 시 비-2xx를 반환하고 포털에서 재시도를 확인하세요.
페이지 로드·재연결 및 주기적 백오프 대조 시 첫 페이지와 이미 로드/표시된 과거 페이지도 새로 가져오세요. 철회는 created_at을 바꾸거나 첫 페이지로 이동시키지 않습니다. 커서는 과거 조회 전용이며 since/updated_since 변경 피드는 없습니다. App + 대화 + 메시지별 병합에서 저장된 recalled_at이 오래된 정상 응답보다 우선합니다. 현재 상태·평가를 읽고 과거 이벤트로 닫힌 대화를 열지 마세요. 결과가 불명확하면 초안과 안정 ID를 유지하세요.
App은 Key에서 결정됩니다. X-External-App-Id를 보내거나 HIOAsk에 직접 연결하지 마세요. Key와 서명 비밀은 서버에만 보관하고 브라우저, URL, 로그에 노출하지 마세요. 로그인 고객의 대화 소유권도 검증해야 하며 App 격리만으로 사용자 권한을 대신할 수 없습니다.
오류 및 복구
| HTTP | Code |
|---|---|
| 400 | MISSING_IDEMPOTENCY_KEY / INVALID_CURSOR / VALIDATION_ERROR |
| 401 | INVALID_API_KEY |
| 403 | SUPPLIER_INQUIRY_NOT_ENABLED / INSUFFICIENT_SCOPE / INQUIRY_SANDBOX_UNAVAILABLE |
| 404 | CONVERSATION_NOT_FOUND |
| 409 | IDEMPOTENCY_KEY_REUSED / CONVERSATION_CONFLICT / CLIENT_MESSAGE_ID_CONFLICT |
| 409 | CONVERSATION_CLOSED / PRODUCT_CARD_NOT_FIRST / RATING_ALREADY_SUBMITTED |
| 410 | RATING_WINDOW_CLOSED / HIOASK_V1_RETIRED |
| 429 | RATE_LIMIT_EXCEEDED / DAILY_QUOTA_EXCEEDED |
| 502 | HIOASK_INTEGRATION_REJECTED |
| 503 | HIOASK_BINDING_NOT_READY / HIOASK_UNAVAILABLE |
401은 Key, 403은 활성화/scope/운영 환경, 409는 기존 자원 또는 동일 재시도, 429는 Retry-After를 확인합니다. 502/503은 제한된 백오프, HIOASK_BINDING_NOT_READY는 HIOBuy 설정이 필요합니다. 비활성 미디어 등 상위 권한 거부는 현재 502 HIOASK_INTEGRATION_REJECTED로 변환되며 개발자 Key가 무효라는 뜻은 아닙니다.
/v1/supplier-inquiries 및 하위 경로는 410 HIOASK_V1_RETIRED입니다. questions, 정형 answers, supplier_inquiry.*는 종료되었습니다. /v1/ask/*와 ask.*를 쓰고 호환 연동은 ask.message.recalled도 처리하세요. V1 기록은 자동 변환 없이 유지됩니다.
철회와 순서가 바뀐 이벤트
ask.message.recalled는 같은 ID, recalled_at, 빈 content를 포함하고 미디어는 없습니다. 생성보다 먼저 와도 App + 대화 + 메시지별 최종 철회 기록을 영구 저장하세요. 이벤트 수락과 같은 트랜잭션에서 공개 본문·첨부 표시·공개 캐시를 제거하세요. 중복은 부작용 없이 처리하며 늦은 created, 오래된 API 응답, 새로고침이 내용을 복원하지 못하게 하세요. 원래 created_at 순서를 유지합니다. 이미 읽거나 다운로드한 복사본의 삭제는 보장할 수 없습니다.
모든 수신기와 기록 대조 대응 후 HIOBuy에 활성화를 확인하세요. 다른 연동은 기존 동작을 유지합니다. 공개 철회 API는 없으며 적격 상담원 답변에만 적용되고 고객 메시지나 내부 메모에는 적용되지 않습니다.
{
"id": "evt_example_recall_001",
"type": "ask.message.recalled",
"created_at": "2026-11-13T13:01:15.000Z",
"livemode": true,
"app_id": "app_example",
"data": {
"conversation": {
"id": "11111111-1111-4111-8111-111111111111",
"external_app_id": "hiobuy:app_example",
"external_conversation_id": "customer-42-1688-673124809943-1",
"external_user_id": "customer-42",
"language": "en",
"context": {
"type": "product",
"product_url": "https://detail.1688.com/offer/673124809943.html",
"product_id": "673124809943",
"product_title": "Knitted shoulder bag"
},
"target_language": "en",
"status": "waiting_customer",
"created_at": "2026-11-13T13:00:00.000Z",
"updated_at": "2026-11-13T13:00:00.000Z"
},
"message": {
"id": "22222222-2222-4222-8222-222222222222",
"conversation_id": "11111111-1111-4111-8111-111111111111",
"client_message_id": "22222222-2222-4222-8222-222222222222",
"sender_type": "staff",
"type": "text",
"content": "",
"language": "en",
"status": "accepted",
"translation_status": "translated",
"created_at": "2026-11-13T13:01:00.000Z",
"attachments": [],
"recalled_at": "2026-11-13T13:01:15.000Z"
}
}
}메시지 인용
활성화된 연동은 기존 ask.message.created에서 reply_to_message_id를 받습니다. 복사한 인용문 대신 ID를 저장하고 App + 대화의 메시지로 해석하세요. 대상에 recalled_at이 있으면 생성·연결 답변보다 먼저 도착해도 모든 인용에 철회 표시를 합니다. 답변 자체가 철회되면 그 인용도 숨깁니다. 과거 API 응답·재전송으로 글·미디어를 복원하지 말고 기존 서명·중복 제거를 유지하세요. 해당 이벤트나 기록을 사용하는 동안 수신기를 비호환 버전으로 되돌리지 마세요.
Get Support
Need integration help? Contact Developer Support at support@hiobuy.com · Response within 1–2 business days