Telegram Bot Load Testing with k6: Messages Being Sent Instead of Received During Testing

I need help with testing my Telegram bot using k6. I want to simulate many users sending messages to my bot at the same time to see how well it performs. The problem is that my bot keeps sending messages to me instead of getting the messages I’m trying to send during the test.

I’m using the Telegram Bot API with the right token and chat ID, but something is wrong. When I run my k6 test, the bot just sends messages back to the chat rather than receiving and handling them properly.

What I want to do is test how my bot responds when lots of virtual users send it messages at once. But right now it’s doing the opposite of what I need.

import http from 'k6/http';
import { check, sleep } from 'k6';

const botToken = 'YOUR_TELEGRAM_BOT_TOKEN';
const targetChatId = 'YOUR_TARGET_CHAT_ID';
const apiEndpoint = `https://api.telegram.org/bot${botToken}/sendMessage`;

export let options = {
  vus: 15,
  duration: '45s',
};

export default function () {
  const messageData = JSON.stringify({
    chat_id: targetChatId,
    text: 'Load testing message from k6',
  });

  const requestParams = {
    headers: {
      'Content-Type': 'application/json',
    },
  };

  const response = http.post(apiEndpoint, messageData, requestParams);

  check(response, {
    'request completed': (r) => r.status === 200,
  });

  sleep(2);
}

You’re testing the wrong thing entirely. Your script uses sendMessage, which makes your bot send messages out - but you need to test users sending messages TO your bot. There’s no API endpoint to fake incoming user messages. Telegram’s Bot API only lets your bot send messages, not receive them for testing. Instead, load test your webhook endpoint directly. If your bot gets messages via webhook, point k6 at your webhook URL and fire POST requests with the same JSON structure Telegram sends. That’s how you actually test your bot’s message processing under load, which is what you really care about for performance testing.

yep, i think ur using the wrong endpoint. the sendMessage is for sending msgs to the bot, not from users. u gotta check webhooks or maybe getUpdates to simulate real user msgs. that’ll give u a better test scenario!

Had this exact problem load testing my bot last year. You’re hitting Telegram’s API to send messages, but that’s not what you need - you need to simulate incoming messages hitting your bot’s logic. I bypassed Telegram completely and tested my webhook handler directly. Made mock payloads that matched Telegram’s webhook format and fired them at my bot’s webhook URL with k6. Got real performance data on how my bot handles message processing, database ops, and response generation under load. Grab Telegram’s webhook payload structure from their docs, wrap that JSON in your k6 requests, and point them at your actual bot endpoint. Way more realistic than using sendMessage, which doesn’t test your bot’s core functionality anyway.