> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-restapi-chat-api-eng-37141.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Send a CometChat message on behalf of a user with REST API for one-on-one or group conversations.

# Send Message

## Constraints

| Item                                                                        | Constraint                                              | Notes                                                              |
| --------------------------------------------------------------------------- | ------------------------------------------------------- | ------------------------------------------------------------------ |
| Maximum message size                                                        | 65 KB (\~65,536 characters including metadata)          | Total size limit for the entire message payload                    |
| File size per message                                                       | 100 MB                                                  | Applies to the uploaded file associated with the message           |
| Message data object                                                         | 10 KB max (UTF8mb4)                                     | Keys with special meaning: text, attachments, customData, metadata |
| Tags                                                                        | Up to 25 tags, 100 characters each (UTF8mb4)            | Tags can be in any language                                        |
| User mentions                                                               | Up to 10 distinct users                                 | Format: `<@uid:{uid of the user}>`                                 |
| Reactions                                                                   | Max 25 distinct reactions, 45 characters each (UTF8mb4) | Emoji supported (may use multiple code points)                     |
| Unread message count (groups)                                               | Up to 300 members                                       | Not updated for larger groups                                      |
| Message receipts (groups)                                                   | Up to 300 online users                                  | Delivery/read receipts disabled in large groups                    |
| For the complete error reference, see [Error Guide](/articles/error-guide). |                                                         |                                                                    |


## OpenAPI

````yaml post /messages
openapi: 3.0.0
info:
  title: Chat APIs
  description: Manage messages, users, groups for a particular app using our Chat API.
  version: '3.0'
servers:
  - url: https://{appId}.api-{region}.cometchat.io/v3
    variables:
      appId:
        default: appId
        description: (Required) App ID
      region:
        enum:
          - us
          - eu
          - in
        default: us
        description: Select Region
security: []
tags:
  - name: API Keys
    description: The API keys are used to authorise the APIs
  - name: Roles
    description: The roles are used to give user access rights
  - name: Users
    description: The REST collection for users.
  - name: Auth Tokens
    description: The auth tokens are used to login end users using client SDKs.
  - name: Blocked Users
    description: The REST collections for blocked users.
  - name: Friends
    description: List,add and remove friends by passing UID in path variables
  - name: Groups
    description: The REST collections for groups.
  - name: Banned Users
    description: Ban and Unban user by passing other UID in path variables.
  - name: Group Members
    description: The REST collections for group members.
  - name: Messages
    description: The REST collections for messages.
  - name: Conversations
    description: The REST collections for conversations.
  - name: Restrict Features
    description: Allows Restricting Features
  - name: Metrics
    description: Allows accessing Data Metrics
  - name: Triggers
    description: Allows adding triggers to a webhook.
  - name: Webhooks
    description: Allows accessing Webhooks.
  - name: Notifications
    description: Allows configuring Notifications core.
  - name: Moderation
    description: The REST collections for Moderations.
paths:
  /messages:
    post:
      tags:
        - Messages
      summary: Send Message
      description: Sends Message on behalf of a user.
      operationId: send-message
      parameters:
        - $ref: '#/components/parameters/onBehalfOf'
      requestBody:
        content:
          application/json:
            schema:
              discriminator:
                propertyName: category
                mapping:
                  message:
                    $ref: '#/components/schemas/messageCategorySchema'
                  interactive:
                    $ref: '#/components/schemas/interactiveCategorySchema'
                  custom:
                    $ref: '#/components/schemas/customCategorySchema'
              oneOf:
                - $ref: '#/components/schemas/messageCategorySchema'
                - $ref: '#/components/schemas/customCategorySchema'
                - $ref: '#/components/schemas/interactiveCategorySchema'
            examples:
              Text Message:
                $ref: '#/components/examples/text-message'
              Media Message:
                $ref: '#/components/examples/media-message'
              Custom Message:
                $ref: '#/components/examples/custom-message'
      responses:
        '200':
          description: Create Message
          content:
            application/json:
              schema:
                properties:
                  data:
                    type: object
                type: object
              example:
                data:
                  id: '1'
                  conversationId: superhero3_user_superhero5
                  sender: superhero3
                  receiverType: user
                  receiver: superhero5
                  category: message
                  type: text
                  data:
                    text: test     hello
                    metadata:
                      key1: val1
                    entities:
                      sender:
                        entity:
                          uid: superhero3
                          name: Spiderman
                          avatar: >-
                            https://data-us.cometchat.io/assets/images/avatars/spiderman.png
                          status: offline
                          role: default
                          createdAt: 1638361550
                        entityType: user
                      receiver:
                        entity:
                          uid: superhero5
                          name: Cyclops
                          avatar: >-
                            https://data-us.cometchat.io/assets/images/avatars/cyclops.png
                          status: offline
                          role: default
                          createdAt: 1638361550
                          conversationId: superhero3_user_superhero5
                        entityType: user
                  sentAt: 1638423490
                  updatedAt: 1638423490
      security:
        - apiKey: []
