skip to Main Content

I have subscribed to a telegram bot (I am not the owner/admin of that bot) which sends messages in a particular format. I need to do is to parse the incoming messages and used the parsed information as parameters to a trading API.

Hence, I need a daemon sort of thing which runs on my laptop and keeps listening for any new messages from that bot, and when it receives one, then parse it.

Can the Telegram Bot API handle this? In other words if I create a bot will it be able to read the messages sent to me by the other bot

2

Answers


  1. You can do it using python and python-telegram-bot package.
    When you create a bot in your python code using the following code:

    bot = telegram.Bot("Your bot's token")
    

    you are able to get the new messages sent to your bot using bot.get_updates() and there’s a feature to check if the sent message is from a bot or not. You can write a function that returns a boolean telling whether is the message sender bot or not:

    def is_bot(update=dict()): #"update" is one of the messages which got returned from get_updates()
        message = update["message"].to_dict()
        return message["from"]["is_bot"]
    
    
    for update in bot.get_updates():
        print(is_bot(update))
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search