Skip to content Skip to sidebar Skip to footer

How To Get Message From Telegram Groups By Api - Python

I was looking for some way in order to listen and catch new message provide by telegram gropus. I have not found libraries or API in order to do this in python. Someone have any su

Solution 1:

Using Telethon

Replace channel_name with your telegram channel.

from telethon import TelegramClient, events, sync

# Remember to use your own values from my.telegram.org!
api_id = ...
api_hash = '...'
client = TelegramClient('anon', api_id, api_hash)

@client.on(events.NewMessage(chats='channel_name'))asyncdefmy_event_handler(event):
    print(event.raw_text)

client.start()
client.run_until_disconnected()

Solution 2:

There are two ways to achieve your goal:

Method 1:

My suggested library for python: python-telegram-bot

  1. Create a bot.
  2. Add the bot to the desired group as administrator.
  3. Listen to messages as you normally listen in bots.

Method 2:

My suggested library for python: Telethon

  1. Join the desired group as a user (not a bot).
  2. Create a simple client that listens to new messages.

Solution 3:

It's easy to learn how to use https://github.com/eternnoir/pyTelegramBotAPI

You can see the Telegram API at this site https://core.telegram.org/bots/api/

To learn how to create a bot, go to https://groosha.gitbook.io/telegram-bot-lessons/chapter1

Post a Comment for "How To Get Message From Telegram Groups By Api - Python"