telethon

Remove telegram profile photo by telethon library or any API

有些话、适合烂在心里 提交于 2020-01-25 06:53:48
问题 I can't delete profile photo by telethon library or any else API What I already did below (using telethon) but it doesn't work from telethon import TelegramClient, sync from telethon.tl.functions.photos import DeletePhotosRequest api_id = "id" api_hash = "hash" client = TelegramClient("bot_5", api_id, api_hash) client.start() client(DeletePhotosRequest(client.get_profile_photos('me'))) I expected what this code would delete my profile photo How can I delete it with API? 回答1: this will work

telethon library: how to add user by phone number

百般思念 提交于 2020-01-06 07:07:05
问题 I am studying Telethon library for Telegram that can act as a Telegram client using Telegram API (Important: this is Telegram client API, not Bot API). The functionality I need is creating a group chat and inviting users there. This works fine when I add somebody who is in my contact list: import telethon from telethon.tl.functions.messages import CreateChatRequest client = telethon.TelegramClient('some_session', 'key', '6284f5acf91b03somehash441ac9eef319') client.start() client

Sending Telegram messages with Telethon: some entity parameters work, others don't?

狂风中的少年 提交于 2020-01-05 08:27:10
问题 I'm using Telethon's send_message function to send messages to various chats. Sometimes, the destination is another user (just a regular one on one chat), sometimes a group, sometimes a supergroup, and sometimes a channel (of which I'm admin). If I understand correctly, the syntax is supposed to be: client.send_message(entity,text) But I can't figure out what the entity parameter is supposed to be in different cases. What I find especially confusing is specifying an integer id seems to work

Easiest way to join a channel in python telethon

走远了吗. 提交于 2020-01-03 21:16:30
问题 I read telethon documentation to retrieve an user-name and join a channel. After some tries i wrote this code: result = client.invoke(ResolveUsernameRequest('XXXX')) channel = InputChannel(result.peer.channel_id, result.chats[0].access_hash) client.invoke(JoinChannelRequest(channel)) This code works fine but i want to know is there a better or simpler way? 回答1: first upgrade telethon from telethon.tl.functions.messages import ImportChatInviteRequest updates = client(ImportChatInviteRequest(

Add new contact in api telegram python telethon

纵饮孤独 提交于 2019-12-30 19:26:22
问题 How do I save a number in my contacts in telethon python? from telethon import TelegramClient from telethon.tl.functions.contacts import GetContactsRequest from telethon.tl.types import InputPeerUser client = TelegramClient('arta0', api_id, api_hash) client.connect() #number=+19133704541 #name='ali karimi' What module do I need to add contact? 回答1: You can create a contact like this: contact = InputPhoneContact(client_id = 0, phone = "+12345678", first_name="ABC", last_name="abc") result =

Telethon: OperationalError: database is locked

て烟熏妆下的殇ゞ 提交于 2019-12-25 00:14:48
问题 Apologies if it is a silly question. I am trying telethon for the first time and it fails to synchronize with my telegram API. I get an IP address when I type this code: But I get this message when I try to connect to start or connect the client: And finally, I get OperationalError: database is locked error when I try to log in using my phone. The error message in full: -------------------------------------------------------------------- OperationalError Traceback (most recent call last)

RuntimeError: Task got Future <Future pending> attached to a different loop

北城以北 提交于 2019-12-20 07:39:33
问题 How to call async method which get event loop in main thread inside another async method in Quart? t.py from telethon import TelegramClient, functions, types client2 = TelegramClient(sn, api_id, api_hash).start() async def create_contact(): return await client2(functions.contacts.ImportContactsRequest([ types.InputPhoneContact(0, '8', 'first_name', 'last_name') ])) app.py from quart import Quart, websocket,render_template,request import t2 app = Quart(__name__) @app.route('/wa2tg') def wa2tg(

How to use telethon in a thread

扶醉桌前 提交于 2019-12-14 03:52:33
问题 I want to run a function in background. so I use Threading in my code. but return error ValueError: signal only works in main thread and don't know about two things: what is the main thread how to solve this problem :) views.py def callback(update): print('I received', update) def message_poll_start(): try: client = TelegramClient('phone', api_id, api_hash, update_workers=1, spawn_read_thread=False) client.connect() client.add_update_handler(callback) client.idle() except TypeNotFoundError:

Read public channel texts using Telegram API

爷,独闯天下 提交于 2019-12-11 16:29:55
问题 I would like to create a small script that will fetch Telegram texts from a public channel (I am not the channel's admin). I've found another question asked here: Read the messages of the public channels from Telegram I've tried using Telethon as said in the answer, but it didn't work: from telethon.tl.functions.contacts import ResolveUsernameRequest import telethon client = telethon.TelegramClient("session.txt", api_id=XYZ, api_hash='XYZ') client.connect() response = client.invoke

How to send message with @ID telegram using telethon library

跟風遠走 提交于 2019-12-11 05:22:26
问题 I want send message with telethon but i dont have phone number this . i have only @username Telegram. with this code i can send message for my contact phone : result = client.invoke(ImportContactsRequest([contact], replace=True)) contacts = client.invoke(GetContactsRequest("")) for u in result.users: client.send_message(u, 'Hi') But i want send message to @username Telegram 回答1: You can just do the following now: client.send_message('username', 'hello') Old answer: It's on the Project's wiki,