Skip to main content

SmartReports 웹훅

개요​

SmartReports 및 SmartBatch는 Verifik의 공용 Webhook 및 Smart Monitor 전송 파이프라인(WebhookEvents)을 통해 수명 주기 알림을 전달합니다. 배치 행이 완료되거나, 배치가 종료되거나, 리포트 PDF 렌더링이 완료(또는 실패)되거나, 이메일 전송이 성공(또는 반송)할 때마다 Verifik은 HTTP POST를 통해 지정된 형식의 smart_batch_* 이벤트를 발송합니다.

HTTP 전송 형식 및 보안

모든 전송은 5000 ms(5초) 타임아웃과 함께 다음 JSON 엔벨로프를 담아 대상 URL로 전송되는 HTTP POST 요청입니다.

{
"type": "smart_batch_report_generated",
"object": { }
}
  • type — 정확한 smart_batch_* 이벤트 식별자(smart_batch_report_generated, smart_batch_report_sent 등).
  • object — 이벤트별 페이로드. 민감한 내부 필드(encryptedOcr 및 prompt)는 존재하는 경우 제거됩니다.
  • HMAC 서명 헤더 없음: 현재 smart_batch_* 제품 전송에는 x-verifik-signature 헤더가 포함되지 않습니다. 항상 HTTPS를 사용하고, 구성된 URL에 비밀 경로 토큰이나 쿼리/헤더 시크릿을 적용하여 수신 URL을 보호하며, 돌이킬 수 없는 후속 작업을 트리거하기 전에 GET https://api.verifik.co/v2/smart-reports/{id}(Authorization: Bearer <VERIFIK_JWT> 사용)로 object.reportId / object.batchId 및 object.externalRefId를 검증하세요.

object의 새로운 선택적 필드는 추가적(additive)인 변경으로 간주하세요.


대상 URL 선택 방식​

대상 URL 결정 방식은 이벤트가 SmartReport 작업에서 발생했는지, 아니면 SmartBatch 실행에서 발생했는지에 따라 달라집니다.

대상 URL 결정 순서
  1. 리포트 이벤트(smart_batch_report_generated, smart_batch_report_generation_failed, smart_batch_report_sent, smart_batch_report_delivery_failed):
    1. 리포트별 / 실행별 report.webhookUrl 재정의(POST /v2/smart-reports/run 또는 POST /v2/smart-reports에서 전달).
    2. 배치의 BatchConfiguration에 설정된 batchConfiguration.notification.webhookUrl.
    3. 둘 다 존재하지 않으면 웹훅이 전송되지 않습니다.
  2. 배치 및 행 실행 이벤트(smart_batch_row_completed, smart_batch_batch_completed):
    • 명시적으로 전달된 경우 options.webhookUrl을 사용하거나, batchConfiguration.notification.webhook / **batchConfiguration.notification.webhookUrl**을 사용합니다.
    • 참고: 비동기 FeatureRunner 실행(smart-batch-run-sync)은 **batchConfiguration.notification.webhookUrl**을 사용하여 smart_batch_batch_completed를 발송하며 object에 runId와 creditsSpent를 포함합니다.

webhookUrl이 결정되면 Verifik은 자동으로 활성 클라이언트 Webhook 레코드(Smart Batch — <name>)를 조회하거나 생성하고 BatchConfiguration에 연결하여 Smart Monitor에 전송 내역이 표시되도록 합니다.


전송 보장 및 재시도 일정​

  • 성공 기준: 엔드포인트는 5000 ms 이내에 HTTP 2xx 응답을 반환해야 합니다. 즉시 200 OK를 반환하고 PDF 다운로드나 데이터베이스 쓰기는 백그라운드 워커로 오프로드하세요.
  • 재시도 일정: 2xx가 아닌 응답, 타임아웃 또는 연결 오류 발생 시 Verifik은 가장 가까운 10분 경계로 반올림하여 [60, 60, 120, 120, 360, 720]분(1시간, 1시간, 2시간, 2시간, 6시간, 12시간) 간격의 백오프로 최대 6회 재시도를 예약합니다.
  • 선택적 실패/성공 알림 이메일: 연결된 Webhook 레코드에 notification.email이 구성되어 있고 notification.success 또는 notification.fail이 활성화되어 있으면, Verifik은 1차 시도 시 Mailgun 알림을 보냅니다.

