-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript02.py
90 lines (68 loc) · 2.66 KB
/
script02.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
"""
Example telegram bot created using telebot library.
"""
import webbrowser
import telebot
from decouple import config
from telebot import types
TOKEN = config("TELEGRAM_BOT_TOKEN")
bot = telebot.TeleBot(TOKEN)
@bot.message_handler(commands=["start"])
def start(message):
markup = types.ReplyKeyboardMarkup()
languages = [
types.KeyboardButton("English"),
types.KeyboardButton("Russian"),
types.KeyboardButton("Uzbek"),
]
markup.add(*languages)
bot.send_message(
message.chat.id, f"Hello! {message.from_user.first_name}", reply_markup=markup
)
bot.register_next_step_handler(message, on_click)
def on_click(message):
if message.text == "English":
bot.send_message(message.chat.id, "You selected English language.")
elif message.text == "Russian":
bot.send_message(message.chat.id, "You selected Russian language.")
@bot.message_handler(commands=["help"])
def help_(message):
bot.send_message(message.chat.id, "Help message...")
@bot.message_handler(commands=["site"])
def site(message):
webbrowser.open("https://www.google.com/")
@bot.message_handler(content_types=["text"])
def echo(message):
if message.text.strip().lower() == "debug":
bot.send_message(message.chat.id, message, parse_mode="HTML")
bot.send_message(message.chat.id, message.text)
@bot.message_handler(content_types=["photo"])
def photo(message):
markup = types.InlineKeyboardMarkup()
button1 = types.InlineKeyboardButton(text="Button 1", callback_data="button1")
button2 = types.InlineKeyboardButton(text="Button 2", callback_data="button2")
button3 = types.InlineKeyboardButton(
text="Open Google", url="https://www.google.com/"
)
delete_button = types.InlineKeyboardButton(text="Delete", callback_data="delete")
edit_button = types.InlineKeyboardButton(text="Edit", callback_data="edit")
markup.add(
button1, button2, button3, delete_button, edit_button
) # markup.row(button1, button2, button3)
bot.reply_to(message, "Photo received!", reply_markup=markup)
@bot.callback_query_handler(func=lambda call: True)
def callback(call):
"""
Handling photo message handler.
"""
if call.data == "button1":
bot.send_message(call.message.chat.id, "Button 1 pressed!")
elif call.data == "button2":
bot.send_message(call.message.chat.id, "Button 2 pressed!")
elif call.data == "delete":
bot.delete_message(call.message.chat.id, call.message.message_id)
elif call.data == "edit":
bot.edit_message_text(
"Edited message", call.message.chat.id, call.message.message_id
)
bot.polling(non_stop=True)