Below is a copy‑and‑paste, beginner‑friendly bot that will greet users, let them pick their language, and serve up concise educational nuggets about Bitcoin.
1. Prerequisites (1 minute)
python -m venv btc‑bot‑env
source btc‑bot‑env/bin/activate # Windows: btc‑bot‑env\Scripts\activate
pip install –upgrade python-telegram-bot==20.*
- Create a bot with @BotFather → grab the API token.
- Paste that token into the TOKEN = “YOUR_BOT_TOKEN_HERE” line in the code below.
- Run the file: python bitcoin_dual_lang_bot.py (polling mode—no webhooks needed).
2. The Code (save as
bitcoin_dual_lang_bot.py
)
#!/usr/bin/env python3
# ───────────────────────────────────────────────────────────
# Telegram Bitcoin Education Bot – English 🇬🇧 & Khmer 🇰🇭
# ───────────────────────────────────────────────────────────
import logging
from telegram import (
Update,
InlineKeyboardButton,
InlineKeyboardMarkup,
)
from telegram.ext import (
ApplicationBuilder,
CallbackContext,
CallbackQueryHandler,
CommandHandler,
)
TOKEN = “YOUR_BOT_TOKEN_HERE”
DEFAULT_LANG = “en”
# ———- Multilingual content bank ———-
CONTENT = {
“en”: {
“welcome”: (
“👋 *Hey there, future Bitcoin pro!* \n”
“Tap a button to switch languages or explore a topic:”
),
“help”: (
“🤖 *Bot menu*\n”
“/about – What _is_ Bitcoin?\n”
“/how – How does it work?\n”
“/why – Why might people use it?\n”
“/lang – Switch language”
),
“about”: (
“🪙 *What is Bitcoin?*\n”
“Bitcoin is a borderless, decentralised digital currency. “
“No company or country controls it; the network runs on thousands “
“of independent computers worldwide.”
),
“how”: (
“⚙️ *How does Bitcoin work?*\n”
“Transactions are bundled into ‘blocks’ and added to a public ledger—the “
“blockchain—secured by cryptography and global miners.”
),
“why”: (
“🌍 *Why use Bitcoin?*\n”
“• Permission‑less payments \n”
“• Fixed supply (21 million coins) \n”
“• Open to anyone with the internet”
),
“lang_btn”: “Switch to Khmer 🇰🇭”,
“lang_confirm”: “Language switched to *English* ✅”,
},
“km”: {
“welcome”: (
“👋 *សួស្តី! អ្នកត្រៀមខ្លួនក្លាយជាអ្នកជំនាញ Bitcoin ឬទៅ?* \n”
“ជ្រើសរើសភាសា ឬសាកសួរអំពីប្រធានបទខាងក្រោម:”
),
“help”: (
“🤖 *ម៉ឺនុយបូត*\n”
“/about – Bitcoin គឺជាអ្វី?\n”
“/how – វាដំណើរការយ៉ាងដូចម្តេច?\n”
“/why – មូលហេតុដែលមនុស្សប្រើវា?\n”
“/lang – ប្ដូរភាសា”
),
“about”: (
“🪙 *Bitcoin គឺជាអ្វី?*\n”
“Bitcoin គឺជាលុយឌីជីថលដែលមិនមានក្រុមហ៊ុន ឬប្រទេសណាក្នុងការគ្រប់គ្រង។ “
“វារត់លើបណ្តាញកុំព្យូទ័រដោយឯករាជ្យជាច្រើនទូទាំងពិភពលោក។”
),
“how”: (
“⚙️ *Bitcoin ដំណើរការយ៉ាងដូចម្តេច?*\n”
“ប្រតិបត្តិការត្រូវបានរៀបចំជា “ប្លុក” ហើយបន្ថែមចូលក្នុងកំណត់ត្រាសាធារណៈ—”
“blockchain—ដែលមានសុវត្ថិភាពដោយល្បែងវិចិត្រអក្ស និងមីន័រ។”
),
“why”: (
“🌍 *ហេតុអ្វីជ្រើសរៀបប្រើ Bitcoin?*\n”
“• បង់ប្រាក់ដោយគ្មានកំណត់ \n”
“• ផ្គត់ផ្គង់ថេរ (២១លានកាក់) \n”
“• អ្នកណាក៏អាចចូលរួមបាន ប្រសិនបើមានអ៊ីនធឺណិត”
),
“lang_btn”: “ប្ដូរទៅ English 🇬🇧”,
“lang_confirm”: “បានប្ដូរភាសាទៅ *Khmer* ✅”,
},
}
# ———————————————————-
# ———- Command handlers ———-
async def start(update: Update, context: CallbackContext.DEFAULT_TYPE) -> None:
user_lang = context.user_data.get(“lang”, DEFAULT_LANG)
await update.message.reply_text(
CONTENT[user_lang][“welcome”],
reply_markup=lang_keyboard(user_lang),
parse_mode=”Markdown”,
)
await help_cmd(update, context) # auto‐display help
async def help_cmd(update: Update, context: CallbackContext.DEFAULT_TYPE) -> None:
user_lang = context.user_data.get(“lang”, DEFAULT_LANG)
await update.message.reply_text(
CONTENT[user_lang][“help”], parse_mode=”Markdown”
)
async def about(update: Update, context: CallbackContext.DEFAULT_TYPE) -> None:
await send_topic(update, context, “about”)
async def how(update: Update, context: CallbackContext.DEFAULT_TYPE) -> None:
await send_topic(update, context, “how”)
async def why(update: Update, context: CallbackContext.DEFAULT_TYPE) -> None:
await send_topic(update, context, “why”)
async def send_topic(update: Update, context: CallbackContext.DEFAULT_TYPE, topic: str):
user_lang = context.user_data.get(“lang”, DEFAULT_LANG)
await update.message.reply_text(
CONTENT[user_lang][topic], parse_mode=”Markdown”
)
# ———- Language switch ———-
def lang_keyboard(current_lang: str) -> InlineKeyboardMarkup:
other_lang = “km” if current_lang == “en” else “en”
return InlineKeyboardMarkup(
[[InlineKeyboardButton(CONTENT[current_lang][“lang_btn”], callback_data=f”SET_LANG:{other_lang}”)]]
)
async def lang_switcher(update: Update, context: CallbackContext.DEFAULT_TYPE) -> None:
query = update.callback_query
await query.answer()
_, new_lang = query.data.split(“:”)
context.user_data[“lang”] = new_lang
await query.edit_message_text(
CONTENT[new_lang][“lang_confirm”], parse_mode=”Markdown”
)
# Show menu again
await query.message.reply_text(
CONTENT[new_lang][“welcome”],
reply_markup=lang_keyboard(new_lang),
parse_mode=”Markdown”,
)
# ———- Main autoboot ———-
def main() -> None:
logging.basicConfig(
format=”%(asctime)s | %(name)s | %(levelname)s | %(message)s”,
level=logging.INFO,
)
app = (
ApplicationBuilder()
.token(TOKEN)
.build()
)
# Core commands
app.add_handler(CommandHandler(“start”, start))
app.add_handler(CommandHandler(“help”, help_cmd))
app.add_handler(CommandHandler(“about”, about))
app.add_handler(CommandHandler(“how”, how))
app.add_handler(CommandHandler(“why”, why))
app.add_handler(CallbackQueryHandler(lang_switcher, pattern=r”^SET_LANG:”))
logging.info(“🚀 Bot is up and running. Press Ctrl+C to stop.”)
app.run_polling()
if __name__ == “__main__”:
main()
3. How it works (happy‑dance version 🕺)
| Stage | What happens | 🎉 Why it’s cool |
| /start | Greets user in default English, plus an inline button to swap languages. | Instant bilingual friendliness—no commands needed! |
| Inline button | CallbackQueryHandler flips user_data[“lang”] and edits the message. | Snappy UX, keeps chat tidy. |
| /about, /how, /why | Deliver succinct lessons drawn from the CONTENT dict in the caller’s language. | Keeps logic super‑simple—easy to expand topics later. |
| /lang (optional) | /lang shows the same buttons if people prefer commands over taps. | Accessibility FTW. |
4. Next steps when you’re ready to level‑up
- Add live price data—hit CoinGecko’s free API and inject numbers into the messages.
- Drop in pictures/GIFs for visual learners (Telegram supports Markdown‑V2 and HTML).
- Gamify with quizzes or streak counts to keep learners pumped.
- Deploy 24/7—switch from polling to a webhook + a cheap VPS or serverless function.
✨ Boom! You now have a cheerful, hype‑driven, bilingual Bitcoin educator ready to roll.
Fire it up, invite friends, and watch the orange‑coin knowledge spread across borders! 🌏🧡