Modul Team Chat menyediakan DM antar member tim per store, dengan integrasi engine WA untuk realtime.
File kunci
| File | Baris | Peran |
|---|---|---|
app/Http/Controllers/TeamchatController.php | 418 | Inbox pesan internal |
app/Models/TeamchatInbox.php | 30 | Model inbox |
Model TeamchatInbox
Field: message, team_id (sender user_store.id), store_id, partisipan (array), mode ('dm'), reader (array of user_store.id), date.
Relasi: team() → UserStore (belongsTo via team_id).
Controller method utama
| Method | Fungsi |
|---|---|
index() | Render Teamchat/Index |
list() | List member + last message per conversation + unread |
getUnreadNumber() | Total unread + team_list + default device |
add() | Simpan pesan + POST ke engine WA update-teamchat |
listInbox() | Paginate inbox per pasangan + auto-mark-read |
markRead() | Mark satu message read |
store() | Create akun di chat service eksternal |
defaultUserDevice() | Set default device + POST ke engine WA |
Route
| Method | Path | Fungsi |
|---|---|---|
| GET | /teamchat | Halaman utama |
| GET | /api/teamchat/list | List member |
| GET | /api/teamchat/unread | Unread count |
| POST | /api/teamchat/add | Kirim pesan |
| GET | /api/teamchat/list-inbox | Inbox per pair |
| POST | /api/teamchat/set_default | Set default device |
| POST | /api/teamchat/mark_read | Mark read (duplikat — terdaftar 2x) |
Integrasi
| Service | Endpoint | Untuk |
|---|---|---|
Engine WA (url_engine) | POST /update-teamchat | Sinkron pesan ke socket (realtime) |
| Chat service eksternal | http://localhost/chat/api_request | Create akun chat (key 21aOfjTBLDhFx6AoMqH hardcoded) |
Temuan
- API key hardcoded (
:19) —21aOfjTBLDhFx6AoMqHuntuk chat service localhost/chathardcoded — tidak conditional env, akan gagal di productionstore()create akun dengan passwordtime()— lemah & predictable- Route
POST /mark_readduplikat — terdaftar 2x (api.php:663-664) list()orWheretanpa grouping — potensi cross-store leakadd()fire-and-forget — engine WA down → pesan tersimpan tapi tidak realtime