Introducing Livops 2.0! Promo codeCEOgives you 8,000 so‘m on your balance.What’s new

Telegram 403: Forbidden: bot can't initiate conversation with a user — how to fix it

Telegram bots cannot write first. The user you are sending to has never started a private chat with your bot: you got their id from a group, a shared contact or another system, not from their own /start. Send them your bot's t.me link with a start parameter, save their chat id when the /start arrives, and on this 403 mark the user as unreachable instead of retrying.

By Livops team, the people who build and run LivopsUpdated

The error, as the Telegram Bot API returns it with error code 403[6][7]:

Forbidden: bot can't initiate conversation with a user

Each library wraps it in its own words:

Library What you see
aiogram 3 TelegramForbiddenError: Telegram server says - Forbidden: bot can't initiate conversation with a user[8][9]
python-telegram-bot telegram.error.Forbidden: Forbidden: bot can't initiate conversation with a user[10][11]
grammY GrammyError: Call to 'sendMessage' failed! (403: Forbidden: bot can't initiate conversation with a user)[12]
Telegraf TelegramError: 403: Forbidden: bot can't initiate conversation with a user[13]

This page explains the rule behind the error, how it differs from chat not found and bot was blocked by the user, where the ids that cause it usually come from, and how to get users to start the bot, store their chat id at the right moment, and handle the 403 — on any host, and on Livops.

What does the error mean?

Telegram’s rule is short: bots can’t start conversations with users. A user must either add the bot to a group or send it a message first; people find a bot by its username or open it through its t.me/bot_username link[1].

The error is that rule enforced. The Bot API runs on top of Telegram’s tdlib library[5]. When a bot sends to a user it has no conversation with, Telegram rejects the peer, and tdlib reports the rejection for a bot writing to a user as 403 Bot can't initiate conversation with a user[6]. The Bot API server adds the Forbidden: prefix and lowercases the first letter[7], which gives the message above.

Nothing is broken and the id may be perfectly correct. The user simply has not started your bot yet.

How it differs from the errors next to it

Three errors show up when a bot cannot write to a person, and each asks for a different fix:

Error What it means What to do
Bad Request: chat not found (400) The Bot API server cannot find that chat for this bot at all, or the target is a person’s @username[7] Fix the id or the token — see chat not found
Forbidden: bot can't initiate conversation with a user (403) The user exists, but has never started a conversation with this bot[1][6] Get the user to press Start, then send
Forbidden: bot was blocked by the user (403) The user did start the bot, and later blocked it[3][7] Mark them inactive until they unblock — see bot was blocked by the user

The last two look alike in a broadcast log, and both mean “skip this user for now”. The difference is in what you can do next: a blocked user has to unblock the bot, while a user who never started it only has to open it once. Telegram tells the bot when a user blocks or unblocks it, with a my_chat_member update in the private chat[3]; there is no such update for a user who simply never came.

Where the ids that cause it come from

1. Group members

The bot sees a user in a group — they sent a command, joined, or were mentioned — and the code saves from.id and later sends a private message to it. The id is real, but a group is not a private conversation, so the send fails until the user opens the bot.

2. Users and contacts shared with the bot

A user can pick other people with a request_users button, or send a contact card. The ids that arrive are real Telegram user ids[3], but the Bot API warns that for a shared user “the bot may not have access to the user”, unless the bot already knows them some other way[3]. A shared Contact may carry the person’s user_id[3]. Neither turns into a conversation with that person.

3. Ids from outside Telegram

A sign-up form, a CRM, an import from another bot, or an id a user typed in. Even when the number is right, this bot has never talked to that person.

4. Phone numbers and usernames

The Bot API has no way to send to a phone number: chat_id is a numeric id, or an @username of a bot, supergroup or channel[3]. A person’s @username fails earlier, with chat not found[7]. Either way, the fix is the same as here: the person has to start the bot, and you use the chat id that start gives you.

How to fix it

Every bot has a link that opens a chat with it, https://t.me/<bot_username>, and you can add a start parameter to it[2]:

https://t.me/your_bot?start=order_1842

When someone opens the chat through that link, the bot receives /start order_1842[2]. The parameter may use A-Z, a-z, 0-9, _ and -, up to 64 characters; base64url is recommended for anything else[2]. Use it to tie the Telegram user to whatever brought them — an order, a sign-up, an account on your site — and then send them the message you could not send before.

Put the link where the person already is: on your site after a form, in an email, or as a button in the group the bot shares with them. In a group, ?startgroup= is a different thing — it asks the user to pick a group to add the bot to[2].

Save the chat id when /start arrives

Only an id that arrived in a private chat with the bot is an id you can write to. Save it there:

aiogram 3:

from aiogram import Router
from aiogram.filters import CommandObject, CommandStart
from aiogram.types import Message

router = Router()


@router.message(CommandStart())
async def start(message: Message, command: CommandObject) -> None:
    await save_user(
        user_id=message.from_user.id,
        chat_id=message.chat.id,
        payload=command.args,  # "order_1842", or None
    )
    await message.answer("You're in. We'll message you here.")

python-telegram-bot:

from telegram import Update
from telegram.ext import CommandHandler, ContextTypes


async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
    payload = context.args[0] if context.args else None
    await save_user(
        user_id=update.effective_user.id,
        chat_id=update.effective_chat.id,
        payload=payload,
    )
    await update.message.reply_text("You're in. We'll message you here.")


app.add_handler(CommandHandler("start", start))

A table for it, in PostgreSQL:

CREATE TABLE users (
  user_id     BIGINT PRIMARY KEY,
  chat_id     BIGINT,           -- set only by /start
  started_at  TIMESTAMPTZ,
  inactive_at TIMESTAMPTZ       -- set on a 403, cleared on the next /start
);

Ids can have more than 32 significant bits, at most 52[5], so keep them as BIGINT. Send only to rows where chat_id is set and inactive_at is empty.

Or ask for permission to write

Two other ways give the bot the right to message a user without a /start[3][4]:

  • A Mini App can call requestWriteAccess, which shows a native popup asking the user to let the bot message them. WebAppUser.allows_write_to_pm is true for a user who already did[4].
  • A login button (LoginUrl) can pass request_write_access: true to ask for the same permission[3].

When a user grants it from a Mini App, the bot receives a write_access_allowed service message in its chat with them[3]: save the chat id from it as you would from /start.

Handle the 403: mark the user, do not retry

The error does not go away on retry. Catch it, record it, and move on — the same handling as for a blocked user. Every library raises a 403 as its own error type:

aiogram 3 — TelegramForbiddenError[8][9]:

from aiogram.exceptions import TelegramForbiddenError

try:
    await bot.send_message(chat_id, text)
except TelegramForbiddenError as e:
    await mark_inactive(chat_id, reason=e.message)

python-telegram-bot — telegram.error.Forbidden[10][11]:

from telegram.error import Forbidden

try:
    await bot.send_message(chat_id, text)
except Forbidden as e:
    await mark_inactive(chat_id, reason=e.message)

grammY — a GrammyError with error_code 403[12]:

import { GrammyError } from "grammy";

try {
  await bot.api.sendMessage(chatId, text);
} catch (err) {
  if (err instanceof GrammyError && err.error_code === 403) {
    await markInactive(chatId, err.description);
  } else {
    throw err;
  }
}

Telegraf — a TelegramError with code 403[13]:

const { TelegramError } = require('telegraf');

try {
  await telegram.sendMessage(chatId, text);
} catch (err) {
  if (err instanceof TelegramError && err.code === 403) {
    await markInactive(chatId, err.description);
  } else {
    throw err;
  }
}

Keep the description in the row. bot can't initiate conversation tells you to send the user a link; bot was blocked by the user tells you to wait for them to unblock. When the user’s /start or first message arrives, clear inactive_at.

On Livops

Livops does not change who your bot may write to; the rule is Telegram’s, and the handling above is in your code. What Livops gives you is the place to run it:

  • The bot as a service. A Telegram bot is its own service type, bot: always running, no public URL needed. Its /start handler and the 403s it logs are on the project’s Logs page and in the terminal with livops logs <service> -f.
  • The users table in PostgreSQL. Add PostgreSQL under Databases, and DATABASE_URL is written into every service in the environment, including services added later. Keep the chat ids from /start there; a broadcast sender in another service of the same environment reads the same table.
  • Staging starts empty. A new environment such as staging gets its own empty database for each database type in production; no data is copied. Its bot has no saved chat ids until users press Start there.
  • A broadcast as a worker. A sender that only reads the table and sends can run as a worker service: an always-on background process with no public URL. See Cron and workers.

A bot or worker costs 19 credits a month (19,000 so’m). One 500 MB database per team is free; see Pricing.

Questions

Can a Telegram bot send the first message to a user?

No. Bots cannot start conversations with users. The user has to send the bot a message, press Start, or add it to a group first. Until then, a message to that user fails, usually with this 403.

The user is in my group with the bot. Why can't the bot message them privately?

Because being in the same group is not a private conversation. The bot can answer the user in the group, but a private message needs the user to open the bot and press Start. Post the bot's t.me link with a start parameter in the group.

Can I message a user by their phone number or username?

No. The Bot API takes a numeric chat id, or an @username only for a bot, a supergroup or a channel. A person's @username or phone number cannot be used, and fails earlier with Bad Request: chat not found.

How is this different from bot was blocked by the user?

Blocked means the user did start the bot and later blocked it. Can't initiate means the user never started a conversation with it at all. Both are 403s, and both are handled the same way in a broadcast: skip the user and stop retrying.

Will retrying later help?

Only after the user writes to the bot. Nothing on your side changes the answer, so mark the user as unreachable and send again when their /start or first message arrives.

Can a Mini App or a login button give my bot permission to write?

Yes. A Mini App can call requestWriteAccess, and a login button can set request_write_access. When a user grants it from a Mini App, the bot also gets a write_access_allowed service message with their chat.

Where do I keep track of who started the bot?

In a database table: one row per user, with the chat id saved in the /start handler and a column for when sends stopped working. Send only to rows that have a chat id and no such mark.

Sources

  1. Telegram — Bots, an introduction for developers (core.telegram.org). Checked .
  2. Telegram — Bot features (deep linking, chat and user selection) (core.telegram.org). Checked .
  3. Telegram Bot API — sendMessage, Update, UsersShared, Contact, WriteAccessAllowed, LoginUrl (core.telegram.org). Checked .
  4. Telegram Mini Apps — requestWriteAccess, WebAppUser (core.telegram.org). Checked .
  5. Telegram — Bot API dialog IDs (core.telegram.org). Checked .
  6. TDLib source — td/telegram/MessageQueryManager.cpp (raw.githubusercontent.com). Checked .
  7. Telegram Bot API server source — telegram-bot-api/Client.cpp (raw.githubusercontent.com). Checked .
  8. aiogram source — aiogram/exceptions.py (raw.githubusercontent.com). Checked .
  9. aiogram source — aiogram/client/session/base.py (raw.githubusercontent.com). Checked .
  10. python-telegram-bot source — telegram/error.py (raw.githubusercontent.com). Checked .
  11. python-telegram-bot source — telegram/request/_baserequest.py (raw.githubusercontent.com). Checked .
  12. grammY source — src/core/error.ts (raw.githubusercontent.com). Checked .
  13. Telegraf source — src/core/network/error.ts (raw.githubusercontent.com). Checked .

Put your project online today

Connect GitHub or drop a folder. No card is asked for.

Deploy your bot

Got a question? — @livops_uz