Skip to content

create_deep_linked_url accepts 4-character bot usernames, but Telegram requires a minimum of 5 #5284

Description

@JSap0914

Bug Description

create_deep_linked_url validates bot_username with len(bot_username) <= 3, which means 4-character usernames are accepted without error.

However, the Telegram Bot documentation explicitly states:

Usernames are 5-32 characters long and not case sensitive – but may only include Latin characters, numbers, and underscores.

Steps to Reproduce

from telegram.helpers import create_deep_linked_url

# Should raise ValueError (4 chars < 5 minimum) but doesn't:
url = create_deep_linked_url("xbot", "payload")  
print(url)  # https://t.me/xbot?start=payload  ← silently wrong

Expected behaviour

create_deep_linked_url("xbot", "payload") should raise ValueError because "xbot" is only 4 characters, below Telegram's 5-character minimum.

Actual behaviour

No error is raised; the function returns a URL with an invalid username.

Root Cause

In src/telegram/helpers.py the guard is:

if bot_username is None or len(bot_username) <= 3:
    raise ValueError("You must provide a valid bot_username.")

The condition should be len(bot_username) < 5 (i.e., <= 4) to match Telegram's actual minimum of 5 characters.

The docstring also incorrectly states "less than 4 characters" instead of "less than 5 characters".

Operating System

Any

Version of Python, python-telegram-bot & dependencies

Any

Relevant log output

N/A

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Effort

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions