Вы находитесь на странице: 1из 5

telegram bot - Python Telebot (PyTelegramBotAPI) - Stack Overflow... https://ru.stackoverflow.com/questions/1347582/python-telebot-pytel...

1/5 03/09/2022, 18:36


telegram bot - Python Telebot (PyTelegramBotAPI) - Stack Overflow... https://ru.stackoverflow.com/questions/1347582/python-telebot-pytel...

В чем нужна помощь

Рад знакомству с тобой


(введенное имя) Рад
знакомству с тобой (опросник/помощь/итд)

from telebot import types

bot = telebot.TeleBot('токен')

@bot.message_handler(commands=['start'])
def start(message):
send_mess = f"<b>Привет, я твой личный помощник</b>!\n What's your name?"
bot.send_message(message.chat.id, send_mess, parse_mode='html')

@bot.message_handler(content_types=['text'])
def get_text_messages(message):
grt = 'Рад знакомству с тобой'
bot.send_message(message.chat.id, grt + ' ' + message.text)

@bot.message_handler(content_types=['text'])
def mess(message):
markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=3)
btn1 = types.KeyboardButton('Опросники')
btn2 = types.KeyboardButton('Помощь')
btn3 = types.KeyboardButton('Плюшки')
btn4 = types.KeyboardButton('Фидбек')
btn5 = types.KeyboardButton('FAQ')
markup.add(btn1, btn2, btn3, btn4, btn5)
send_mess = f"<b>Выбери подходящий вариант</b>"
bot.send_message(message.chat.id, send_mess, parse_mode='html',
reply_markup=markup)

@bot.message_handler(content_types=['text'])
def mess(message):
get_message_bot = message.text.strip().lower()

if get_message_bot == "начать тест заново":


markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=3)
btn1 = types.KeyboardButton('Опросники')
btn2 = types.KeyboardButton('Помощь')
btn3 = types.KeyboardButton('Плюшки')
btn4 = types.KeyboardButton('Фидбек')
btn5 = types.KeyboardButton('FAQ')
markup.add(btn1, btn2, btn3, btn4, btn5)
final_message = "Решил попробовать что-то ещё? \nВыбери какое направление тебя
интересует:"

elif get_message_bot == "опросники":

2/5 03/09/2022, 18:36


telegram bot - Python Telebot (PyTelegramBotAPI) - Stack Overflow... https://ru.stackoverflow.com/questions/1347582/python-telebot-pytel...

markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=3)


btn1 = types.KeyboardButton('1')
btn2 = types.KeyboardButton('2')
markup.add(btn1, btn2)
final_message = "текст"
else:
markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=3)
btn1 = types.KeyboardButton('Опросники')
btn2 = types.KeyboardButton('Помощь')
btn3 = types.KeyboardButton('Плюшки')
btn4 = types.KeyboardButton('Фидбек')
btn5 = types.KeyboardButton('FAQ')
markup.add(btn1, btn2, btn3, btn4, btn5)
final_message = "Так, так, так\nПостой, лучше нажми на одну из интерактивных
кнопок ниже"
bot.send_message(message.chat.id, final_message, parse_mode='html',
reply_markup=markup)

bot.polling(none_stop=True)

3/5 03/09/2022, 18:36


telegram bot - Python Telebot (PyTelegramBotAPI) - Stack Overflow... https://ru.stackoverflow.com/questions/1347582/python-telebot-pytel...

import telebot
from telebot import types

bot = telebot.TeleBot('')

markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=3)


btn1 = types.KeyboardButton('Опросники')
btn2 = types.KeyboardButton('Помощь')
btn3 = types.KeyboardButton('Плюшки')
btn4 = types.KeyboardButton('Фидбек')
btn5 = types.KeyboardButton('FAQ')
markup.add(btn1, btn2, btn3, btn4, btn5)

markup2 = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=3)


btn1 = types.KeyboardButton('1')
btn2 = types.KeyboardButton('2')
markup2.add(btn1, btn2)

@bot.message_handler(commands=['start'])
def start(message):
username = message.from_user.username
bot.send_message(message.chat.id, "Let`s start!", reply_markup=markup)
send_mess = f"Привет, {username}! Я твой личный помощник!"
bot.send_message(message.chat.id, send_mess, reply_markup=markup)

def mess(message):
send_mess = "Выбери подходящий вариант"
bot.send_message(message.chat.id, send_mess, reply_markup=markup)

@bot.message_handler(func=lambda message: message.text =='начать тест заново')


def foo(message):
final_message = "Решил попробовать что-то ещё? \nВыбери какое направление тебя
интересует:"
bot.send_message(message.chat.id, final_message, reply_markup=markup)

@bot.message_handler(func=lambda message: message.text =="Опросники")


def foo(message):
final_message = "текст"
bot.send_message(message.chat.id, final_message, parse_mode='html',
reply_markup=markup2)

bot.polling(none_stop=True)

582

4/5 03/09/2022, 18:36

Вам также может понравиться