import telebot # Token provided by BotFather bot = telebot.TeleBot("insert_your_token_here") # Send a message to the user with user_id bot.send_message(user_id, "Hello from bot!")
import telebot bot = telebot.TeleBot("insert_your_token_here") @bot.message_handler(content_types=['text']) def echo_message(message): bot.reply_to(message, message.text) bot.polling()
import telebot from telebot import types bot = telebot.TeleBot("insert_your_token_here") @bot.message_handler(commands=['start']) def send_welcome(message): markup = types.InlineKeyboardMarkup() btn_a = types.InlineKeyboardButton('Option A', callback_data='a') btn_b = types.InlineKeyboardButton('Option B', callback_data='b') markup.add(btn_a, btn_b) bot.send_message(message.chat.id, "Choose an option:", reply_markup=markup) @bot.callback_query_handler(func=lambda call: True) def callback_query(call): bot.answer_callback_query(call.id, f"You selected {call.data}") bot.polling()This code creates an inline keyboard with two options and sends it to the user when they type /start command. When the user selects an option, the bot responds with a message containing the selected option. The `InlineKeyboardMarkup` class is used to create the keyboard, while `callback_query_handler()` is used to handle the user's selection. The library used in these examples is `python-telegram-bot`.