דלג לתוכן הראשי
Subscribe 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

Subscribe

Send the body below to Import Subscription. 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.
Import body
{
  "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"
}
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.

Payload

When the event fires, your URL receives an HTTP POST with eventName: "newMediaMessage" and the following eventData:
message
Message
The incoming message, including the media array with each file’s fileId (use Generate Public Media URL to download). See the Message object for all fields.
chat
Chat
The chat the message belongs to. See the Chat object for all fields.
Example payload
{
  "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