From d6d85a663010cbdf1c0f35037df862a973343325 Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 26 Apr 2016 19:02:52 +0400 Subject: [PATCH] Create bot20-example.py --- examples/bot20-example.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 examples/bot20-example.py diff --git a/examples/bot20-example.py b/examples/bot20-example.py new file mode 100644 index 0000000..fd907e6 --- /dev/null +++ b/examples/bot20-example.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +import telebot +from telebot import types +bot = telebot.TeleBot('your bot token') + +@bot.callback_query_handler(func=lambda call: True) +def callback(call): + if call.data == "{usd}": + answer = 'Success USD' + kb = types.InlineKeyboardMarkup() + kb.add(types.InlineKeyboardButton("Success USD", callback_data='{usd}')) + bot.edit_message_text(text=answer, message_id=call.message.message_id, chat_id=call.message.chat.id, parse_mode="HTML", reply_markup=kb) + if call.data == "{eur}": + answer = "Success EUR" + kb = types.InlineKeyboardMarkup() + kb.add(types.InlineKeyboardButton("Success EUR", callback_data='{eur}')) + bot.edit_message_text(text=answer, message_id=call.message.message_id, chat_id=call.message.chat.id, parse_mode="HTML", reply_markup=kb) +@bot.message_handler(content_types=['text']) +def main(message): + if message.text == "/test": + cid = message.chat.id + markup = types.InlineKeyboardMarkup() + usd = types.InlineKeyboardButton(text="USD", callback_data="{usd}") + eur = types.InlineKeyboardButton(text="EUR", callback_data="{eur}") + markup.row(usd, eur) + bot.send_message(cid, "Choose one currency:", reply_markup=markup) + else: + cid = message.chat.id + bot.send_message(cid, "That command doesnt exist") +bot.polling(none_stop=True, interval=0)