Is my Python Telegram bot's response time excessively slow?

My Python Telegram bot’s response time is unexpectedly slow (6–8 seconds). What may cause this delay and how can I enhance it? Can webhooks help? See alternate code below:

import requests
import time

API_KEY = 'ABCXYZ:1234567890'
BASE = f'https://api.telegram.org/bot{API_KEY}'
next_id = 0

while True:
    time.sleep(0.1)
    reply = requests.get(f'{BASE}/getupdates?offset={next_id}').json()
    if reply.get('result'):
        text_msg = reply['result'][0]['message']['text']
        print(text_msg)
        if text_msg == 'Hello':
            requests.get(f'{BASE}/sendmessage?chat_id=987654321&text=Hello there')
        next_id = reply['result'][0]['update_id'] + 1

The delay you’re encountering appears to originate from using a polling mechanism with synchronous HTTP requests. In my experience, continuously polling the Telegram API with a time.sleep interval can accumulate small delays that add up, especially under fluctuating network conditions. I switched to using webhooks in one of my projects to trigger events immediately and it significantly reduced response time. Moreover, adopting asynchronous programming patterns can help manage tasks more efficiently, ensuring that your bot handles messages promptly without waiting on blocking calls.