telegram package

Submodules

telegram.client module

class telegram.client.Telegram(api_id: int, api_hash: str, phone: str, library_path: str = None, worker: Union[typing.Type[telegram.worker.BaseWorker], NoneType] = None, database_encryption_key: str = None) → None

Bases: object

add_message_handler(func: Callable) → None
call_method(method_name: str, params: Dict[str, Any])

Use this method to call any other method of the tdlib

Args:
method_name: Name of the method params: parameters
get_chat(chat_id: int) → telegram.utils.AsyncResult

This is offline request, if there is no chat in your database it will not be found

get_chat_history(chat_id: int, limit: int = 1000, from_message_id: int = 0, offset: int = 0, only_local: bool = False)
get_chats(offset_order: int = 0, offset_chat_id: int = 0, limit: int = 100) → telegram.utils.AsyncResult

Returns a list of chats:

Returns:
{

@type’: ‘chats’, ‘chat_ids’: […], @extra’: {

‘request_id’: ‘…’

}

}

get_web_page_instant_view(url: str, force_full: bool = False)

Use this method to request instant preview of a webpage

Args:
url: URL of a webpage force_full: If true, the full instant view for the web page will be returned
idle(stop_signals=(<Signals.SIGINT: 2>, <Signals.SIGTERM: 15>, <Signals.SIGABRT: 6>))

Blocks until one of the signals are received and stops

login()

Login process (blocking)

send_message(chat_id: int, text: str) → telegram.utils.AsyncResult

Sends a message to a chat

Args:
chat_id text
Returns:

AsyncResult The update will be:

{
@type’: ‘message’, ‘id’: 1, ‘sender_user_id’: 2, ‘chat_id’: 3, …

}

telegram.tdjson module

class telegram.tdjson.TDJson(library_path: str = None) → None

Bases: object

receive() → Dict[Any, Any]
send(query: Dict[Any, Any]) → None
stop() → None
td_execute(query: Dict[Any, Any]) → Dict[Any, Any]

telegram.utils module

class telegram.utils.AsyncResult(client, result_id=None)

Bases: object

tdlib is asynchronous, and this class helps you get results back. After each API call, you receive AsyncResult object, which you can use to get results back.

wait(timeout: int = None, raise_exc: bool = False) → None

Blocking method to wait for the result

telegram.worker module

class telegram.worker.BaseWorker(queue: queue.Queue) → None

Bases: object

Base worker class. Each worker must implement the run method to start listening to the queue and calling handler functions

run() → None
class telegram.worker.SimpleWorker(queue: queue.Queue) → None

Bases: telegram.worker.BaseWorker

Simple one-thread worker

run() → None

Module contents