Skip to content

API Reference

Complete reference for all API methods available for your chat bot.

Sending Messages

POST /bot/send-message

This is the primary method for your bot to send messages to users.

Headers:

javascript
{
  'Content-Type': 'application/json',
  'X-App-Key': 'your-bot-token'
}

Request Body:

javascript
{
  "uid": 12345,
  "message": {
    "text": "Hello! How can I help you today?",
    "buttonMarkup": [
      [
        { "text": "Get Started", "callbackData": "start_action" },
        { "text": "Help", "url": "https://example.com/help" }
      ]
    ]
  }
}

Parameters:

FieldTypeRequiredDescription
uidnumberYesThe user's unique identifier
messageobjectYesThe message object
message.textstringNoThe text content of the message
message.buttonMarkuparrayNoAn array of button rows (see Interactive Buttons)
message.mediaarrayNoAn array of media attachments (e.g., images)

Response:

A successful request will return a JSON object with the ID of the sent message:

javascript
{
  "success": true,
  "messageId": "507f1f77bcf86cd799439011"
}

Examples:

Simple Text Message:

javascript
async function sendWelcomeMessage(userId) {
  try {
    const response = await bot.sendMessage(userId, {
      text: 'Welcome to our service! 🎉',
    });
    console.log('Message sent:', response);
  } catch (error) {
    console.error('Failed to send message:', error);
  }
}

sendWelcomeMessage(12345);

Message with Interactive Buttons:

javascript
async function sendMenuMessage(userId) {
  const message = {
    text: 'What would you like to do?',
    buttonMarkup: [
      [
        { text: '📋 View Products', callbackData: 'menu_products' },
        { text: '🛒 My Orders', callbackData: 'menu_orders' },
      ],
      [{ text: '🌐 Visit Website', url: 'https://example.com' }],
    ],
  };

  try {
    const response = await bot.sendMessage(userId, message);
    console.log('Menu sent:', response);
  } catch (error) {
    console.error('Failed to send menu:', error);
  }
}

sendMenuMessage(12345);

Interactive Buttons

Add interactive buttons to your messages to create engaging, menu-driven experiences. Buttons are organized in rows within the buttonMarkup array.

Button Structure

Each button is an object with a text property and one of callbackData, url, or copyText:

javascript
{
  "text": "Button Label",
  "url": "https://example.com",        // Optional: For URL buttons
  "callbackData": "custom_data",       // Optional: For callback buttons
  "copyText": "text to copy"           // Optional: For copy buttons
}

Button Types

1. Callback Button

Triggers a callback-query webhook event when clicked. This is the primary way to handle interactive actions within your bot.

Structure: { "text": "Get Started", "callbackData": "start_action" }

Use Cases: Menu navigation, triggering bot actions, confirming choices.

2. URL Button

Opens a web page in the user's browser when clicked.

Structure: { "text": "Visit Website", "url": "https://example.com" }

Use Cases: Linking to your website, documentation, or payment pages.

3. Copy Button

Copies a specified string of text to the user's clipboard when clicked.

Structure: { "text": "Copy Code", "copyText": "PROMO2024" }

Use Cases: Sharing promo codes, referral links, or wallet addresses.

Button Layout

Buttons are arranged in an array of arrays, where each inner array represents a row of buttons:

javascript
"buttonMarkup": [
  [ button1, button2 ],    // First row with 2 buttons
  [ button3 ],             // Second row with 1 button
]

Button Examples

E-commerce Menu:

javascript
"buttonMarkup": [
  [
    { "text": "🛍️ Browse Products", "callbackData": "menu_products" },
    { "text": "🛒 My Cart", "callbackData": "menu_cart" }
  ],
  [
    { "text": "📞 Contact Support", "callbackData": "menu_support" },
    { "text": "🌐 Visit Store", "url": "https://store.example.com" }
  ]
]

Promotional Message:

javascript
"buttonMarkup": [
  [
    { "text": "📋 Copy Code", "copyText": "SAVE20" },
    { "text": "🛒 Shop Now", "url": "https://store.example.com/promo" }
  ],
  [
    { "text": "❌ No Thanks", "callbackData": "promo_decline" }
  ]
]

Limitations

  • Max buttons per message: 10
  • Max buttons per row: 4
  • Button text length: 20 characters
  • Callback data length: 64 characters
  • URL length: 2048 characters
  • Copy text length: 256 characters