I created a Telegram bot with python-telegram-bot to reply to channel posts, but it never responds. Below is a revised code sample:
async def on_channel_update(update, ctx):
try:
message = update.channel_post if update.channel_post else update.message
if not message or message.chat.username != channel_id:
return
msg_id = message.message_id
chat_id = message.chat.id
link_text = f"Message ID: {msg_id}"
reply = f"View message: {link_text}"
await ctx.bot.send_message(chat_id=chat_id, text=reply, reply_to_message_id=msg_id)
except Exception as error:
print('Error processing update:', error)
async def launch_bot():
TOKEN = "YOUR_BOT_TOKEN"
channel_id = "YourChannelName"
bot_instance = CustomBot(TOKEN, channel_id)
await bot_instance.run()