Base64 Transform Bot — Telegram Developer CLI Utility
Transform Base64 payloads, convert cURL commands to Python requests, normalize smart quotes, format JSON, and inspect YouTube metadata directly inside Telegram via @base64_transform_bot.

Technical Architecture: Reverse-Engineering @base64_transform_bot
Although originally named after its Base64 encoder, @base64_transform_bot evolved into a multi-command developer CLI inside Telegram. Each command operates as a stateless state-machine transition stored in context.user_data['mode'], allowing developers to switch modes once and pipe consecutive payloads without re-typing command prefixes.
[ Telegram Update ]
│
├──> Command Handler (/encode_base64, /curl_converter, /json_formatter, ...)
│ └── Set context.user_data['mode'] = command
│
└──> Message Handler (Filters.text & ~Filters.command)
├── Read active mode from context.user_data['mode']
├── Dispatch payload to pure transformation function:
│ ├── Base64 Codec (base64.b64encode / b64decode with padding repair)
│ ├── Smart Quote Normalizer (Unicode U+2018..U+201D -> ASCII 0x22)
│ ├── cURL Tokenizer (shlex.split -> Python requests AST builder)
│ ├── JSON Formatter (json.loads -> json.dumps(indent=2))
│ └── YouTube OEmbed / Watch Parser (thumbnail + metadata JSON)
└── Reply with monospace MarkdownV2 / HTML code block
1. Padding-Resilient Base64 Encoding & Decoding
Developers frequently copy Base64 strings from JWT segments or URL query parameters where trailing = padding characters are stripped or URL-safe alphabets (- and _) are used. The bot's codec normalizes URL-safe characters and restores modulo-4 padding before decoding:
import base64
def encode_text_to_base64(text: str) -> str:
return base64.b64encode(text.encode("utf-8")).decode("ascii")
def decode_base64_to_text(payload: str) -> str:
cleaned = payload.strip().replace("-", "+").replace("_", "/")
missing_padding = len(cleaned) % 4
if missing_padding:
cleaned += "=" * (4 - missing_padding)
raw_bytes = base64.b64decode(cleaned, validate=False)
return raw_bytes.decode("utf-8", errors="replace")
2. Smart Quote Normalization & JSON Pretty-Printing
When copying JSON payloads or CLI flags from rich-text editors (Notion, Slack, macOS Notes), ASCII straight quotes (" and ') are frequently mutated into typographic curly quotes (“, ”, ‘, ’), breaking JSON parsers. The bot exposes dedicated quote-replacement handlers alongside a strict JSON formatter:
import json
CURLY_QUOTE_MAP = str.maketrans({
"\u201c": '"', # Left double quotation mark
"\u201d": '"', # Right double quotation mark
"\u2018": '"', # Left single quotation mark
"\u2019": '"', # Right single quotation mark
"\u00ab": '"', # Left-pointing double angle quotation mark
"\u00bb": '"', # Right-pointing double angle quotation mark
})
def replace_curly_quotes(text: str) -> str:
return text.translate(CURLY_QUOTE_MAP)
def format_json_payload(raw_json: str) -> str:
normalized = replace_curly_quotes(raw_json.strip())
parsed = json.loads(normalized)
return json.dumps(parsed, indent=2, ensure_ascii=False)
3. POSIX Shell Tokenization for cURL-to-Python Conversion
When a user selects /curl_converter and pastes a raw curl command copied from Chrome DevTools (Copy as cURL), the handler tokenizes the shell string using Python's shlex.split to extract -H / --header pairs, -X method overrides, cookies, and --data / --data-raw bodies, emitting executable requests code:
import shlex
from urllib.parse import urlparse
def curl_to_python_requests(curl_command: str) -> str:
# Strip multiline backslash continuations before POSIX tokenization
normalized = curl_command.replace("\\\n", " ").replace("\\\r\n", " ").strip()
tokens = shlex.split(normalized)
method = "GET"
url = ""
headers = {}
data_payload = None
i = 0
while i < len(tokens):
token = tokens[i]
if token == "curl":
i += 1
continue
if token in ("-X", "--request") and i + 1 < len(tokens):
method = tokens[i + 1].upper()
i += 2
elif token in ("-H", "--header") and i + 1 < len(tokens):
header_line = tokens[i + 1]
if ":" in header_line:
k, v = header_line.split(":", 1)
headers[k.strip()] = v.strip()
i += 2
elif token in ("-d", "--data", "--data-raw", "--data-binary") and i + 1 < len(tokens):
data_payload = tokens[i + 1]
if method == "GET":
method = "POST"
i += 2
elif not token.startswith("-") and not url:
url = token
i += 1
else:
i += 1
lines = ["import requests", "", f'url = "{url}"']
if headers:
lines.append(f"headers = {repr(headers)}")
if data_payload is not None:
lines.append(f"data = {repr(data_payload)}")
call_args = ["url"]
if headers:
call_args.append("headers=headers")
if data_payload is not None:
call_args.append("data=data")
lines.append(f"response = requests.{method.lower()}({', '.join(call_args)})")
lines.append("print(response.status_code, response.text)")
return "\n".join(lines)
Command Reference & Capabilities Matrix
| Bot Command | Input Payload | Output Format | Browser Tool Equivalent |
|---|---|---|---|
/encode_base64 | Plain UTF-8 text string | Standard RFC 4648 Base64 string | — |
/decode_base64 | Standard or URL-safe Base64 string | Decoded UTF-8 text string | — |
/replace_curly_quotes | Text with smart/typographic quotes (“ ” ‘ ’) | Text normalized to ASCII straight double quotes (") | — |
/replace_single_quotes | Text or Python dict with single quotes (') | Text with double quotes (") for JSON compatibility | — |
/curl_converter | DevTools curl command string | Formatted Python requests snippet | — |
/json_formatter | Minified or unformatted JSON string | Pretty-printed JSON (2-space indentation) | — |
/youtube_thumbnail | YouTube watch or youtu.be URL | High-resolution maxresdefault.jpg photo reply | YouTube Toolkit |
/youtube_title | YouTube video URL | Extracted video title string | YouTube Toolkit |
/youtube_metadata | YouTube video URL | Structured OEmbed/watch metadata JSON | YouTube Toolkit |
Stateless Processing & Privacy Architecture
- In-Memory Execution: All string transformations, Base64 decoding, and
shlexAST parsing occur strictly in transient process memory without database logging of user payloads. - Session Isolation: Active command state (
context.user_data['mode']) is isolated per Telegramuser_idand cleared on process restart or/start.
Get notified about updates to this tool
No spam. Just high-quality updates about new features and guides.
Related Tools
Related Posts
Learn how to detect Google AdSense on any website using Python. Covers fast HTML scanning with BeautifulSoup, ads.txt validation, and headless Playwright automation to bypass bot protection and lazy loading.
Learn how to easily download YouTube video thumbnails using Python's requests library, without the need for heavy dependencies like Pytube. This guide covers extracting video IDs from various YouTube URL formats and fetching the highest quality thumbnail available.
This piece will introduce Make (formerly Integromat) as a direct competitor to n8n, highlighting its visual, diagram-like workflow builder. The comparison will focus on key differences in pricing models, UI/UX, and advanced features like branching logic, which are a major selling point for Make. Examples will show how to build the same complex workflow in both n8n and Make to illustrate their unique approaches.