จัดการ LINE Official Account (LINE OA)
ภาพรวม
LINE OA เป็นหน่วยของ tenant ในระบบนี้ ข้อมูลแทบทุกตารางถูก scope ด้วย line_oa_id
โมดูลนี้จึงเป็นแกนกลางของทั้งระบบ ครอบคลุมการสร้าง แก้ไข และลบ OA, การเก็บ channel credential
(channel id, channel secret, access token), การจัดการ webhook URL, การตั้งค่า audience auto-refresh,
การตั้งค่า GA tracking, การตั้งค่าการรับส่งข้อความ ตลอดจนการเชื่อมต่อกับระบบ mbox (live chat) ภายนอก
route ส่วนใหญ่อยู่บน group public คู่กับ JwtLoginAuth เพราะต้องเรียกได้ก่อนที่ token
จะมี lineOaId เนื่องจากหน้าเลือก OA หลัง login จำเป็นต้องดึงรายการ OA มาแสดงก่อน
Business Flow
การเชื่อม OA เข้าระบบ
- ผู้ใช้กรอก channel id, channel secret และ access token แล้วเรียก
POST /api/line-oa/get-oa-infoระบบจะยิงถาม LINE API เพื่อยืนยันว่า credential ใช้งานได้ พร้อมดึงชื่อและรูปของ OA มาแสดง POST /api/line-oaสร้างแถวในline_oaโดยตรวจโควตาmaxChannelsจากกลไก plan limits พร้อม generate ค่าwebhook_idและline_oa_hash- ผู้ใช้คัดลอก webhook URL ที่ระบบ generate ไปตั้งค่าใน LINE Developer Console
โดย
GET /api/line-oa/webhook/:webhookIdใช้ค้นย้อนกลับจาก webhook id ไปยัง OA PUT /api/line-oa/:id/regenerate-webhookออก webhook id ใหม่ในกรณีที่ค่าเดิมรั่วไหล
การใช้งานประจำวัน
GET /api/line-oaแสดงรายการแบบแบ่งหน้า โดยคืนโครงสร้าง{data, total, totalOverAll}GET /api/line-oa/find-all-objectซึ่งไม่มี guard เลย คืนรูปแบบ dropdown, dropdown-group หรือ object ตามค่าที่ระบุใน query?format=PUT /api/line-oa/:idแก้ไขข้อมูล และPUT /api/line-oa/:id/statusเปิด/ปิดการใช้งานDELETE /api/line-oa/:idลบแบบ soft delete ส่วนDELETE /api/line-oa/:id/hardลบข้อมูลจริง ต้องเป็น super admin และส่ง?confirm=กำกับ
การตั้งค่าเฉพาะทาง
- audience auto-refresh ผ่าน
GET /api/line-oa/:id/audience-refresh-settingsและPUT /api/line-oa/:id/audience-refresh-settingsกำหนดว่า cron ที่ refresh audience ของ OA นี้จะทำงานอย่างไร - GA tracking ผ่าน
GET /api/line-oa/:id/ga-tracking-settingsและPUT /api/line-oa/:id/ga-tracking-settingsเก็บ measurement id และ api secret สำหรับส่ง event ไป Google Analytics - message handling ผ่าน
PUT /api/line-oa/:id/message-handlingเลือกว่าข้อความขาเข้า จะให้ auto-response, workflow หรือ mbox ตัวใดเป็นผู้รับ - mbox ผ่าน
POST /api/line-oa/:id/mbox/test-connectionสำหรับทดสอบ baseUrl, apiToken และ accountId รวมถึงGET /api/line-oa/:id/mbox/teamsสำหรับดึงรายชื่อทีมมาผูก
สิทธิ์เข้าถึง OA เฉพาะ super admin
GET /api/line-oa/:id/user-accessและPUT /api/line-oa/:id/user-accessกำหนดว่าผู้ใช้คนใดเข้าถึง OA นี้ได้ โดยเขียนลงuser_line_oaroute คู่นี้อยู่บน groupauthedซึ่งต่างจาก route อื่นที่ port มา เพราะต้องให้ CLS ถูกเติมค่าก่อนที่SuperAdmin()จะอ่าน
ไฟล์และฟังก์ชันหลัก
โค้ดอยู่ที่ internal/modules/lineoa/ ประกอบด้วย controller.go, service.go, dto.go,
responses.go, js.go และ user_access.go
| Method | Route | Handler | Guard / Policy |
|---|---|---|---|
| GET | /api/line-oa | ct.findAll | JwtLogin + readAll line-oa |
| GET | /api/line-oa/find-all-object | ct.findAllObject | ไม่มี guard |
| GET | /api/line-oa/:id | ct.findByID | JwtLogin + read |
| GET | /api/line-oa/webhook/:webhookId | ct.findByWebhookID | JwtLogin + read |
| POST | /api/line-oa | ct.create | JwtLogin + create |
| POST | /api/line-oa/get-oa-info | ct.getOaInfo | — |
| POST | /api/line-oa/validate-login | ct.validateLogin | — |
| PUT | /api/line-oa/:id | ct.update | JwtLogin + update |
| PUT | /api/line-oa/:id/status | ct.updateStatus | JwtLogin + update |
| PUT | /api/line-oa/:id/regenerate-webhook | ct.regenerateWebhook | JwtLogin + update |
| GET / PUT | /api/line-oa/:id/audience-refresh-settings | ct.getAudienceRefreshSettings / ct.updateAudienceRefreshSettings | JwtLogin + read/update |
| GET / PUT | /api/line-oa/:id/ga-tracking-settings | ct.getGaTrackingSettings / ct.updateGaTrackingSettings | JwtLogin + read/update |
| PUT | /api/line-oa/:id/message-handling | ct.updateMessageHandling | JwtLogin + update |
| POST | /api/line-oa/:id/mbox/test-connection | ct.testMboxConnection | JwtLogin + update |
| GET | /api/line-oa/:id/mbox/teams | ct.getMboxTeams | JwtLogin + read |
| DELETE | /api/line-oa/:id | ct.delete | JwtLogin + delete |
| DELETE | /api/line-oa/:id/hard | ct.hardDelete | auth.SuperAdmin() |
| GET / PUT | /api/line-oa/:id/user-access | ct.getUserAccess / ct.updateUserAccess | authed + auth.SuperAdmin() |
จุดเชื่อมต่อกับ Service อื่น
- Permission — policy metadata
PolicyModuleLineOaยังไม่บังคับใช้ สิ่งที่บังคับจริงคือauth.SuperAdmin()บน hard delete และ user-access - ตารางที่เกี่ยวข้อง —
line_oa,line_oa_app,user_line_oa,organization - Redis — cache ข้อมูล OA และ LINE access token
- RabbitMQ — publish ลงคิว
line_sync_follower_userเมื่อสั่ง sync follower - External — LINE Messaging API ผ่าน
internal/externals/lineapiและระบบ mbox ผ่าน HTTP - Cross-module —
planlimitsสำหรับโควตาmaxChannelsและauth.GenerateLineOaHash - แทบทุก feature ในระบบพึ่งพา
lineOaIdที่มาจากโมดูลนี้