'How to do a knock knock test on a telegram bot

I have a set of telegram bots that are running 24/7 but I'd like to make sure they are actually responding. How could I write something that would send something like "knock, knock" and get back a "Who's there?" response to monitor the health of the bots.

I can't use another bot to do this work because bots are not allowed to talk to one another. So, how do I pull this off?

I'd prefer it be done in python but at this point I'd just like something that could report a status. My goal is to feed this in django-healthcheck custom checker. I have about 80 bots I need to check with more being added every day or two.

I was thinking I could do it with tdlib but the sendMessage API requires a chatID and all I have is a botName. Also, none of the bots I've connected with on my phone showed up in the tdlib list of contacts.....



Solution 1:[1]

You should use a user account and communicate with those bots using an MTProto library, like Pyrogram or Telethon.

Many people do this by sending a message to the bot with the user account, and waiting for a response, but this is tricky and I do not recommend it. It can risk your account to get banned or face floodwaits if done constantly.

Instead, I recommend your bot to ping a user account every 30 seconds or something around it, and do something like this in your user account code:

from time import time
from typing import Optional

from pyrogram import Client, filters

last_ping: Optional[float] = None

@Client.message_handler(filters.username("@YourBot") & filters.private & ~ filters.reply & filters.regex("^ping$"))
async def update_status():
    global last_ping
    last_ping = time()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 roj1512