API access

The Chat API provides endpoints for message handling, chat history, and bot interactions. Built on Next.js 15 and deployed on Vercel, it follows a serverless architecture with multi-agent support

Endpoints

Send Message

POST /api/telegram/message

// Request
{
  chatId: number;
  text: string;
  keyboard?: InlineKeyboard;
  agentId?: string;
}

// Response
204 No Content
400 Bad Request
401 Unauthorized
403 Forbidden
429 Too Many Requests
500 Internal Server Error

Webhook Handler

Data Types

Message Types

Keyboard Types

Database Operations

Store Message

Get Chat History

Update Chat History

Error Handling

Error Types

Common Errors

  • 400 Bad Request: Invalid message format or parameters

  • 401 Unauthorized: Invalid bot token or missing authentication

  • 403 Forbidden: Insufficient permissions or unauthorized agent

  • 429 Too Many Requests: Rate limit exceeded (function or message)

  • 500 Internal Server Error: Server-side error or external service failure

Rate Limiting

Function Calls

Message Sending

Security

Authentication

  • Bot token validation per agent

  • User permission checks

  • Group membership verification

  • Agent authorization

Input Validation

  • Message content sanitization

  • Parameter validation

  • Type checking

  • SQL injection prevention

Error Messages

Best Practices

  1. API Usage

    • Implement proper error handling

    • Follow rate limiting guidelines

    • Use appropriate content types

    • Validate all inputs

    • Handle timeouts gracefully

  2. Security

    • Validate all inputs

    • Sanitize responses

    • Handle errors securely

    • Use HTTPS only

    • Implement proper authentication

    • Follow least privilege principle

  3. Performance

    • Cache when possible

    • Use appropriate indexes

    • Monitor response times

    • Implement retry logic

    • Handle concurrent requests

    • Use connection pooling

  4. Multi-Agent Support

    • Validate agent configurations

    • Handle agent-specific settings

    • Maintain separate chat histories

    • Implement proper error boundaries

    • Monitor agent performance

Last updated