Skip to content

Gateways ​

Gateways connect your agent to external communication channels.

Overview ​

Supported channels:

  • Email - SMTP/IMAP integration
  • Telegram - Bot API
  • WhatsApp - Business API
  • Slack - Workspace integration
  • Discord - Bot integration
  • X.com (Twitter) - Post tweets and interactions
  • SMS - Twilio/providers
  • Webhook - Custom HTTP endpoints

Cross-Gateway Features

When the same contact uses multiple gateways, they share:

  • Memory - Preferences and facts persist across channels
  • History - Search conversations across all platforms
  • Context - Agent knows who they're talking to regardless of channel

See Contacts - Cross-Gateway Memory for details.

Gateway Types ​

Email ​

json
{
  "type": "email",
  "name": "Support Email",
  "config": {
    "smtp_host": "smtp.example.com",
    "smtp_port": 587,
    "smtp_user": "support@example.com",
    "smtp_password": "{{secrets.smtp_password}}",
    "from_name": "Support Team",
    "from_email": "support@example.com"
  }
}

Telegram ​

json
{
  "type": "telegram",
  "name": "Support Bot",
  "config": {
    "bot_token": "{{secrets.telegram_token}}",
    "webhook_url": "https://your-domain.com/webhooks/telegram"
  }
}

WhatsApp ​

json
{
  "type": "whatsapp",
  "name": "WhatsApp Business",
  "config": {
    "phone_number_id": "123456789",
    "access_token": "{{secrets.whatsapp_token}}",
    "business_id": "987654321"
  }
}

Slack ​

json
{
  "type": "slack",
  "name": "Workspace",
  "config": {
    "bot_token": "{{secrets.slack_token}}",
    "app_id": "A123456",
    "signing_secret": "{{secrets.slack_signing}}"
  }
}

Discord ​

json
{
  "type": "discord",
  "name": "Server Bot",
  "config": {
    "bot_token": "{{secrets.discord_token}}",
    "application_id": "123456789"
  }
}

X.com (Twitter) ​

json
{
  "type": "x",
  "name": "Twitter Bot",
  "config": {
    "api_key": "{{secrets.x_api_key}}",
    "api_secret": "{{secrets.x_api_secret}}",
    "access_token": "{{secrets.x_access_token}}",
    "access_token_secret": "{{secrets.x_access_token_secret}}"
  }
}

X.com Features ​

FeatureDescription
Post tweetsSend tweets from your agent
Reply to mentionsRespond to @mentions
Direct messagesSend and receive DMs
Media uploadAttach images to tweets

Posting a Tweet ​

bash
curl -X POST https://your-domain.com/api/agents/{id}/messages \
  -d '{
    "gateway_id": "x-gateway-123",
    "content": "Hello from my AI agent! 🤖",
    "options": {
      "media_url": "https://example.com/image.png"
    }
  }'

SMS ​

json
{
  "type": "sms",
  "name": "Twilio SMS",
  "config": {
    "provider": "twilio",
    "account_sid": "ACxxxx",
    "auth_token": "{{secrets.twilio_token}}",
    "from_number": "+1234567890"
  }
}

Webhook ​

json
{
  "type": "webhook",
  "name": "Custom Integration",
  "config": {
    "url": "https://api.example.com/messages",
    "method": "POST",
    "headers": {
      "Authorization": "Bearer {{secrets.api_key}}"
    }
  }
}

MQTT ​

Bidirectional IoT messaging through an EMQX broker: the agent subscribes to one topic and publishes replies to another.

json
{
  "type": "mqtt",
  "name": "Sensor fleet",
  "config": {
    "brokerUrl": "mqtts://broker.example.com:8883",
    "subscribeTopic": "devices/+/in",
    "publishTopic": "devices/out",
    "qos": 1,
    "autoReply": false,
    "replyMaxChars": 240
  }
}

Two options matter for machine-facing endpoints, and the Add/Edit gateway dialog exposes both for MQTT:

  • autoReply (default true). With false the gateway is ingest-only: inbound messages are stored in the conversation and workflow triggers still fire, but the agentic loop never runs and nothing is published back (no /start greeting either). Use it for telemetry feeds the agent should know about but not answer.
  • replyMaxChars (default unlimited). Replies are cut to this many characters (with a trailing …) before they are published, so constrained devices never receive a long message.

autoReply is a common GatewayConfig field, so it can be set on any gateway type; replyMaxChars is applied on the MQTT outbound path.

Creating Gateways ​

Via Dashboard ​

  1. Navigate to Services
  2. Click Add Gateway
  3. Select type
  4. Configure credentials
  5. Test connection
  6. Save

Via API ​

