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

# Messages with Attachments

> Fires when a new incoming message contains media

ubscribe to receive a notification whenever a new incoming message contains a media attachment. Triggers for images, videos, audio files, documents, and stickers.

**Event name:** `newMediaMessage`\\

**Required token scopes:**

* `Create scenarios`
* `Manage scenarios on behalf of user`

see [Authentication](/he/api-reference/authentication)

## Subscribe

Send the body below to [Import Subscription](/he/api-reference/subscribe-to-events/import-subscription-subscribe-to-an-event). You only need to change:

* **`url`** *(required)* - Located under `data.actions[0].params.url`. Replace `{{yourWebhookURL}}` with the destination URL that should receive the events.
* **`asStatus`** - Keep `"active"` to enable the subscription immediately, or `"inactive"` to save it as an inactive revision.

```json Import body [expandable]  theme={null}
{
  "data": {
    "version": "v1",
    "name": "(SUB) Messages with Attachments",
    "description": "Sends a webhook when a new incoming message includes a media item (image / video / document / audio / sticker)",
    "triggerEvents": [
      "domain.message.created"
    ],
    "loaders": {
      "beforeConditions": [],
      "afterConditions": [
        {
          "name": "chat",
          "alias": "chat",
          "params": {
            "id": {
              "##provide": {
                "provider": "message",
                "key": "parent_chat"
              }
            }
          },
          "confidentialData": false
        }
      ]
    },
    "conditions": [
      [
        {
          "name": "filtrex",
          "params": {
            "expression": "direction == \"incoming\"",
            "value": {
              "##provide": {
                "provider": "message",
                "key": "message"
              }
            }
          },
          "confidentialData": false
        },
        {
          "name": "filtrex",
          "params": {
            "expression": "type == \"media\"",
            "value": {
              "##provide": {
                "provider": "message",
                "key": "message"
              }
            }
          },
          "confidentialData": false
        }
      ]
    ],
    "actions": [
      {
        "name": "request",
        "params": {
          "url": "{{yourWebhookURL}}",
          "method": "post",
          "json": true,
          "data": {
            "eventName": "newMediaMessage",
            "eventData": {
              "message": {
                "##provide": {
                  "provider": "message",
                  "key": "message"
                }
              },
              "chat": {
                "##provide": {
                  "provider": "chat",
                  "key": "chat"
                }
              }
            }
          }
        },
        "confidentialData": false
      }
    ],
    "options": {
      "unorderedActions": false
    }
  },
  "asStatus": "active"
}
```

<Note>
  A `201` response returns your new subscription - save its `_id` to manage it later. You can also add an optional `authorUid` root field (a Texter user UID) to attribute the subscription to a specific user.
</Note>

## Payload

When the event fires, your URL receives an HTTP `POST` with `eventName: "newMediaMessage"` and the following `eventData`:

<ResponseField name="message" type="Message">
  The incoming message, including the `media` array with each file's `fileId` (use [Generate Public Media URL](/he/api-reference/files/generate-public-media-url) to download). See the [Message object](/he/api-reference/objects/message) for all fields.
</ResponseField>

<ResponseField name="chat" type="Chat">
  The chat the message belongs to. See the [Chat object](/he/api-reference/objects/chat) for all fields.
</ResponseField>

```json Example payload  theme={null}
{
  "eventName": "newMediaMessage",
  "eventData": {
    "message": {
      "_id": "64de3b15398a8o09c47a9f62",
      "type": "media",
      "media": [
        {
          "mediaType": "image",
          "caption": "how much does it cost?",
          "fileId": "696325cb1bc02c8a8a9f383a",
          "filename": "image.png"
        }
      ],
      "direction": "incoming",
      "...": "..."
    },
    "chat": {
      "_id": "69062b15262e17ab3033f886",
      "displayName": "Noa Yoter",
      "...": "..."
    }
  }
}
```

## Manage this subscription

| Action             | Endpoint                                                                                 |
| ------------------ | ---------------------------------------------------------------------------------------- |
| List subscriptions | [List All Subscriptions](/he/api-reference/subscribe-to-events/list-all-subscriptions)   |
| Pause              | [Inactivate Subscription](/he/api-reference/subscribe-to-events/inactivate-subscription) |
| Resume             | [Activate Subscription](/he/api-reference/subscribe-to-events/activate-subscription)     |
| Delete             | [Delete Subscription](/he/api-reference/subscribe-to-events/delete-subscription)         |
| Debug executions   | [List Scenario Runs](/he/api-reference/scenarios-advanced/list-scenario-runs)            |
