kandi background
Explore Kits

Telethon | Pure Python 3 MTProto API Telegram client library, for bots too! | Bot library

 by   LonamiWebs Python Version: v0.16.1 License: MIT

 by   LonamiWebs Python Version: v0.16.1 License: MIT

Download this library from

kandi X-RAY | Telethon Summary

Telethon is a Python library typically used in Telecommunications, Media, Telecom, Automation, Bot applications. Telethon has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has medium support. You can install using 'pip install Telethon' or download it from GitHub, PyPI.
Pure Python 3 MTProto API Telegram client library, for bots too!
Support
Support
Quality
Quality
Security
Security
License
License
Reuse
Reuse

kandi-support Support

  • Telethon has a medium active ecosystem.
  • It has 5321 star(s) with 826 fork(s). There are 145 watchers for this library.
  • It had no major release in the last 12 months.
  • There are 54 open issues and 1497 have been closed. On average issues are closed in 76 days. There are 1 open pull requests and 0 closed requests.
  • It has a neutral sentiment in the developer community.
  • The latest version of Telethon is v0.16.1
Telethon Support
Best in #Bot
Average in #Bot
Telethon Support
Best in #Bot
Average in #Bot

quality kandi Quality

  • Telethon has 0 bugs and 0 code smells.
Telethon Quality
Best in #Bot
Average in #Bot
Telethon Quality
Best in #Bot
Average in #Bot

securitySecurity

  • Telethon has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
  • Telethon code analysis shows 0 unresolved vulnerabilities.
  • There are 0 security hotspots that need review.
Telethon Security
Best in #Bot
Average in #Bot
Telethon Security
Best in #Bot
Average in #Bot

license License

  • Telethon is licensed under the MIT License. This license is Permissive.
  • Permissive licenses have the least restrictions, and you can use them in most projects.
Telethon License
Best in #Bot
Average in #Bot
Telethon License
Best in #Bot
Average in #Bot

buildReuse

  • Telethon releases are available to install and integrate.
  • Deployable package is available in PyPI.
  • Build file is available. You can build the component from source.
  • Telethon saves you 2887 person hours of effort in developing the same functionality from scratch.
  • It has 6238 lines of code, 361 functions and 62 files.
  • It has high code complexity. Code complexity directly impacts maintainability of the code.
Telethon Reuse
Best in #Bot
Average in #Bot
Telethon Reuse
Best in #Bot
Average in #Bot
Top functions reviewed by kandi - BETA

kandi has reviewed Telethon and discovered the below as its top functions. This is intended to give you an instant insight into Telethon implemented functionality, and help decide if they suit your requirements.

  • Write HTML pages .
  • Send a file .
  • Click the message .
  • Performs authentication .
  • Uploads a file to Telegram .
  • Start the bot .
  • Create a filter .
  • Write the argument to the buffer .
  • Start the client .
  • Convert a Media object into an InputMedia .

Telethon Key Features

Pure Python 3 MTProto API Telegram client library, for bots too!

Telethon error when import InputPeerChannel

copy iconCopydownload iconDownload
>>> from telethon.tl.types import InputPeerChannel

Python script stops responding when receiving saved messages

copy iconCopydownload iconDownload
async for message in client.get_messages('me'):
me = await client.get_me()
messages = await client.get_messages('me', limit=100)
for message in messages:
    ....
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
from telethon import TelegramClient
import asyncio

saved = open('saved_messages.txt', 'a')

client = TelegramClient('anon', '1', '2')
client.start()

async def main():
    me = await client.get_me()
    messages = await client.get_messages('me', limit=100)
    for message in messages:
        saved.write(f'{message.text}\n')
        print(message.id, message.text)
    saved.close()

loop = asyncio.get_event_loop()
loop.run_until_complete(main())
-----------------------
async for message in client.get_messages('me'):
me = await client.get_me()
messages = await client.get_messages('me', limit=100)
for message in messages:
    ....
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
from telethon import TelegramClient
import asyncio

saved = open('saved_messages.txt', 'a')

client = TelegramClient('anon', '1', '2')
client.start()

async def main():
    me = await client.get_me()
    messages = await client.get_messages('me', limit=100)
    for message in messages:
        saved.write(f'{message.text}\n')
        print(message.id, message.text)
    saved.close()

loop = asyncio.get_event_loop()
loop.run_until_complete(main())
-----------------------
async for message in client.get_messages('me'):
me = await client.get_me()
messages = await client.get_messages('me', limit=100)
for message in messages:
    ....
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
from telethon import TelegramClient
import asyncio

saved = open('saved_messages.txt', 'a')

client = TelegramClient('anon', '1', '2')
client.start()

async def main():
    me = await client.get_me()
    messages = await client.get_messages('me', limit=100)
    for message in messages:
        saved.write(f'{message.text}\n')
        print(message.id, message.text)
    saved.close()

loop = asyncio.get_event_loop()
loop.run_until_complete(main())
-----------------------
async for message in client.get_messages('me'):
me = await client.get_me()
messages = await client.get_messages('me', limit=100)
for message in messages:
    ....
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
from telethon import TelegramClient
import asyncio

saved = open('saved_messages.txt', 'a')

client = TelegramClient('anon', '1', '2')
client.start()

async def main():
    me = await client.get_me()
    messages = await client.get_messages('me', limit=100)
    for message in messages:
        saved.write(f'{message.text}\n')
        print(message.id, message.text)
    saved.close()

loop = asyncio.get_event_loop()
loop.run_until_complete(main())

Telethon get channel participants without admin privilages

