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

# Usage examples

> Copy common Messaging API flows.

These examples use bearer auth for readability. Use [HMAC signing](/api/authentication) when a request should be signed instead of carrying the secret directly.

## Send a first message

```bash theme={null}
curl https://console.trychert.com/api/v1/send \
  -H "Authorization: Bearer $CHERT_SIGNING_SECRET" \
  -H "Content-Type: application/json" \
  -d '{"phone":"+14155551234","body":"Hi Sam - got a minute?"}'
```

## Create a chat, then follow up

```bash theme={null}
CHAT_ID=$(
  curl -s https://console.trychert.com/api/v1/chats \
    -H "Authorization: Bearer $CHERT_SIGNING_SECRET" \
    -H "Content-Type: application/json" \
    -d '{
      "from": "+15555550100",
      "to": ["+14155551234"],
      "message": {
        "parts": [{ "type": "text", "value": "Hi Sam - got a minute?" }]
      }
    }' | jq -r '.chat.id'
)

curl -X POST "https://console.trychert.com/api/v1/chats/$CHAT_ID/messages" \
  -H "Authorization: Bearer $CHERT_SIGNING_SECRET" \
  -H "Content-Type: application/json" \
  -d '{
    "message": {
      "parts": [{ "type": "text", "value": "Following up here." }]
    }
  }'
```

## Send a rich link

The `rich_link` part shape is the same on every Chert sender line.

```bash theme={null}
curl -X POST "https://console.trychert.com/api/v1/chats/$CHAT_ID/messages" \
  -H "Authorization: Bearer $CHERT_SIGNING_SECRET" \
  -H "Content-Type: application/json" \
  -d '{
    "message": {
      "parts": [
        { "type": "text", "value": "Here is the review link." },
        { "type": "rich_link", "url": "https://example.com/review" }
      ]
    }
  }'
```

## Send image, text, and a rich link

Use this follow-up endpoint for existing DMs and groups. For a new group,
[create the group](/api/group-chats/create) with text first, then send this
message after you have the `chat.id`.

```bash theme={null}
curl -X POST "https://console.trychert.com/api/v1/chats/$CHAT_ID/messages" \
  -H "Authorization: Bearer $CHERT_SIGNING_SECRET" \
  -H "Content-Type: application/json" \
  -d '{
    "message": {
      "parts": [
        { "type": "media", "attachment_id": "att_review_image" },
        { "type": "text", "value": "Hi Marcus, this is Todd from Texas Prime Plumbing. I would really appreciate a Google review." },
        { "type": "rich_link", "url": "https://search.google.com/local/writereview?placeid=..." }
      ]
    }
  }'
```

## Upload and send a file

```bash theme={null}
UPLOAD=$(
  curl -s https://console.trychert.com/api/v1/attachments \
    -H "Authorization: Bearer $CHERT_SIGNING_SECRET" \
    -H "Content-Type: application/json" \
    -d '{"filename":"invoice.pdf","content_type":"application/pdf","size_bytes":204800}'
)

UPLOAD_URL=$(echo "$UPLOAD" | jq -r '.upload_url')
ATTACHMENT_ID=$(echo "$UPLOAD" | jq -r '.attachment_id')

curl -X PUT "$UPLOAD_URL" \
  -H "Authorization: Bearer $CHERT_SIGNING_SECRET" \
  -H "Content-Type: application/pdf" \
  --data-binary @invoice.pdf

curl -X POST "https://console.trychert.com/api/v1/chats/CHAT_ID/messages" \
  -H "Authorization: Bearer YOUR_SIGNING_SECRET" \
  -H "Content-Type: application/json" \
  -d '{
    "message": {
      "parts": [
        { "type": "text",  "value": "See attached." },
        { "type": "media", "attachment_id": "att_abc..." }
      ]
    }
  }'
```

## Send multiple images

Upload multiple images, then request grouped delivery from an existing chat.

```bash theme={null}
curl -X POST "https://console.trychert.com/api/v1/chats/$CHAT_ID/messages" \
  -H "Authorization: Bearer $CHERT_SIGNING_SECRET" \
  -H "Content-Type: application/json" \
  -d '{
    "parallel_attachments": true,
    "message": {
      "parts": [
        { "type": "media", "attachment_id": "att_photo_1" },
        { "type": "media", "attachment_id": "att_photo_2" },
        { "type": "media", "attachment_id": "att_photo_3" },
        { "type": "media", "attachment_id": "att_photo_4" }
      ]
    }
  }'
```

## Stream replies while developing

```bash theme={null}
curl -N https://console.trychert.com/api/v1/events/stream \
  -H "Authorization: Bearer $CHERT_SIGNING_SECRET"
```

For production, create a webhook subscription and listen for `message.received`.

```bash theme={null}
curl -X POST https://console.trychert.com/api/v1/webhook-subscriptions \
  -H "Authorization: Bearer $CHERT_SIGNING_SECRET" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://your-app.example/webhooks/chert",
    "events": ["message.received"]
  }'
```

## React to a message

Use a message id from chat history or a `message.received` webhook.

```bash theme={null}
curl -X POST "https://console.trychert.com/api/v1/messages/$MESSAGE_ID/react" \
  -H "Authorization: Bearer $CHERT_SIGNING_SECRET" \
  -H "Content-Type: application/json" \
  -d '{"reaction":"like"}'
```
