Skip to main content

ค้นหา LINE OA จาก hash

ภาพรวม

endpoint แรกที่ client-web เรียกในทุกหน้า LIFF ทำหน้าที่แปลง hash ที่อยู่ใน URL รูปแบบ /{hash}/... ให้กลายเป็น lineLiffId เพื่อให้เว็บเรียก liff.init() ได้ พร้อมทั้งส่งข้อมูลสาธารณะของ OA ที่หน้าเว็บต้องใช้กลับไปด้วย ได้แก่ ชื่อ OA, @-id และรูปปก

endpoint นี้ถูกออกแบบมาโดยรู้ตัวว่า ไม่ต้องยืนยันตัวตน จึงคืนเฉพาะฟิลด์ที่ปลอดภัยจริง ๆ ซึ่งทุกฟิลด์เป็นข้อมูลที่ปรากฏบนหน้า LINE สาธารณะของ OA อยู่แล้ว และห้ามเพิ่ม credential ใด ๆ ลงใน response นี้

Business Flow

  1. รับ :hash จาก path แล้วค้นตาราง line_oa ด้วยเงื่อนไข status NOT IN ('delete') AND deleted_date IS NULL สังเกตว่าเงื่อนไขนี้ หลวมกว่า ของ liff.Service ซึ่งบังคับ status='active' กล่าวคือ OA ที่ inactive ยัง resolve hash ได้ แต่จะ verify token ไม่ผ่านในขั้นถัดไป
  2. หากไม่พบแถวจะตอบ 400 พร้อม message APP_007 (parity กับ ErrorResponse.APP_007 ของ source)
  3. ประกอบ response ตามกติกาต่อไปนี้
    • lineLiffId และ formLiffId อ่านจาก jsonb line_login_info โดยค่าว่างหรือ key ที่ไม่มีจะกลายเป็น JSON null (parity กับ value || null)
    • botBasicId คือ @-id สาธารณะ ซึ่งหน้า thank-you ของฟอร์มต้องใช้ประกอบลิงก์ https://line.me/R/ti/p/<id> สำหรับ action oa_chat เมื่อเปิดใน external browser
    • name มาจาก line_oa_name ใช้เป็น document title ของหน้าเว็บ
    • imageUrl ได้จากการ resolve line_oa.cover ซึ่งเป็น storage path ให้กลายเป็น public URL สำหรับใช้เป็น og:image โดย path ที่ว่างจะได้ null แทนที่จะเป็น URL ที่ชี้ไป bucket root, path ที่เป็น absolute URL อยู่แล้วจะถูกส่งผ่านไปตรง ๆ และหากไม่มี config ของ storage จะได้ null โดยไม่ panic

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

รายการค่า
RouteGET /api/line-oa/get-by-hash/:hash
Registerinternal/lineoa/register.goRegister(r, deps)
Handlerinternal/lineoa/handler.go(*Handler).GetByHash
Serviceinternal/lineoa/service.go(*Service).GetByHash, findByHash, resolveCover, emptyToNil
Repositoryinternal/lineoa/repository.goFindByHash, FindActiveByID
Entityinternal/lineoa/entity.goLineOa, LineLoginInfo
ResponseGetByHashResponse ประกอบด้วย lineLiffId, formLiffId, botBasicId, name, imageUrl

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

  • ตาราง line_oa โดยใช้คอลัมน์ line_oa_hash, line_oa_name, bot_basic_id, cover และ jsonb line_login_info
  • internal/storagex สำหรับเรียก GetPublicURL ซึ่งอนุญาตให้เป็น nil ได้ (กรณีนั้นจะไม่ส่งรูปกลับไป)
  • lineoa.Repository ถูกใช้ต่อโดย การตรวจสิทธิ์ LIFF Token ผ่าน FindActiveByID และโดยโดเมน bulletin กับ loyalty ผ่านฟังก์ชัน FindOaByHash ของโดเมนตัวเอง
  • ฝั่ง client-web ที่เกี่ยวข้องคือ feature line-oa-hash-routing ซึ่งดูแลโครง URL /{hash}/... และ OG metadata ระดับ OA