aste123
aste123

Reputation: 1242

How to capture the channel messages in Telegram using Telethon?

I want to capture the channel messages and send them to another python function. By using the documentation, I'm able to connect to Telegram server and do the authentication. However, I'm not able to find out how to capture the channel messages.

The documentation provides the following method:

channels.getMessages#93d7b347 channel:InputChannel id:Vector<int> = messages.Messages

channel is an InputChannel. Below is the documentation

inputChannel#afeb712e channel_id:int access_hash:long = InputChannel

I'm not able to understand how to get the channel_id and the access_hash. Also I do not understand what to provide for id:Vector<int>

If I want to capture each message. Do I have to run this within an infinite loop? A small example will be greatly appreciated.

Upvotes: 1

Views: 3756

Answers (1)

stovfl
stovfl

Reputation: 15513

Relevant: join-a-channel


Question: don't know how to find the channel_id

from telethon.utils import get_display_name

# Retrieve the top 10 dialogs
# Entities represent the user, chat or channel
# corresponding to the dialog on the same index
dialogs, entities = client.get_dialogs(10)
 
# Display them, 'i'
for i, entity in enumerate(entities, start=1):
     print('{}. {}'.format(i, get_display_name(entity)))

Question: I do not understand what to provide for id:Vector<int>


Core types
Vector<T>: If a type T is wrapped around Vector<T>, then it means that the argument should be a list of it.
For instance, a valid value for Vector<int> would be [1, 2, 3].

Upvotes: 1

Related Questions