# Sending outbound messages

Note:
The current messages version is v2. See [versioning](#versioning) for more information.

For sending messages, the [ConversationAPI format](/docs/conversation/message-types) is used.

You need to implement the transformation between the ConversationAPI format and the format for your channel.

## ConversationAPI specification derivations

Even though Chatlayer follows the ConversationAPI standard, some changes were made to match specific Chatlayer use-cases
better.

### Media Message

`media_message` also contains a type field representing the type of the media passed. This can be any of the following
values:

| type | value |
|  --- | --- |
| Image | 0 |
| Video | 1 |
| File | 2 |
| Audio | 3 |
| Unknown | -1 |


An example of how the payload may look:

```json
{
  "media_message": {
    "url": "https://foo.com/bar.png",
    "type": 1
  }
}
```

## Sending out messages

`bundle.inputData.messages` contains all the messages you need to process. These need to be filtered and transformed and
then you can trigger the required API to send out the message.

```javascript
const performSend = async (sdk, bundle) => {
    const transformedMessages = bundle.inputData.messages.map(message => {
        // This is a simple text example, but we support all ConversationAPI message types
        return message.text_message.text
    })

    // This will typically be the API you are currently implementing
    await sdk.request({
        url: "https://api.messaging.com/messages",
        method: "POST",
        body: transformedMessages
    })
}
```

## Custom message types

Certain message types are not supported in the native ConversationAPI format. We provide those under
the `explicit_channel_message.CHATLAYER` key.

All the types specified below will be JSON stringified, meaning you need to extract the actual object
with `JSON.parse(explicit_channel_message.CHATLAYER)`

### Quick replies

```json
{
  "text": "This is the quick reply title",
  "quick_replies": [
    {
      "title": "Click me",
      "content_type": "text",
      "payload": "ukgbkn24kjnb",
      "image_url": "https://image.com/image1"
    }
  ]
}
```

## Versioning

It is important to take versioning into account when developing your app. `bundle.version` will contain the version
number that corresponds to the used message format. It is very important to take this into account so that your
integration keeps working when a major change is made in the messaging format.