# GoTreat API's Definition ## Cơ chế hoạt động - #1: Khách hàng gửi mail tới **admin@gotreat.one** - #2: Mandrill webhook nhận và gửi request POST tới **https://gotreat.one/api/receive** (server mình) - #3: Server mình xử lý auto-reply - #4: Server gọi hàm send trong thư viện của Mailchimp - #5: Mailchimp Transactional tự gửi lại mail cho khách hàng ## Note for demo - Triggers code cứng (k có api CRUD) - Skip phần agruments (name, age, ...) ## Các API Cho Mailchimp gọi ### 1. Nhận email response từ Mandrill webhook (#2) - URL: /api/webhook/email/receive - Method: POST - Body (example): ```json= { "mandrill_events": [ { "event": "inbound", "msg": { "dkim": { "signed": true, "valid": true }, "email": "todo@checkcheckcheck.example.com", "from_email": "example.sender@mandrillapp.com", "html": "<p>This is an example inbound message.</p><img src=\"http://mandrillapp.com/track/open.php?u=999&id=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&tags=_all,_sendexample.sender@mandrillapp.com\" height=\"1\" width=\"1\">\n", "sender": null, "spf": { "detail": "sender SPF authorized", "result": "pass" }, "subject": "This is an example webhook message", "tags": [], "template": null, "text": "This is an example inbound message.\n", "text_flowed": false, "to": [["todo@checkcheckcheck.example.com", null]] }, "ts": 1368214102 } ] } ``` - Sau khi nhận email, tiếp tục xử lí nghiệp vụ ### 2. Thêm template cho hệ thống auto-reply - URL: /api/template - Method: POST - Body (example): ```json= { "data": { "name": "Chẩn đoán COVID" "content": "Chào {{vocative}} {{name}},\nVới thông tin mà {{vocative}} cung cấp, có thể {{vocative}} đã bị COVID.", "triggers": ['h1ji2', 'jeqw1'], "arguments": [ "name", "vocative" ], "threshold": 15, } } ``` - Response: - Người nào code thì người đó mô tả - Yêu cầu: phải có code, message, data là true/false - Note: Ở mức demo, chưa cần biết ai thêm template, cứ request POST là thêm - **Field triggers là list các id** ### 3. Lấy các template - URL: /api/template - Method: GET ```json= { "templates": [ { "id": 2, "name": "Chẩn đoán COVID", "content": "Chào {{name}},\nVới thông tin mà {{name}} cung cấp, có thể {{name}} đã bị COVID.", "threshold": 15, "createdAt": "2022-11-10T08:15:56.000Z", "updatedAt": "2022-11-11T16:39:11.000Z" }, { "id": 3, "name": "Chẩn đoán Viêm Gan", "content": "Chào {{name}},\nVới thông tin mà {{name}} cung cấp, có thể {{name}} đã bị Viêm Gan.", "threshold": 15, "createdAt": "2022-11-10T08:17:27.000Z", "updatedAt": "2022-11-10T08:17:27.000Z" }, ] } ``` ### 4. Lấy chi tiết template - URL: /api/template/{id} - Method: GET ```json= { "template": { "id": 2, "name": "Chẩn đoán COVID", "content": "Chào {{name}},\nVới thông tin mà {{name}} cung cấp, có thể {{name}} đã bị COVID.", "threshold": 15, "createdAt": "2022-11-10T08:15:56.000Z", "updatedAt": "2022-11-11T16:39:11.000Z", "triggers": [ { "trigger_id": 1, "priority": 5 }, { "trigger_id": 4, "priority": 2 } ] } } ``` ### 5. Create template ``` All template details except ID ``` ### 6. Update template ``` All template details ``` ### 7. Lấy các triggers - URL: /api/trigger - Method: GET ```json= { triggers: [ { "id": 0, "keyword": "Sổ mũi", "createdAt": "2022-11-11T14:59:48.000Z", "updatedAt": "2022-11-11T14:59:48.000Z" }, { "id": 1, "keyword": "sốt", "createdAt": "2022-11-10T08:18:29.000Z", "updatedAt": "2022-11-10T08:18:29.000Z" }, ] } ``` ### 8. Create trigger ### 9. Delete trigger