E
E
Elick2021-11-04 17:12:06
Python
Elick, 2021-11-04 17:12:06

How to make only one request to pyTelegramBotAPI?

token='token'
bot=telebot.TeleBot(token)
@bot.message_handler(commands=['refresh'])
def ref_teleg(message):
    bot.send_message(chat.id, 'text')
bot.polling()


Is it possible to somehow make only one request, and not many (and continuously) like polling does?

My program should periodically check what is happening in the telegram, and then go on with "its own business", but because of polling, it will endlessly look at telegrams

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2021-11-04
@Elick

You can, send the one request you want, don't call polling.
If you want to get updates, there is a getUpdates method

S
Story teller, 2021-11-04
@Story teller

It works like this for me (I don't know how correct this implementation is):

async def send_message(message):
    await bot.send_message(chat_id, text=message)
loop = asyncio.get_event_loop()
loop.run_until_complete(send_message(message))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question