Skip to main content
Version: v1.0.0-beta.0

ChatSystem Broadcast Events

Listening to Message\Created event#

From the frontend channel, you may listen to Message\Created Event on broadcast channel:

  • private-message-created.{$conversation_id} as message
  • private-message-new.user.{$participantId} as message to each conversation participants

Using Laravel Echo as example broadcast client

Echo.private(`message-created.${conversation_id}`)  .listen('message', (event) => {    console.log(event)  })// OREcho.private(`message-new.user.${participant_id}`)  .listen('message', (event) => {    console.log(event)  })
output
{  "message": {      "id": 922,      "conversation_id": 304,      "user_id": 13,      "reply_type": null,      "reply_id": null,      "message": "i am good",      "type": "activity",      "metas": null,      "created_at": "2021-07-23T22:36:20.000000Z",      "updated_at": "2021-07-23T22:36:20.000000Z",      "isSender": true,      "reply": null  }}

Listening to Message\Events event#

From the frontend channel, you may listen to Message\Events Event on broadcast channel private-message-event.user.{$participant_id} as message. This will broadcast to all participant otherwise it will only broadcast to the event maker if the event->type is delete and event->all is not true and event->made_tye is message.

Using Laravel Echo as example broadcast client

Echo.private(`message-event.user.${participant_id}`)  .listen('message', (event) => {    console.log(event)  })
output
{  "event": {        "id": 2042,        "maker_type": "App\\Models\\User",        "maker_id": 13,        "made_type": "App\\Models\\Message",        "made_id": 925,        "type": "read",        "all": false,        "created_at": "2021-07-23T23:00:06.000000Z",        "updated_at": "2021-07-23T23:00:06.000000Z",        "made": {            "id": 925,            "conversation_id": 305,            "user_id": 13,            "reply_type": null,            "reply_id": null,            "message": "i am good",            "type": "user",            "metas": {                "token": "1627080883413"            },            "created_at": "2021-07-23T22:54:44.000000Z",            "updated_at": "2021-07-23T22:54:44.000000Z",            "isSender": true        }    }}