components:
  parameters:
    onBehalfOf:
      name: onBehalfOf
      in: header
      description: UID of the user on whose behalf the action is performed.
      schema:
        type: string
  schemas:
    messageCategorySchema:
      properties:
        receiver:
          description: The receiver of the message.
          type: string
        muid:
          description: The muid will be a unique Identifier of the message.
          type: string
        receiverType:
          description: The receiverType of the message. either user or group
          type: string
          enum:
            - user
            - group
        category:
          description: >-
            Category of the message. The available categories are message and
            custom.
          type: string
          default: message
          enum:
            - message
        quotedMessageId:
          description: >-
            ID of the message being quoted.

            If provided, the send message response will include a
            `quotedMessage` node

            in the response containing the referenced message object.
          type: string
        type:
          description: >-
            Type of the message. The available values are text, image, file,
            audio, video.
          type: string
          default: text
          enum:
            - text
            - image
            - file
            - audio
            - video
        data:
          description: JSON containing message attributes.
          properties:
            text:
              type: string
            metadata:
              type: object
            attachments:
              description: >-
                For the messages with image, video, audio or file type (i.e.
                category=="message" && type !="text"), the property contains an
                array of attachment objects.
              type: array
              items:
                properties:
                  url:
                    description: Contains the URL of the attachment.
                    type: string
                  name:
                    description: Name of the attachment.
                    type: string
                  mimeType:
                    description: Mime Type of attachment.
                    type: string
                  extension:
                    description: The extension of the attachment.
                    type: string
                  size:
                    description: The size of the attachment(in bytes).
                    type: string
                type: object
          type: object
        multipleReceivers:
          description: >-
            JSON containing array of UIDs and GUID for whom the message must be
            sent. Format for multiple receivers - {"uids": ["uid1","uid2"],
            "guids":["guid1"]}
          properties:
            uids:
              type: array
              items:
                type: string
            guids:
              type: array
              items:
                type: string
          type: object
        tags:
          description: A list of tags to identify specific messages.
          type: array
          items:
            type: string
      type: object
    interactiveCategorySchema:
      properties:
        receiver:
          description: The receiver of the message.
          type: string
        muid:
          description: The muid will be a unique Identifier of the message.
          type: string
        receiverType:
          description: The receiverType of the message. either user or group
          type: string
          enum:
            - user
            - group
        category:
          description: Category of the message. The available categories is interactive.
          type: string
          default: interactive
          enum:
            - interactive
        type:
          description: >-
            Type of the message. The available values are card, form and
            customInteractive.
          type: string
          default: card
          enum:
            - card
            - form
            - customInteractive
            - scheduler
        data:
          description: >-
            JSON containing message attributes. Please select the appropriate
            schema based on the type property.
          type: object
          oneOf:
            - $ref: '#/components/schemas/interactionFormSchema'
            - $ref: '#/components/schemas/interactionCardSchema'
            - $ref: '#/components/schemas/SchedulerSchema'
            - $ref: '#/components/schemas/customInteractiveSchema'
        multipleReceivers:
          description: >-
            JSON containing array of UIDs and GUID for whom the message must be
            sent. Format for multiple receivers - {"uids": ["uid1","uid2"],
            "guids":["guid1"]}
          properties:
            uids:
              type: array
              items:
                type: string
            guids:
              type: array
              items:
                type: string
          type: object
        tags:
          description: A list of tags to identify specific messages.
          type: array
          items:
            type: string
      type: object
      example:
        receiverType: user
        data:
          interactionGoal:
            type: allOf
            elementIds:
              - element8
          allowSenderInteraction: true
          interactiveData:
            title: Form Title
            formFields:
              - elementType: textInput
                elementId: element1
                defaultValue: vivek
                label: Name
                optional: false
                maxLines: 1
                placeholder:
                  text: write your name here
              - elementType: textInput
                elementId: element2
                label: Last Name
                optional: false
                maxLines: 1
              - elementType: textInput
                elementId: element3
                label: Address
                optional: false
                maxLines: 5
              - elementType: dropdown
                elementId: element4
                label: Country
                optional: false
                defaultValue: option1
                options:
                  - value: option1
                    label: INDIA
                  - value: option2
                    label: AUSTRALIA
              - elementType: checkbox
                elementId: element5
                optional: true
                label: Services
                options:
                  - value: option1
                    label: Garbage
                  - value: option2
                    label: Electricity Bill
                  - value: option3
                    label: Lift
                defaultValue:
                  - option1
                  - option2
              - elementType: singleSelect
                elementId: element6
                optional: false
                label: Wing
                defaultValue: option1
                options:
                  - value: option1
                    label: A Wing
                  - value: option2
                    label: B Wing
              - elementType: button
                elementId: element9
                buttonText: About us
                disableAfterInteracted: true
                action:
                  actionType: urlNavigation
                  url: https://www.cometchat.com
            submitElement:
              elementType: button
              elementId: element8
              buttonText: Submit
              disableAfterInteracted: true
              action:
                actionType: apiAction
                url: >-
                  https://10893f2ae68f59.api-us.cometchat-staging.com/v3.0/messages
                method: POST
                payload:
                  category: message
                  type: text
                  data:
                    text: Thanks For filling the Form!
                  receiver: superhero2
                  receiverType: user
                headers:
                  appId: 10893f2ae68f59
                  Content-Type: application/json
                  apiKey: 5797f2d3d103d7d78f085eb46bfd14d5c45ddfdf
                  onBehalfOf: superhero1
                dataKey: CometChatData
        category: interactive
        type: form
        receiver: superhero1
        tags:
          - tag1
    customCategorySchema:
      properties:
        receiver:
          description: The receiver of the message.
          type: string
        muid:
          description: The muid will be a unique Identifier of the message.
          type: string
        receiverType:
          description: The receiverType of the message. either user or group
          type: string
          enum:
            - user
            - group
        category:
          description: Category of the message. The available categories is custom.
          type: string
          default: custom
          enum:
            - custom
        quotedMessageId:
          description: >-
            ID of the message being quoted.

            If provided, the send message response will include a
            `quotedMessage` node

            in the response containing the referenced message object.
          type: string
          default: message
          enum:
            - message
        type:
          description: Type of the message.
          type: string
        data:
          description: JSON containing message attributes.
          properties:
            customData:
              description: when category==”custom”, this property can have any JSON object.
              type: object
          type: object
        multipleReceivers:
          description: >-
            JSON containing array of UIDs and GUID for whom the message must be
            sent. Format for multiple receivers - {"uids": ["uid1","uid2"],
            "guids":["guid1"]}
          properties:
            uids:
              type: array
              items:
                type: string
            guids:
              type: array
              items:
                type: string
          type: object
        tags:
          description: A list of tags to identify specific messages.
          type: array
          items:
            type: string
      type: object
    interactionFormSchema:
      title: Form Schema
      properties:
        interactionGoal:
          properties:
            type:
              type: string
              enum:
                - anyOf
                - allOf
                - oneOf
                - none
            elementIds:
              type: array
              items:
                type: string
          type: object
        allowSenderInteraction:
          type: boolean
        interactiveData:
          properties:
            text:
              type: string
            formFields:
              type: array
              items:
                properties:
                  elementType:
                    type: string
                  elementId:
                    type: string
                  defaultValue:
                    type: string
                  label:
                    type: string
                  optional:
                    type: boolean
                  maxLines:
                    type: integer
                  placeholder:
                    type: object
                type: object
            submitElement:
              properties:
                elementType:
                  type: string
                elementId:
                  type: string
                buttonText:
                  type: string
                disableAfterInteracted:
                  type: boolean
                optional:
                  type: boolean
                action:
                  properties:
                    url:
                      type: string
                    method:
                      type: string
                    payload:
                      type: object
                    headers:
                      type: object
                    dataKey:
                      type: string
                    actionType:
                      type: string
                  type: object
              type: object
          type: object
      type: object
    interactionCardSchema:
      title: Card Schema
      properties:
        interactionGoal:
          properties:
            type:
              type: string
              enum:
                - anyOf
                - allOf
                - oneOf
                - none
            elementIds:
              type: array
              items:
                type: string
          type: object
        allowSenderInteraction:
          type: boolean
        interactiveData:
          properties:
            text:
              type: string
            cardActions:
              type: array
              items:
                properties:
                  elementType:
                    type: string
                  elementId:
                    type: string
                  defaultValue:
                    type: string
                  label:
                    type: string
                  optional:
                    type: boolean
                  maxLines:
                    type: integer
                  placeholder:
                    type: object
                type: object
            submitElement:
              properties:
                elementType:
                  type: string
                elementId:
                  type: string
                buttonText:
                  type: string
                disableAfterInteracted:
                  type: boolean
                optional:
                  type: boolean
                action:
                  properties:
                    url:
                      type: string
                    method:
                      type: string
                    payload:
                      type: object
                    headers:
                      type: object
                    dataKey:
                      type: string
                    actionType:
                      type: string
                  type: object
              type: object
          type: object
      type: object
    SchedulerSchema:
      required:
        - interactionGoal
        - allowSenderInteraction
        - interactiveData
      properties:
        interactionGoal:
          required:
            - type
            - elementIds
          properties:
            type:
              type: string
              enum:
                - anyAction
                - allOf
                - oneOf
                - none
            elementIds:
              type: array
              items:
                type: string
          type: object
        allowSenderInteraction:
          type: boolean
        interactiveData:
          required:
            - title
            - avatarUrl
            - bufferTime
            - icsFileUrl
            - availability
            - timezoneCode
            - duration
            - scheduleElement
            - goalCompletionText
            - dateRangeStart
            - dateRangeEnd
          properties:
            title:
              type: string
            avatarUrl:
              type: string
            bufferTime:
              type: integer
            icsFileUrl:
              type: string
            timezoneCode:
              type: string
            duration:
              type: integer
            scheduleElement:
              required:
                - action
                - elementId
                - buttonText
                - elementType
                - disableAfterInteracted
              properties:
                action:
                  required:
                    - url
                    - actionType
                    - method
                    - dataKey
                    - headers
                    - payload
                  properties:
                    url:
                      type: string
                    actionType:
                      type: string
                    method:
                      type: string
                    dataKey:
                      type: string
                    headers:
                      type: object
                    payload:
                      required:
                        - data
                        - type
                        - category
                        - receiver
                        - receiverType
                      properties:
                        data:
                          properties:
                            text:
                              type: string
                          type: object
                        type:
                          type: string
                        category:
                          type: string
                        receiver:
                          type: string
                        receiverType:
                          type: string
                      type: object
                  type: object
                elementId:
                  type: string
                buttonText:
                  type: string
                elementType:
                  type: string
                disableAfterInteracted:
                  type: boolean
              type: object
            goalCompletionText:
              type: string
            dateRangeStart:
              type: string
              format: date
            dateRangeEnd:
              type: string
              format: date
          type: object
      type: object
    customInteractiveSchema:
      title: Custom Interactive Schema
      properties:
        data:
          type: object
      type: object
  examples:
    text-message:
      summary: Text Message example
      value:
        receiver: cometchat-uid-2
        receiverType: user
        category: message
        type: text
        data:
          text: Hello
    media-message:
      summary: Media Message example
      value:
        receiverType: user
        data:
          text: Hello there!
          attachments:
            - name: ironman.png
              extension: png
              mimeType: image/png
              url: >-
                https:
                //files-<REGION>.cometchat.io/<APP_ID>/media/<HASH>.png?fat=<FILE_ACCESS_TOKEN>
        category: message
        type: image
        receiver: cometchat-uid-2
    custom-message:
      summary: Custom Message example
      value:
        receiverType: user
        data:
          customData:
            text: Hello there!
        category: custom
        type: text
        receiver: cometchat-uid-2
        tags:
          - tag1
  securitySchemes:
    apiKey:
      type: apiKey
      description: API Key with fullAccess scope(i.e. Rest API Key from the Dashboard).
      name: apikey
      in: header

````