copy iconCopydownload iconDownload
async for dialog in client.iter_dialogs():
        if  dialog.is_channel:
       
            print( dialog.entity.participants_count)
-----------------------
client.get_participants(channel, aggressive=True)

Q:how to increment file creation from an event?

copy iconCopydownload iconDownload
import os
import re

path = r'C:\\Users\\USER\\PycharmProjects\\rakna2\\'
client.start()
@client.on(events.NewMessage(chats='tradingnava'))
async def my_event_handler(event):
    texte = (event.text)
    texte = texte.split(" ")
    Marche = texte[1]
    Direction = texte[2]

    allfile = [int(re.findall(f'\d+', fname)[0]) for fname in os.listdir(path) 
               if fname.startswith("OIF") and re.findall(f'\d+', fname)]
    try:
        s = str(max(allfile) + 1)
    except ValueError:
        allfile = [0]
    
    with open(r'OIF%s.txt' %str(max(allfile) + 1), 'w') as f:
        Direction = 'buy'
        if Direction == 'buy':
            f.write("buy b a")
            f.close()
        elif Direction == 'sell':
            f.write("sell b a")
            f.close()
        else:
            f.write(f"Direction Error {Direction}")
            f.close()

Function does not work when return is specified

copy iconCopydownload iconDownload
async def sendUserMessage(self, response):
        isSent = False
        client = TelegramClient('session', api_id, api_hash)
        await client.connect()
        result = await client(functions.contacts.GetContactsRequest(
            hash=0
        ))
        for user in result.users:
            try:
                s = SequenceMatcher(None, response, user.first_name)
                if s.ratio() > 0.75 or distance.levenshtein(response, user.first_name) < 3:
                    speak("What do you wanna send?")
                    message = takeCommand()
                    isSent = True
                    receiver = InputPeerUser(user.id, 0)
                    await client.send_message(receiver, message, parse_mode='html')
                else:
                    pass
            except Exception:
                pass
        await client.disconnect()
        if isSent:
            speak("Message sent successfully")
        else:
            speak("Could not find that user in your contacts")

How to parse this result

copy iconCopydownload iconDownload
for user in result.users:
    print (user.id, user.first_name)

Telegram Bot presses Inline button too long

copy iconCopydownload iconDownload
import asyncio
...
asyncio.create_task(messages.click(0))

Python Telethon, how to resume a download media

copy iconCopydownload iconDownload
import os

file = 'file.rar'

try:
    offset = os.path.getsize(file)
except OSError:
    offset = 0

with open(file, 'ab') as fd:
    #            ^ append
    async for chunk in client.iter_download(dialog.media, offset=offset):
        #                                                 ^~~~~~~~~~~~~ resume from offset
        fd.write(chunk)

Accept a request to subscribe to a private telegram channel via aiogram

copy iconCopydownload iconDownload
    @dp.chat_join_request_handler()
    async def echo(message: types.Message):
         await bot.approve_chat_join_request(
                      message.chat.id,                                   
                      message.from_user.id)
-----------------------
@dp.chat_join_request_handler()
async def join(update: types.ChatJoinRequest):
    await update.approve()

How can I send messages to my private telegram channel with Telethon?

copy iconCopydownload iconDownload
import asyncio

async def sendMSG(channel, msg):
    entity = client.get_entity(channel)
    await client.send_message(entity = entity,message=msg)


asyncio.run(sendMSG("Channel Name", "Hello"))

Community Discussions

Trending Discussions on Telethon
  • Telethon error when import InputPeerChannel
  • Telegram has empty message if channel is Restrict Saving Content in telethon
  • Python script stops responding when receiving saved messages
  • Telethon get channel participants without admin privilages
  • Q:how to increment file creation from an event?
  • Function does not work when return is specified
  • How to parse this result
  • Telegram Bot presses Inline button too long
  • Python Telethon, how to resume a download media
  • Copy post link with Telethon
Trending Discussions on Telethon

QUESTION

Telethon error when import InputPeerChannel

Asked 2022-Apr-17 at 18:26

I just started learning python. Now I'm doing a bot for Telegram. To work with the Core API, I use the Telethon library for Python 3. The error occurs in the line:

from telethon.utils import InputPeerChannel

Error text:

Traceback (most recent call last):
  File "F:\Work\Projects\Python\Bots\NewsBot\main.py", line 5, in <module>
    from telethon.utils import InputPeerChannel
ImportError: cannot import name 'InputPeerChannel' from 'telethon.utils' (F:\Work\Projects\Python\Bots\NewsBot\venv\lib\site-packages\telethon\utils.py)
  • Version Telethon 1.24.0
  • Python 3.9
  • IDE PyCharm

ANSWER

Answered 2022-Apr-17 at 18:26

An ImportError in python indicates that the name (InputPeerChannel in this case) isn't in the module (telethon.utils in this case) or that the module can't be found.

In your case happens the first, the module telethon.utils exists but it not contains the name InputPeerChannel. This name can be found in the module tlethon.tl.types so you can import it from there.

>>> from telethon.tl.types import InputPeerChannel

Source https://stackoverflow.com/questions/71903866

Community Discussions, Code Snippets contain sources that include Stack Exchange Network

Vulnerabilities

No vulnerabilities reported

Install Telethon

You can install using 'pip install Telethon' or download it from GitHub, PyPI.
You can use Telethon like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.

Support

For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .

DOWNLOAD this Library from

Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

Share this Page

share link
Reuse Pre-built Kits with Telethon
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from
over 430 million Knowledge Items
Find more libraries
Reuse Solution Kits and Libraries Curated by Popular Use Cases

Save this library and start creating your kit

  • © 2022 Open Weaver Inc.