이벤트 수명 주기​

flowchart TD
B["배치 실행 중"] -->|"smart_batch_row_completed\n(행별 모드)"| R["행 완료"]
B -->|"smart_batch_batch_completed"| F["배치 완료"]
R --> F
F -->|"PDF 렌더링 + 점수 계산"| G{"PDF 결과"}
G -->|"성공"| EV1["smart_batch_report_generated"]
G -->|"오류"| EV2["smart_batch_report_generation_failed"]
EV1 -->|"선택적 emailTo / send-email"| E{"이메일 결과"}
E -->|"전송됨"| EV3["smart_batch_report_sent"]
E -->|"실패함"| EV4["smart_batch_report_delivery_failed"]

이벤트 카탈로그​

이벤트 typeobject.event발생 시점주요 object 필드
smart_batch_report_generated"report.generated"리포트 PDF 렌더링 성공 시(POST /v2/smart-reports/run, POST /v2/smart-reports/{id}/generate 또는 비동기 배치 완료 시).reportId, batchId, templateId, status, rowIndex, pdfSize, pdfEngine, generationDurationMs, downloadUrl, htmlUrl, verificationScore, externalRefId, generatedAt
smart_batch_report_generation_failed"report.generation_failed"리포트 PDF 렌더링 실패 시.reportId, batchId, templateId, status, error, externalRefId, failedAt
smart_batch_report_sent"report.sent"리포트 PDF 이메일 전송 성공 시(/run의 emailTo 또는 POST /v2/smart-reports/{id}/send-email).reportId, batchId, templateId, status, recipients, subject, messageId, downloadUrl, htmlUrl, externalRefId, sentAt
smart_batch_report_delivery_failed"report.delivery_failed"리포트 PDF 이메일 전송 실패 또는 반송 시.reportId, batchId, templateId, status, recipients, subject, messageId, error, downloadUrl, htmlUrl, externalRefId, sentAt
smart_batch_batch_completed"batch.completed"SmartBatch의 모든 행이 최종 상태(completed 또는 failed)에 도달한 경우.batchId, runId, status, creditsSpent, stats
smart_batch_row_completed"row.completed"행별 배치 업데이트 흐름에서 최종 행이 아닌 행이 완료 상태(completed, failed 또는 partial)에 도달한 경우.batchId, rowIndex, status, results, errors

이벤트 스키마 및 페이로드 예제​

1. smart_batch_report_generated​

SmartReport PDF 렌더링이 완료되었을 때(status: "generated") 발생합니다.

