Using Python Telegram Bot in Python 3, my bot sends messages but the typing indicator never appears. See this revised code example:
import telegram
from telegram.ext import Updater, CommandHandler
def handle_message(update, context):
context.bot.send_chat_action(chat_id=update.effective_chat.id, action=telegram.ChatAction.TYPING)
context.bot.send_message(chat_id=update.effective_chat.id, text='Hello there!')
updater = Updater('YOUR_TOKEN_HERE')
updater.dispatcher.add_handler(CommandHandler('start', handle_message))
updater.start_polling()
hey, try schedulin a brief delay between send_chat_action and send_message. sometimes the msg goes out to fast which cancels the typin indicator. use context.job_queue or async sleep to give it time to appear.
It appears that the typing indicator might be suppressed if the send_message method is executed immediately after the send_chat_action call. In my experience, ensuring a proper delay even of a fraction of a second can help. In one project, I experimented by separating the two calls into distinct functions, using an asynchronous call to ensure the indicator had time to display. Also, verifying that you are using the correct chat action constant and that your library version supports it was key. Incremental testing often reveals minor timing issues that might not be obvious at first glance.
I encountered a similar issue and discovered that the immediate execution of send_message after send_chat_action might be overwhelming the chat interface. In my experience, inserting a brief pause before sending the actual message allowed the typing indicator enough time to be perceived by the user. I experimented with a more controlled delay using a job queue method, and in some cases, even a time.sleep of just a few hundred milliseconds made a noticeable difference. This approach helps in ensuring that the typing action is transmitted and displayed properly on both client and server ends.
hey, maybe try using an async sleep instead of time.sleep, as time.sleep might block other events. adding a brief await asyncio.sleep(0.5) sometimes gives enuff time for the typin indicator to show. also, check your version match docs.