> ## Documentation Index
> Fetch the complete documentation index at: https://docs.journeybee.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Message Events

> Triggered when messages are created, updated, or deleted in partnership rooms

## Event Types

* **`message_created`** - New message in partnership room
* **`message_updated`** - Message content updated
* **`message_deleted`** - Message removed

## Webhook Details

**Event IDs**: `message_created`, `message_updated`, `message_deleted`\
**Content-Type**: `application/json`\
**Method**: `POST`

## Authentication

All webhooks include JWT authentication in the Authorization header:

<CodeGroup>
  ```javascript Node.js theme={null}
  const jwt = require('jsonwebtoken');

  app.post('/webhook', (req, res) => {
    const token = req.headers.authorization?.split('Bearer ')[1];
    
    try {
      const decoded = jwt.verify(token, process.env.INTEGRATION_UUID);
      console.log('Event:', decoded.event_id); // 'message_created'
      console.log('Company:', decoded.company_uuid);
      
      const { message, configuration } = req.body;
      // Process message data...
      
      res.status(200).send('OK');
    } catch (error) {
      res.status(401).send('Invalid token');
    }
  });
  ```

  ```python Python theme={null}
  import jwt
  from flask import Flask, request

  app = Flask(__name__)

  @app.route('/webhook', methods=['POST'])
  def webhook():
      token = request.headers.get('Authorization', '').replace('Bearer ', '')
      
      try:
          decoded = jwt.decode(token, os.getenv('INTEGRATION_UUID'), algorithms=['HS256'])
          print(f"Event: {decoded['event_id']}")  # 'message_created'
          print(f"Company: {decoded['company_uuid']}")
          
          payload = request.json
          message = payload['message']
          # Process message data...
          
          return 'OK', 200
      except jwt.InvalidTokenError:
          return 'Invalid token', 401
  ```
</CodeGroup>

## JWT Token Payload

<ResponseField name="company_uuid" type="string">
  UUID of the company where the message was created
</ResponseField>

<ResponseField name="user_uuid" type="string">
  UUID of the user who created the message
</ResponseField>

<ResponseField name="event_id" type="string">
  Always `message_created` for this event
</ResponseField>

<ResponseField name="api_key" type="string">
  Your integration's API key
</ResponseField>

## Webhook Payload Schema

<ResponseField name="message" type="object">
  The created message object

  <Expandable title="message object">
    <ResponseField name="uuid" type="string">
      Unique identifier for the message
    </ResponseField>

    <ResponseField name="created_at" type="number">
      Unix timestamp when message was created
    </ResponseField>

    <ResponseField name="updated_at" type="number">
      Unix timestamp when message was last updated
    </ResponseField>

    <ResponseField name="content" type="string">
      Message content text
    </ResponseField>

    <ResponseField name="replied_to_message_uuid" type="string">
      UUID of the message being replied to (null if not a reply)
    </ResponseField>

    <ResponseField name="room_uuid" type="string">
      UUID of the message room
    </ResponseField>

    <ResponseField name="created_by_user_uuid" type="string">
      UUID of the user who created the message
    </ResponseField>

    <ResponseField name="created_by_user_email" type="string">
      Email of the user who created the message
    </ResponseField>

    <ResponseField name="created_by_user_first_name" type="string">
      First name of the user who created the message
    </ResponseField>

    <ResponseField name="created_by_user_last_name" type="string">
      Last name of the user who created the message
    </ResponseField>

    <ResponseField name="created_by_user_profile_image_url" type="string">
      Profile image URL of the user who created the message
    </ResponseField>

    <ResponseField name="created_by_user_company_uuid" type="string">
      UUID of the company the message author belongs to
    </ResponseField>

    <ResponseField name="created_by_user_company_name" type="string">
      Name of the company the message author belongs to
    </ResponseField>

    <ResponseField name="attachments" type="array">
      Array of file attachments

      <Expandable title="attachments items">
        <ResponseField name="uuid" type="string">
          Attachment UUID
        </ResponseField>

        <ResponseField name="file_name" type="string">
          Original filename
        </ResponseField>

        <ResponseField name="file_size" type="number">
          File size in bytes
        </ResponseField>

        <ResponseField name="mime_type" type="string">
          MIME type of the file
        </ResponseField>

        <ResponseField name="file_url" type="string">
          URL to access the file
        </ResponseField>
      </Expandable>
    </ResponseField>

    <ResponseField name="partnership_uuid" type="string">
      UUID of the partnership associated with this message room
    </ResponseField>

    <ResponseField name="partner_type" type="string">
      Type of partnership: `referral` or `reseller`
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="configuration" type="array">
  Integration configuration settings for field mapping

  <Expandable title="configuration items">
    <ResponseField name="id" type="string">
      Configuration section ID
    </ResponseField>

    <ResponseField name="selected" type="array">
      Selected configuration options

      <Expandable title="selected items">
        <ResponseField name="id" type="string">
          Option ID
        </ResponseField>

        <ResponseField name="value" type="string">
          Selected value
        </ResponseField>
      </Expandable>
    </ResponseField>
  </Expandable>
</ResponseField>

## Example Payload

```json theme={null}
{
  "message": {
    "uuid": "message_12345678-1234-5678-9012-123456789abc",
    "created_at": 1716214515227,
    "updated_at": 1716214515227,
    "content": "Hello! I wanted to follow up on our partnership discussion from last week.",
    "replied_to_message_uuid": null,
    "room_uuid": "room_87654321-4321-8765-2109-876543210987",
    "created_by_user_uuid": "user_11111111-1111-1111-1111-111111111111",
    "created_by_user_email": "john@partner.com",
    "created_by_user_first_name": "John",
    "created_by_user_last_name": "Smith",
    "created_by_user_profile_image_url": "https://cdn.journeybee.io/profile/john.jpg",
    "created_by_user_company_uuid": "company_22222222-2222-2222-2222-222222222222",
    "created_by_user_company_name": "Partner Company",
    "attachments": [
      {
        "uuid": "asset_33333333-3333-3333-3333-333333333333",
        "file_name": "partnership-proposal.pdf",
        "file_size": 1048576,
        "mime_type": "application/pdf",
        "file_url": "https://cdn.journeybee.io/files/partnership-proposal.pdf"
      }
    ],
    "partnership_uuid": "partnership_44444444-4444-4444-4444-444444444444",
    "partner_type": "referral"
  },
  "configuration": []
}
```

## Notes

* Webhook is sent when a new message is created in a partnership room
* JWT token must be verified using your Integration UUID as the secret
* Messages can include file attachments with download URLs
* `replied_to_message_uuid` is null for new messages, set for replies
* Configuration array is typically empty for message events