필드타입설명
object.eventstring항상 "report.generated"입니다.
object.reportIdstringSmartReport ObjectId.
object.batchIdstring연결된 SmartBatch ObjectId.
object.templateIdstringPDF 렌더링에 사용된 SmartReportTemplate ObjectId.
object.statusstring"generated".
object.rowIndexnumber리포트로 렌더링된 0부터 시작하는 배치 행 인덱스.
object.pdfSizenumber렌더링된 PDF 파일 크기(바이트).
object.pdfEnginestring사용된 엔진("puppeteer" 또는 "pdfkit").
object.generationDurationMsnumberPDF 렌더링 소요 시간(밀리초).
object.downloadUrlstringPDF 바이너리를 가져오기 위한 상대 API 경로 /v2/smart-reports/{reportId}/download.
object.htmlUrlstringHTML + Verification Score JSON을 가져오기 위한 상대 API 경로 /v2/smart-reports/{reportId}/html.
object.verificationScoreobject (선택)점수 계산이 활성화된 경우 점수 요약(score, verdict, coverage, profile).
object.externalRefIdstring (선택)/run 또는 리포트 생성 시 전달된 호출자 상관관계 ID.
object.generatedAtstring (ISO 8601)생성이 완료된 타임스탬프.
{
"type": "smart_batch_report_generated",
"object": {
"event": "report.generated",
"reportId": "6740a1b2c3d4e5f678901234",
"batchId": "6740a1b2c3d4e5f678901111",
"templateId": "6740a1b2c3d4e5f678902222",
"status": "generated",
"rowIndex": 0,
"pdfSize": 184320,
"pdfEngine": "puppeteer",
"generationDurationMs": 1420,
"downloadUrl": "/v2/smart-reports/6740a1b2c3d4e5f678901234/download",
"htmlUrl": "/v2/smart-reports/6740a1b2c3d4e5f678901234/html",
"verificationScore": {
"score": 0.9625,
"verdict": "approve",
"coverage": 1,
"profile": "cabify_driver"
},
"externalRefId": "case-12345",
"generatedAt": "2026-11-24T20:15:30.120Z"
}
}

2. smart_batch_report_generation_failed​

PDF 생성이 실패했을 때(status: "failed") 발생합니다.

필드타입설명
object.eventstring항상 "report.generation_failed"입니다.
object.reportIdstringSmartReport ObjectId.
object.batchIdstring연결된 SmartBatch ObjectId.
object.templateIdstringSmartReportTemplate ObjectId.
object.statusstring"failed".
object.errorstring렌더링이 중단된 이유를 설명하는 실패 메시지.
object.externalRefIdstring (선택)리포트에 존재하는 경우 호출자 상관관계 ID.
object.failedAtstring (ISO 8601)실패가 발생한 타임스탬프.
{
"type": "smart_batch_report_generation_failed",
"object": {
"event": "report.generation_failed",
"reportId": "6740a1b2c3d4e5f678901234",
"batchId": "6740a1b2c3d4e5f678901111",
"templateId": "6740a1b2c3d4e5f678902222",
"status": "failed",
"error": "Chromium page timeout while rendering custom font asset",
"externalRefId": "case-12345",
"failedAt": "2026-11-24T20:16:02.450Z"
}
}

3. smart_batch_report_sent​

리포트 이메일 전송이 성공했을 때(status: "sent") 발생합니다.

필드타입설명
object.eventstring항상 "report.sent"입니다.
object.reportIdstringSmartReport ObjectId.
object.batchIdstring연결된 SmartBatch ObjectId.
object.templateIdstringSmartReportTemplate ObjectId.
object.statusstring"sent".
object.recipientsstring[]수신자 이메일 주소 목록.
object.subjectstring발송된 이메일 제목.
object.messageIdstring메일 공급자 메시지 ID.
object.downloadUrlstring상대 API 경로 /v2/smart-reports/{reportId}/download.
object.htmlUrlstring상대 API 경로 /v2/smart-reports/{reportId}/html.
object.externalRefIdstring (선택)리포트에 존재하는 경우 호출자 상관관계 ID.
object.sentAtstring (ISO 8601)이메일 발송이 완료된 타임스탬프.
{
"type": "smart_batch_report_sent",
"object": {
"event": "report.sent",
"reportId": "6740a1b2c3d4e5f678901234",
"batchId": "6740a1b2c3d4e5f678901111",
"templateId": "6740a1b2c3d4e5f678902222",
"status": "sent",
"recipients": ["compliance@yourcompany.com"],
"subject": "SmartReport: Colombia Citizen Comprehensive — 2026-11-24",
"messageId": "<20261124201535.1.abc123@mg.verifik.co>",
"downloadUrl": "/v2/smart-reports/6740a1b2c3d4e5f678901234/download",
"htmlUrl": "/v2/smart-reports/6740a1b2c3d4e5f678901234/html",
"externalRefId": "case-12345",
"sentAt": "2026-11-24T20:15:35.800Z"
}
}