bash
curl -X POST https://your-domain.com/api/agents/{id}/gateways \
  -H "Content-Type: application/json" \
  -d '{
    "type": "telegram",
    "name": "Support Bot",
    "config": {
      "bot_token": "123456:ABC..."
    }
  }'

Managing Gateways ​

List Gateways ​

bash
curl https://your-domain.com/api/agents/{id}/gateways

Get Gateway ​

bash
curl https://your-domain.com/api/agents/{id}/gateways/{gatewayId}

Update Gateway ​

bash
curl -X PUT https://your-domain.com/api/agents/{id}/gateways/{gatewayId} \
  -d '{
    "config": {
      "from_name": "New Name"
    }
  }'

Delete Gateway ​

bash
curl -X DELETE https://your-domain.com/api/agents/{id}/gateways/{gatewayId}

Sending Messages ​

Via API ​

bash
curl -X POST https://your-domain.com/api/agents/{id}/messages \
  -d '{
    "gateway_id": "gateway-123",
    "to": "+1234567890",
    "content": "Hello from the agent!"
  }'

Via Workflow ​

json
{
  "type": "send-message",
  "data": {
    "gateway": "telegram-bot",
    "to": "{{contact.telegram}}",
    "message": "Your order is ready!"
  }
}

Receiving Messages ​

Webhook Processing ​

External Service
     │
     │ Webhook POST
     ▼
┌─────────────────┐
│   Gateway       │
│   Webhook       │
└────────┬────────┘
         │
         ▼
┌─────────────────┐
│   Message       │
│   Processing    │
└────────┬────────┘
         │
         ▼
┌─────────────────┐
│   Agent         │
│   Response      │
└─────────────────┘

Message Format ​

json
{
  "id": "msg-123",
  "gateway_id": "gateway-456",
  "direction": "inbound",
  "from": "+1234567890",
  "to": "agent",
  "content": "Hello!",
  "metadata": {
    "channel": "sms",
    "timestamp": "2024-12-15T10:00:00Z"
  }
}

Default Gateway ​

Set a default gateway per channel:

json
{
  "type": "telegram",
  "is_default": true
}

Gateway Status ​

StatusDescription
activeReady to send/receive
inactiveDisabled
errorConfiguration issue
rate_limitedTemporarily limited

Integration ​

With Contacts ​

Route based on contact preference:

json
{
  "type": "send-message",
  "data": {
    "contact_id": "{{contact.id}}",
    "channel": "{{contact.preferred_channel}}",
    "message": "Hello {{contact.name}}!"
  }
}

With Conversations ​

Messages are grouped by conversation:

json
{
  "conversation_id": "conv-123",
  "gateway_id": "gateway-456",
  "contact_id": "contact-789"
}

Best Practices ​

1. Secure Credentials ​

Store sensitive data securely:

  • Use secrets storage
  • Never log tokens
  • Rotate regularly

2. Test Before Deploy ​

Verify configuration:

  • Send test messages
  • Check webhook delivery
  • Monitor responses

3. Handle Rate Limits ​

Respect provider limits:

  • Implement backoff
  • Queue messages
  • Monitor usage

4. Log Messages ​

Track all communication:

  • Store message history
  • Log delivery status
  • Audit access

5. Use Templates ​

Standardize messages:

  • Create message templates
  • Use variables
  • Maintain consistency

Troubleshooting ​

Messages Not Sending ​

  1. Verify credentials
  2. Check gateway status
  3. Review error logs
  4. Test with simple message

Webhooks Not Received ​

  1. Verify webhook URL
  2. Check authentication
  3. Review server logs
  4. Test with curl

Rate Limiting ​

  1. Reduce message frequency
  2. Implement queuing
  3. Contact provider
  4. Use multiple gateways

Processing Architecture ​

The gateway system uses a modular processor architecture that handles:

  1. Input Parsing - Platform-specific webhook parsing into standardized format
  2. Contact Resolution - Address book lookup/creation
  3. Conversation Management - Thread tracking across platforms
  4. Output Formatting - Platform-specific message formatting (HTML, Block Kit, etc.)
  5. Delivery - Platform API integration with rate limiting
Webhook → Parser → Contact Lookup → Agent → Formatter → Platform API

Each platform has its own processor implementation:

  • TelegramProcessor - Bot API, HTML formatting, inline keyboards
  • EmailProcessor - Resend/MailChannels, HTML emails, attachments
  • WhatsAppProcessor - Meta Business API, templates, media support
  • SlackProcessor - Block Kit, threads, file uploads (planned)
  • DiscordProcessor - Embeds, interactions (planned)

See Gateway Processing Architecture for detailed technical documentation.

API Reference ​

See Gateways API for complete endpoint documentation.