Developer recipe

Send your first Telegram message

Verify an API key, choose a connected Telegram account, and start a direct conversation by username.

Result
A Telegram DM is sent from one of your connected accounts and the resulting chat is returned.
Time
5 minutes
Key scopes
readsend

Before you start

  1. Connect at least one Telegram account in GramClaw Settings.
  2. Create an API key with read and send scopes. The full key is shown only once.
  3. Choose a recipient who expects the test message. The endpoint sends immediately.

1. Set your credentials

Keep the API key in a server-side environment variable. Do not place it in browser code or commit it to source control.

Terminal
export GRAMCLAW_BASE_URL="https://gramclaw.com"
export GRAMCLAW_API_KEY="gc_live_replace_with_your_key"

2. Verify the key and find an account ID

The response lists only connected accounts this key is allowed to use. Copy the id of the Telegram account you want to send from.

Terminal
curl -s "$GRAMCLAW_BASE_URL/api/v1/me" \
  -H "Authorization: Bearer $GRAMCLAW_API_KEY"

3. Start the conversation and send

Replace the account ID, username, and message. Keep the same Idempotency-Key when retrying this exact request so a network retry does not send twice.

Terminal
export TELEGRAM_ACCOUNT_ID="replace_with_account_id"

curl -s "$GRAMCLAW_BASE_URL/api/v1/chats/start" \
  -H "Authorization: Bearer $GRAMCLAW_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: first-message-001" \
  -d '{
    "account_id": "'"$TELEGRAM_ACCOUNT_ID"'",
    "identifier": "@recipient_username",
    "provider": "TELEGRAM",
    "text": "Hi! This is a test message sent with the GramClaw API."
  }'
  • Success returns a chat object containing its id.
  • A 401 means the key is missing or invalid. A 403 means the key lacks the send scope or cannot use that account.
  • A 404 means GramClaw could not resolve or reach the supplied identifier.
Chat on Telegram