4. smart_batch_report_delivery_failed​

리포트 이메일 전송이 실패했을 때(status: "failed") 발생하며, 전송이 시도조차 되지 않은 경우와 전송 실패를 구분할 수 있습니다.

필드타입설명
object.eventstring항상 "report.delivery_failed"입니다.
object.reportIdstringSmartReport ObjectId.
object.batchIdstring연결된 SmartBatch ObjectId.
object.templateIdstringSmartReportTemplate ObjectId.
object.statusstring"failed".
object.recipientsstring[]수신자 이메일 주소 목록.
object.subjectstring시도된 이메일 제목.
object.messageIdstring (선택)실패 전 발급된 경우 메일 공급자 메시지 ID.
object.errorstring이메일 전송 오류 메시지.
object.downloadUrlstring상대 API 경로 /v2/smart-reports/{reportId}/download.
object.htmlUrlstring상대 API 경로 /v2/smart-reports/{reportId}/html.
object.externalRefIdstring (선택)리포트에 존재하는 경우 호출자 상관관계 ID.
object.sentAtstring (ISO 8601)실패한 전송 시도가 완료된 타임스탬프.
{
"type": "smart_batch_report_delivery_failed",
"object": {
"event": "report.delivery_failed",
"reportId": "6740a1b2c3d4e5f678901234",
"batchId": "6740a1b2c3d4e5f678901111",
"templateId": "6740a1b2c3d4e5f678902222",
"status": "failed",
"recipients": ["invalid@nonexistent-domain.test"],
"subject": "SmartReport: Colombia Citizen Comprehensive — 2026-11-24",
"messageId": null,
"error": "Mailgun 400: invalid recipient domain",
"downloadUrl": "/v2/smart-reports/6740a1b2c3d4e5f678901234/download",
"htmlUrl": "/v2/smart-reports/6740a1b2c3d4e5f678901234/html",
"externalRefId": "case-12345",
"sentAt": "2026-11-24T20:15:36.210Z"
}
}

5. smart_batch_batch_completed​

SmartBatch가 최종 상태("completed" 또는 "failed")로 전환될 때 한 번 발생합니다.

필드타입설명
object.eventstring항상 "batch.completed"입니다.
object.batchIdstringSmartBatch ObjectId.
object.runIdstring (선택)FeatureRunner 실행 ObjectId(비동기 FeatureRunner 동기화 시 포함).
object.statusstring"completed" 또는 "failed".
object.creditsSpentnumber (선택)해당 실행에서 소모된 총 Verifik 크레딧(비동기 FeatureRunner 동기화 시 포함).
object.statsobject집계 수치: { totalRows, completedRows, failedRows, partialRows }.
{
"type": "smart_batch_batch_completed",
"object": {
"event": "batch.completed",
"batchId": "6740a1b2c3d4e5f678901111",
"runId": "6740a1b2c3d4e5f678903333",
"status": "completed",
"creditsSpent": 12,
"stats": {
"totalRows": 2,
"completedRows": 2,
"failedRows": 0,
"partialRows": 0
}
}
}

6. smart_batch_row_completed​

배치의 모든 행이 완료되기 전에 행별 배치 업데이트 흐름에서 개별 행이 완료 상태("completed", "failed" 또는 "partial")에 도달하면 발생합니다.

필드타입설명
object.eventstring항상 "row.completed"입니다.
object.batchIdstringSmartBatch ObjectId.
object.rowIndexnumber배치 내 0부터 시작하는 행 인덱스.
object.statusstring"completed", "failed" 또는 "partial".
object.resultsobject단계 순번(sequence)을 키로 하는 검증 단계 출력 맵.
object.errorsarray실패한 단계에 대해 기록된 { step, message, code } 오류 목록.
{
"type": "smart_batch_row_completed",
"object": {
"event": "row.completed",
"batchId": "6740a1b2c3d4e5f678901111",
"rowIndex": 0,
"status": "completed",
"results": {
"1": {
"fullName": "JUAN CARLOS PEREZ GOMEZ",
"documentNumber": "123456789"
}
},
"errors": []
}
}

