---
title: "Send message"
method: POST
path: "/messages"
tags: ["messages"]
---

# Send message

`POST /messages`

## Request

- Base URL: `https://botapi.tamtam.chat`
- URL: `https://botapi.tamtam.chat/messages`
- Auth: API key in query parameter `access_token`

Sends a message to a chat.
As a result for this method new message identifier returns.
### Attaching media
Attaching media to messages is a three-step process.

At first step, you should [obtain a URL to upload](#operation/getUploadUrl) your media files.

At the second, you should upload binary of appropriate format to URL you obtained at the previous step. See [upload](https://dev.tamtam.chat/#operation/getUploadUrl) section for details.

Finally, if the upload process was successful, you will receive JSON-object in a response body.  Use this object to create attachment. Construct an object with two properties:
- `type` with the value set to appropriate media type
- and `payload` filled with the JSON you've got.

For example, you can attach a video to message this way:

1. Get URL to upload. Execute following:
```shell
curl -X POST 'https://botapi.tamtam.chat/uploads?access_token=%access_token%&type=video'
```
As the result it will return URL for the next step.
```json
{
    "url": "https://vu.mycdn.me/upload.do…"
}
```

2. Use this url to upload your binary:
```shell
curl -i -X POST
  -H "Content-Type: multipart/form-data"
  -F "data=@movie.mp4" "https://vu.mycdn.me/upload.do…"
```
As the result it will return JSON you can attach to message:
```json
  {
    "token": "_3Rarhcf1PtlMXy8jpgie8Ai_KARnVFYNQTtmIRWNh4"
  }
```
3. Send message with attach:
```json
{
    "text": "Message with video",
    "attachments": [
        {
            "type": "video",
            "payload": {
                "token": "_3Rarhcf1PtlMXy8jpgie8Ai_KARnVFYNQTtmIRWNh4"
            }
        }
    ]
}
```

**Important notice**:

It may take time for the server to process your file (audio/video or any binary).
While a file is not processed you can't attach it. It means the last step will fail with `400` error.
Try to send a message again until you'll get a successful result.

## Query parameters

- `user_id` integer
- `chat_id` integer
- `disable_link_preview` boolean

## Request body

- NewMessageBody
  - `text` string, nullable, required: Message text
  - `attachments` AttachmentRequest[], nullable, required: Message attachments. See `AttachmentRequest` and it's inheritors for full information
    - `type` string, required
  - `link` NewMessageLink, required
    - `type` 'forward' | 'reply', required: Type of linked message
    - `mid` string, required: Message identifier of original message
  - `notify` boolean: If false, chat participants would not be notified
  - `format` 'markdown' | 'html': Message text format

## Response `200`

Returns info about created message

- SendMessageResult
  - `message` Message, required: Message in chat
    - `sender` User
      - `user_id` integer, required: Users identifier
      - `name` string, required: Users visible name
      - `username` string, nullable, required: Unique public user name. Can be `null` if user is not accessible or it is not set
      - `is_bot` boolean, required: `true` if user is bot
      - `last_activity_time` integer, required: Time of last user activity in TamTam (Unix timestamp in milliseconds). Can be outdated if user disabled its "online" status in settings
    - `recipient` Recipient, required: New message recipient. Could be user or chat
      - `chat_id` integer, nullable, required: Chat identifier
      - `chat_type` 'dialog' | 'chat' | 'channel', required: Type of chat. Dialog (one-on-one), chat or channel
      - `user_id` integer, nullable, required: User identifier, if message was sent to user
    - `timestamp` integer, required: Unix-time when message was created
    - `link` LinkedMessage
      - `type` 'forward' | 'reply', required: Type of linked message
      - `sender` User
        - `user_id` integer, required: Users identifier
        - `name` string, required: Users visible name
        - `username` string, nullable, required: Unique public user name. Can be `null` if user is not accessible or it is not set
        - `is_bot` boolean, required: `true` if user is bot
        - `last_activity_time` integer, required: Time of last user activity in TamTam (Unix timestamp in milliseconds). Can be outdated if user disabled its "online" status in settings
      - `chat_id` integer: Chat where message has been originally posted. For forwarded messages only
      - `message` MessageBody, required: Schema representing body of message
        - `mid` string, required: Unique identifier of message
        - `seq` integer, required: Sequence identifier of message in chat
        - `text` string, nullable, required: Message text
        - `attachments` Attachment[], nullable, required: Message attachments. Could be one of `Attachment` type. See description of this schema
          - `type` string, required
        - `markup` MarkupElement[], nullable: Message text markup. See [Formatting](#section/About/Text-formatting) section for more info
          - `type` string, required: Type of the markup element. Can be **strong**, *emphasized*, ~strikethrough~, ++underline++, `monospaced`, link or user_mention
          - `from` integer, required: Element start index (zero-based) in text
          - `length` integer, required: Length of the markup element
    - `body` MessageBody, required: Schema representing body of message
      - `mid` string, required: Unique identifier of message
      - `seq` integer, required: Sequence identifier of message in chat
      - `text` string, nullable, required: Message text
      - `attachments` Attachment[], nullable, required: Message attachments. Could be one of `Attachment` type. See description of this schema
        - `type` string, required
      - `markup` MarkupElement[], nullable: Message text markup. See [Formatting](#section/About/Text-formatting) section for more info
        - `type` string, required: Type of the markup element. Can be **strong**, *emphasized*, ~strikethrough~, ++underline++, `monospaced`, link or user_mention
        - `from` integer, required: Element start index (zero-based) in text
        - `length` integer, required: Length of the markup element
    - `stat` MessageStat: Message statistics
      - `views` integer, required
    - `url` string, nullable: Message public URL. Can be `null` for dialogs or non-public chats/channels
    - `constructor` User
      - `user_id` integer, required: Users identifier
      - `name` string, required: Users visible name
      - `username` string, nullable, required: Unique public user name. Can be `null` if user is not accessible or it is not set
      - `is_bot` boolean, required: `true` if user is bot
      - `last_activity_time` integer, required: Time of last user activity in TamTam (Unix timestamp in milliseconds). Can be outdated if user disabled its "online" status in settings

## Other responses

- `401`: Authorization Error. No `access_token` provided or token is invalid
- `500`: Internal Server Error

## Changes

- **2021-06-02** `137e3d1e0b4f`: 4 info
  - added `highlighted` discriminator mapping keys to the `message/body/allOf[#/components/schemas/MessageBody]/markup/items/` response property for the response status `200`
  - added `highlighted` discriminator mapping keys to the `message/link/allOf[#/components/schemas/LinkedMessage]/message/allOf[#/components/schemas/MessageBody]/markup/items/` response property for the response status `200`
  - removed `code` discriminator mapping keys from the `message/body/allOf[#/components/schemas/MessageBody]/markup/items/` response property for the response status `200`
  - removed `code` discriminator mapping keys from the `message/link/allOf[#/components/schemas/LinkedMessage]/message/allOf[#/components/schemas/MessageBody]/markup/items/` response property for the response status `200`
- **2021-05-31** `dc45288cfedc`: 6 info
  - added the new optional request property `format`
  - added the optional property `message/body/allOf[#/components/schemas/MessageBody]/markup` to the response with the `200` status
  - added the optional property `message/link/allOf[#/components/schemas/LinkedMessage]/message/allOf[#/components/schemas/MessageBody]/markup` to the response with the `200` status
  - added the required property `message/constructor/allOf[#/components/schemas/User]/last_activity_time` to the response with the `200` status
  - …2 more
- …earlier changes not shown

[Operation history](https://skmtc.dev/tamtam/apis/tamtam-bot-api/changes/messages/post.md)

---

[API](https://skmtc.dev/tamtam/apis/tamtam-bot-api.md) - [All operations](https://skmtc.dev/tamtam/apis/tamtam-bot-api/llms.txt) - [OpenAPI document](https://skmtc.dev/tamtam/apis/tamtam-bot-api/revisions/fa85402ea716?raw)
