T
T
tokyodead2021-07-14 07:14:38
Python
tokyodead, 2021-07-14 07:14:38

Function for telegram bot in python?

Good afternoon, tell me, I’m writing a bot for telegrams, I’m new to this and I can’t figure out how to make it so that if this is help # 1 send him one help, and if this is help # 2 send him another help?
Here is the code

bot = telebot.TeleBot(TOKEN)

@bot.message_handler(commands=['start'])
def start(message):
    markup = types.ReplyKeyboardMarkup(resize_keyboard = True)
    item1 = types.KeyboardButton('Заказать справку')
    markup.add(item1)
    bot.send_message(message.chat.id, 'Вас приветствует бот myboy', reply_markup=markup)

@bot.message_handler(content_types=['text'])
def bot_message(message):
    if message.chat.type == 'private':
        if message.text == 'Заказать справку':
            markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
            item1 = types.KeyboardButton('Справка#1')
            back = types.KeyboardButton('Назад')
            markup.add(item1, back)
            bot.send_message(message.chat.id, 'Какая справка Вам нужна?', reply_markup=markup)

        elif message.text == 'Справка#1':
            bot.send_message(message.chat.id, 'Введите ИИН')

        elif message.text.isdigit and len(message.text) == 12:
            with con:
                cur = con.cursor()
                sql = "SELECT `fullname` FROM `bot_db` WHERE `iin`=%s and status=1 and user_type=1 limit 1 "
                cur.execute(sql, (message.text,))
                result = cur.fetchone()
                name = result
                age = '1997-01-08'
                page_name = str(name) + '.pdf'
                get_pdf(name,age, page_name)
                bot.send_message(message.chat.id, result)
                r = open('C:\\Users\\Alkon PC\\PycharmProjects\\mainpy\\{}'.format(page_name), 'rb')
                bot.send_document(message.chat.id, r)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Krostelev, 2021-07-14
@tokyodead

You need to get familiar with register_next_step_handler , it will make life a bit easier on your task. If I understand correctly, the catch is that both certificates require a TIN and you need to somehow remember for which reference the TIN is now expected from the user. register_next_step_handler will help you. Look for examples, try. If something does not work out - throw off the code here, we will look.
I also advise you to study the work with Inline buttons, with them more opportunities will open up.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question