AppFolio 웹훅 이벤트 | sed 's/\b(.)/\u\1/g'
개요
AppFolio Stack은 임대, 결제, 유지보수 이벤트에 대한 웹훅을 지원합니다.
웹훅 핸들러
import express from "express";
import crypto from "crypto";
const router = express.Router();
router.post("/webhooks/appfolio", express.raw({ type: "application/json" }), (req, res) => {
const signature = req.headers["x-appfolio-signature"] as string;
const expected = crypto.createHmac("sha256", process.env.APPFOLIO_WEBHOOK_SECRET!)
.update(req.body).digest("hex");
if (!crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected))) {
return res.status(401).json({ error: "Invalid signature" });
}
const event = JSON.parse(req.body.toString());
console.log(`Event: ${event.type} — ${JSON.stringify(event.data)}`);
res.status(200).json({ received: true });
});
이벤트 유형
| 이벤트 | 트리거 | 사용 사례 |
|---|---|---|
lease.created | 새 임대 계약 체결 | CRM 업데이트 |
lease.expired | 임대 종료 | 갱신 워크플로우 트리거 |
payment.received | 임대료 납부 | 회계 업데이트 |
maintenance.created | 작업 요청 등록 | 공급업체 파견 |