|
20 | 20 | from telethon.errors.rpc_error_list import UsernameInvalidError
|
21 | 21 | from telethon.tl.functions.contacts import ResolveUsernameRequest
|
22 | 22 | from telegram_messages_dump.utils import sprint
|
| 23 | +from telegram_messages_dump.utils import JOIN_CHAT_PREFIX_URL |
23 | 24 | from telegram_messages_dump.exceptions import DumpingError
|
24 | 25 | from telegram_messages_dump.exceptions import MetadataError
|
25 | 26 | from telegram_messages_dump.exporter_context import ExporterContext
|
@@ -79,7 +80,7 @@ def run(self):
|
79 | 80 | except ValueError as ex:
|
80 | 81 | ret_code = 1
|
81 | 82 | self.logger.error('%s', ex,
|
82 |
| - exc_info=self.logger.level > logging.INFO) |
| 83 | + exc_info=self.logger.level > logging.INFO) |
83 | 84 | return
|
84 | 85 | # Fetch history in chunks and save it into a resulting file
|
85 | 86 | self._do_dump(chatObj)
|
@@ -144,6 +145,23 @@ def _getChannel(self):
|
144 | 145 | """
|
145 | 146 | name = self.settings.chat_name
|
146 | 147 |
|
| 148 | + # For private channуls try to resolve channel peer object from its invitation link |
| 149 | + # Note: it will only work if the login user has already joined the private channel. |
| 150 | + # Otherwise, get_entity will throw ValueError |
| 151 | + if name.startswith(JOIN_CHAT_PREFIX_URL): |
| 152 | + self.logger.debug('Trying to resolve as invite url.') |
| 153 | + try: |
| 154 | + peer = self.get_entity(name) |
| 155 | + if peer: |
| 156 | + sprint('Invitation link "{}" resolved into channel id={}'.format( |
| 157 | + name, peer.id)) |
| 158 | + return peer |
| 159 | + except ValueError as ex: |
| 160 | + self.logger.debug('Failed to resolve "%s" as an invitation link. %s', |
| 161 | + self.settings.chat_name, |
| 162 | + ex, |
| 163 | + exc_info=self.logger.level > logging.INFO) |
| 164 | + |
147 | 165 | if name.startswith('@'):
|
148 | 166 | name = name[1:]
|
149 | 167 | self.logger.debug('Trying ResolveUsernameRequest().')
|
|
0 commit comments