웹훅 수신기 예제​

아래 수신기 구현은 5초 이내에 즉시 요청을 확인 응답(200 OK)하고, 반복 전송을 멱등하게 중복 제거하며, GET /v2/smart-reports/{id}로 리포트를 검증한 뒤 Authorization: Bearer <VERIFIK_JWT>를 사용하여 PDF를 다운로드합니다.

import express from 'express';
import fs from 'node:fs/promises';

const app = express();
app.use(express.json({ limit: '2mb' }));

const VERIFIK_API_URL = 'https://api.verifik.co';
const VERIFIK_JWT = process.env.VERIFIK_JWT;

// Replace with Redis or a unique DB index in production
const processedEvents = new Set();

async function verifyAndDownloadPdf(obj) {
// Verify the event directly against Verifik API before trusting payload fields
const metaRes = await fetch(`${VERIFIK_API_URL}/v2/smart-reports/${obj.reportId}`, {
headers: { Authorization: `Bearer ${VERIFIK_JWT}` },
});
if (!metaRes.ok) {
throw new Error(`Report lookup failed: HTTP ${metaRes.status}`);
}
const { data: report } = await metaRes.json();

const pdfRes = await fetch(`${VERIFIK_API_URL}${obj.downloadUrl}`, {
headers: { Authorization: `Bearer ${VERIFIK_JWT}` },
});
if (!pdfRes.ok) {
throw new Error(`PDF download failed: HTTP ${pdfRes.status}`);
}

const pdfBuffer = Buffer.from(await pdfRes.arrayBuffer());
const outPath = `./reports/${report.externalRefId || obj.reportId}.pdf`;
await fs.mkdir('./reports', { recursive: true });
await fs.writeFile(outPath, pdfBuffer);
console.log(`Saved ${outPath} (${pdfBuffer.length} bytes), score:`, report.verificationScoreSummary);
}

app.post('/webhooks/verifik-reports', (req, res) => {
const { type, object: obj } = req.body ?? {};
if (!type || !obj) {
return res.status(400).json({ error: 'Invalid webhook payload' });
}

const idempotencyKey = `${type}:${obj.reportId || obj.batchId}:${obj.rowIndex ?? ''}:${obj.status || ''}`;
if (processedEvents.has(idempotencyKey)) {
return res.status(200).json({ received: true, duplicate: true });
}
processedEvents.add(idempotencyKey);

// Acknowledge within 5 seconds before downloading PDFs or updating downstream systems
res.status(200).json({ received: true });

setImmediate(async () => {
try {
switch (type) {
case 'smart_batch_report_generated':
await verifyAndDownloadPdf(obj);
break;
case 'smart_batch_report_generation_failed':
console.error('Report generation failed:', obj.reportId, obj.externalRefId, obj.error);
break;
case 'smart_batch_report_sent':
console.log('Report emailed:', obj.reportId, obj.recipients, obj.messageId);
break;
case 'smart_batch_report_delivery_failed':
console.error('Email delivery failed:', obj.reportId, obj.recipients, obj.error);
break;
case 'smart_batch_batch_completed':
console.log('Batch settled:', obj.batchId, obj.status, obj.stats, 'credits:', obj.creditsSpent);
break;
case 'smart_batch_row_completed':
console.log('Row completed:', obj.batchId, obj.rowIndex, obj.status);
break;
default:
console.log('Unhandled SmartBatch event:', type);
}
} catch (err) {
console.error('Async webhook handler failed:', err);
}
});
});

app.listen(3000, () => console.log('SmartReports webhook listener on :3000'));

관련 문서​