With a chat platform API custom app, you can set up a workflow that lets your
agents attach files during a chat session.

## Agent file attachment workflow

Here's the workflow for an agent attaching a file during a chat session.

1. An agent attaches a file during a chat session.
2. Your webhook endpoint receives a `message_received` event, which includes the `media_id` value for the attached file. For more information, see [Webhooks for the chat API platform](https://docs.cloud.google.com/contact-center/ccai-platform/docs/webhooks).
3. Send a `GET` request to the following endpoint to get the attachment file,
   specifying the `media_id` value from the previous step. Authenticate using
   [basic authentication](https://docs.cloud.google.com/contact-center/ccai-platform/docs/apps-api#basic_authentication).

       https://YOUR_CCAAS_HOST/apps/api/v1/chats/CHAT_ID/media?media_id=MEDIA_ID&media_type=MEDIA_TYPE

   Replace the following:
   - `YOUR_CCAAS_HOST`: your Contact Center AI Platform (CCAI Platform) host

   - `CHAT_ID`: the chat ID

   - `MEDIA_ID`: the ID of the file that you want to
     download. Get this from the `message_received` webhook event.

   - `MEDIA_TYPE`: the type of the file that you want
     to download. One of `photo`, `video`, `audio`, or `document`.

   A successful request returns the attachment file. For more information, see
   [Chat platform API Guide](https://docs.cloud.google.com/contact-center/ccai-platform/docs/chat-platform-api-guide).