B
B
brandn2021-08-30 03:56:15
Telegram
brandn, 2021-08-30 03:56:15

How to create a telegram bot that will search for data on request?

All the best

, the essence is this, there is a table in which a

person enters the data of the client base to the bot the last 4 digits of the phone number, and the bot sends him data based on the table, such as:

Surname
Phone number (in full)
Address
Amount

in words it seems clear, but in reality it got stuck

I will be glad for your help

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan Mandzyuk, 2021-08-30
@Ryslan_13

This is a finished bot that worked for me

from aiogram import Bot, Dispatcher, executor, types
import openpyxl

TOKEN = "Ваш токен"

book = openpyxl.open("Имя вашего exl файла", read_only=True)
shet = book.active

bot = Bot(TOKEN)
dp = Dispatcher(bot)

@dp.message_handler()
async def bot_start(message: types.Message):
  for ino in shet:
    surname_ = ino[0].value
    number_ = str(ino[1].value)
    addresses_ = ino[2].value
    sum_ = ino[3].value

    if message.text in number_:
      await bot.send_message(message.chat.id, f'Фамилия: {surname_}\nНомер телефона: {number_}\nАдрес: {addresses_}\nСумма: {sum_}')

if __name__ == '__main__':
  executor.start_polling(dp, skip_updates=True)

I don't know exactly how (if, in) works, but it probably finds matches every subsequent character.
if message.text in number_:
      await bot.send_message(message.chat.id, f'Фамилия: {surname_}\nНомер телефона: {number_}\nАдрес: {addresses_}\nСумма: {sum_}')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question