# chatMessageReceived

Emitted when a new chat message has been received.

You can use that event to play a chime sound on receiving a message or to display chat messages in a custom way in your integration. Note the **local** boolean flag in the message - it tells if this message was sent by the local user (yourself). For example if you are going to play a chime sound on receiving a message, then you would not want to do it when **local** flag is **true**.

#### Sample payload

```json
{
    "type": "chatMessageReceived",
    "data": {
        "message": {
            "id": "ceb29418-3aa7-4354-9fe6-9875b9b260cf",
            "message": "How are you?",
            "date": "2024-06-11T08:23:16Z",
            //If it was sent by the local user (yourself)
            "local": true,
            "privateGroup": true/false,
            "user": {
               "name": "John Smith",
               "avatarColor": "#4ecdc4",
               "role": "moderator",
               "id": "862f90f8-5a66-4b24-befb-7343a9fd34aa"
            }
        }
        //Contains detailed information if chat panel is opened and which section
        "chatState": {
           "panelOpen": true,
           "activeTab": "public", //public or private
           "privateChatActiveView": {
              //"list" or "personal" depending on if private list is opened or a concrete personal private chat
              "name": "list",
              "data": {
                 //uuid of the user who you are having private chat with
                 "id": "..uuid...",
                 //If the opened chat is the group chat
                 "group": true/undefined
              }
           }
        }    
    }
}
```

#### Sample subscription code

```javascript
sambaFrame.on('chatMessageReceived', (event) => {
  const data = event.data;
  console.log('New chat message is:', data.message);
});
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.digitalsamba.com/reference/sdk/events/chatmessagereceived.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
