Skip to main content

จัดการเพื่อน LINE (LINE User)

ภาพรวม

line_user คือฐานข้อมูลเพื่อน (follower) ของแต่ละ LINE OA และเป็นข้อมูลหลักที่ทุกอย่างวางอยู่บน ไม่ว่าจะเป็น audience, campaign, report หรือ trigger ล้วน query จากตารางนี้ทั้งสิ้น

โมดูลนี้ให้เครื่องมือสำหรับค้นหาเพื่อน ดูรายละเอียดรายบุคคล ดู GA journey ของแต่ละคน sync follower จาก LINE นำเข้าเพื่อนจากไฟล์ CSV รวมถึงแก้ไข custom attribute และ profile รายบุคคล

Business Flow

การค้นหาและดูรายละเอียด

  1. GET /api/line-users/search ค้นหาแบบแบ่งหน้าด้วย FilterGetLineUserDto ซึ่งรองรับการค้นด้วยชื่อ สถานะ follow tag และ custom attribute โดย scope ผลลัพธ์ตาม lineOaId ใน CLS
  2. GET /api/line-users/:id ดูรายละเอียดของเพื่อนคนเดียว ทั้ง profile, attribute และประวัติ
  3. GET /api/line-users/:id/ga-journey?days=30 ดึงเส้นทางการใช้งานที่ track ไว้จาก GA โดยมีค่าเริ่มต้นที่ 30 วัน ใช้ประกอบการวิเคราะห์พฤติกรรมรายบุคคล

การ sync จาก LINE

  1. POST /api/line-users/sync-follower-users สั่งดึงรายชื่อ follower ทั้งหมดจาก LINE โดย publish งานลงคิว RabbitMQ line_sync_follower_user ให้ worker ทำแบบ background
  2. GET /api/line-users/last-synced-follower-users-status ให้ cms-web poll เพื่อตรวจสถานะของรอบ sync ล่าสุด

การนำเข้าจาก CSV

  1. POST /api/line-users/import-all-friends รับเป็น multipart/form-data สำหรับอัปโหลดไฟล์ CSV รายชื่อเพื่อน ไฟล์จะถูกเก็บลง object storage จากนั้นสร้างแถวใน line_user_import และ line_user_import_detail แล้ว publish ลงคิว line_import_csv_user ให้ worker ประมวลผล
  2. ผลการ import ดูย้อนหลังได้ที่ GET /api/report/import-history

การแก้ไขข้อมูลรายบุคคล

  1. PUT /api/line-users/:id/custom-attribute แก้ค่า custom attribute โดย schema ของ attribute มาจากโมดูล attribute master
  2. PUT /api/line-users/:id/profile แก้ profile ที่เก็บไว้ฝั่งระบบ

ไฟล์และฟังก์ชันหลัก

โค้ดอยู่ที่ internal/modules/lineuser/ ประกอบด้วย controller.go, service.go, repository.go, csv.go, gajourney.go, lineoa.go, dto.go และ module.go

route ทั้งหมด register บน group authed.Group("/line-users")

MethodRouteHandlerPolicy (metadata)
GET/api/line-users/searchsvc.searchHandlerreadAll line-user
GET/api/line-users/last-synced-follower-users-statussvc.lastSyncedFollowerUsersStatusHandlerread line-user
GET/api/line-users/:idsvc.getLineUserDetailHandlerread line-user
GET/api/line-users/:id/ga-journeysvc.getGaJourneyHandlerread line-user
POST/api/line-users/sync-follower-userssvc.syncFollowerUsersHandlerupdate line-user
POST/api/line-users/import-all-friendssvc.importLineUsersHandlercreate line-user
PUT/api/line-users/:id/custom-attributesvc.updateCustomAttributeHandlerupdate line-user
PUT/api/line-users/:id/profilesvc.updateProfileHandlerupdate line-user

ฟังก์ชันที่โมดูลอื่นเรียกใช้: service ของ lineuser ถูกโมดูล report เรียกใช้ เพื่อ reuse ตัว build query ชุดเดียวกัน

จุดเชื่อมต่อกับ Service อื่น

  • Permission — policy metadata PolicyModuleLineUser และเนื่องจากอยู่บน group authed จึงต้องมี token ที่มี lineOaId แล้ว
  • ตารางที่เกี่ยวข้องline_user, line_user_import, line_user_import_detail, tracking_line_users, attribute_master, line_oa
  • RabbitMQ — คิว line_sync_follower_user และ line_import_csv_user
  • Storage — อัปโหลดไฟล์ CSV ไปยัง MinIO/S3
  • External — LINE Messaging API สำหรับดึง follower id และ profile รวมถึง Google Analytics สำหรับ GA journey
  • ผู้บริโภคข้อมูลนี้ — การจัดการ audience, การจัดการแคมเปญ, รายงานรายชื่อเพื่อนทั้งหมด, การ mapping ข้อมูลนำเข้า และหน้า dashboard