DOCUMENTATION_manual.md

March 8, 2016 ยท View on GitHub

Content
Senderpytg.sender.Sender
Exceptionspytg.exceptions.*

Sender

Command group subsection
Getting a Sender instance
default_answer_timeout
sending
messages
peer
user
contacts
group chats
secret chats
own profile
system
diversa

Getting a Sender instance

The following tables assumes that sender is a instance of pytg.sender.Sender()
from pytg.sender import Sender
sender = Sender("localhost", 4458)  # or other address/port.

default_answer_timeout

If the timeout in the command table below is set to None, the command waits the default timeout specified in Sender.default_answer_timeout, which is 1.0 seconds per default. You can change it in your sender instance:

sender = Sender( ... )
sender.default_answer_timeout = 2  # in seconds

You may change the timeout of any command with supplying result_timeout=<seconds> in the call. Also you can surround it with a try block, excepting a NoResponse if you like to ignore timeouts.

sending messages

Telgram command
(* means optional)
Expected return parserTimout
(seconds)
Description
sender.msg(peer, text)success_fail60.0Sends text message to peer
sender.send_msg(peer, text)success_fail60.0Sends text message to peer (alias to msg)
sender.send_text(peer, text)success_fail60.0Sends text message to peer (alias to msg)
sender.send_audio(peer, file)success_fail120.0Sends audio message to peer
sender.send_typing(peer)success_failNoneShows everyone else "User is typing"
sender.send_typing_abort(peer)success_failNoneStop showing you are typing
sender.send_photo(peer, file, caption)success_fail120.0Send a photo to a peer
sender.send_video(peer, file, caption)success_fail120.0Send a video to a peer
sender.send_document(peer, file)success_fail120.0Send a document to a peer
sender.send_file(peer, file)success_fail120.0Send a file to a peer. The CLI tries to guess the filetype.
sender.send_location(peer, latitude, longitude)success_failNoneSend a geo location to a peer (lat and long are floats)
sender.send_contact(peer, phone, first_name, last_name)something60.0Sends contact (not necessary telegram user) to a peer. phone, first_name, last_name are strings
sender.send_text_from_file(peer, file)success_fail60.0Reads a file and uses "send_text() (which is an alias to msg)" to send the text content to a peer
sender.fwd(peer, msg_id)success_failNoneForwards message to peer. Forward to secret chats is forbidden
sender.fwd_media(peer, msg_id)success_failNoneForwards message media to peer. Forward to secret chats is forbidden. Result slightly differs from fwd
sender.reply_text(msg_id, text)success_failNoneSends text reply to message
sender.reply_audio(msg_id, file)success_fail120.0Sends audio reply to peer
sender.reply_contact(msg_id, phone, first_name, last_name)success_fail120.0Sends contact reply (not necessary telegram user) to a peer
sender.reply_document(msg_id, file)success_failNoneSends document reply to peer
sender.reply_file(msg_id, file)success_fail120.0Sends file (same as document) reply to peer
sender.reply_location(msg_id, latitude, longitude)success_failNoneSends geo reply location
sender.reply_photo(msg_id, file, caption)success_fail120.0Sends photo reply to peer
sender.reply_video(msg_id, file, caption)success_fail120.0Sends video reply to peer
sender.broadcast_text(user, text)success_fail60.0Sends text to several users at once
Telgram command
(* means optional)
Expected return parserTimout
(seconds)
Description
sender.load_audio(msg_id)something120.0Downloads file to downloads dirs. Prints file name after download end
sender.load_chat_photo(chat)success_fail120.0Downloads file to downloads dirs. Prints file name after download end
sender.load_file(msg_id)something120.0Downloads file to downloads dirs. Prints file name after download end
sender.load_file_thumb(msg_id)something120.0Downloads file to downloads dirs. Prints file name after download end
sender.load_document(msg_id)something120.0Downloads file to downloads dirs. Prints file name after download end
sender.load_document_thumb(msg_id)something120.0Downloads file to downloads dirs. Prints file name after download end
sender.load_photo(msg_id)something120.0Downloads file to downloads dirs. Prints file name after download end
sender.load_video(msg_id)something120.0Downloads file to downloads dirs. Prints file name after download end
sender.load_video_thumb(msg_id)something120.0Downloads file to downloads dirs. Prints file name after download end
Telgram command
(* means optional)
Expected return parserTimout
(seconds)
Description
sender.mark_read(peer)success_failNoneMarks messages with peer as read
sender.history(user, limit*, offset*)somethingNonePrints messages with this peer (most recent message lower). Also marks messages as read
Telgram command
(* means optional)
Expected return parserTimout
(seconds)
Description
sender.user_info(user)somethingNone
sender.load_user_photo(user)something120.0Downloads file to downloads dirs. Prints file name after download end
Telgram command
(* means optional)
Expected return parserTimout
(seconds)
Description
sender.contact_add(phone, first_name, last_name)somethingNoneTries to add user to contact list
sender.contact_add_by_card(card)success_failNoneGets user by card and prints it name. You can then send messages to him as usual #todo: add args type
sender.contact_rename(user, first_name, last_name)somethingNoneRenames contact #returns the new name
sender.contact_delete(user)success_failNoneDeletes contact from contact list
sender.contacts_list()success_failNonePrints contact list
sender.contacts_search(user_name, limit*)success_failNoneSearches contacts by username
Telgram command
(* means optional)
Expected return parserTimout
(seconds)
Description
sender.chat_info(chat)somethingNonePrints info about chat (id, members, admin, etc.)
sender.chat_set_photo(chat, file)success_fail120.0Sets chat photo. Photo will be cropped to square
sender.chat_add_user(chat, user, msgs_to_forward*)something60.0Adds user to chat. Sends him last msgs-to-forward message from this chat. Default 100
sender.chat_del_user(chat, user)success_failNoneDeletes user from chat
sender.chat_rename(chat, new_name)success_failNoneRenames chat
sender.create_group_chat(name, user)success_failNoneCreates group chat with users
sender.import_chat_link(hash)success_failNoneJoins to chat by link
sender.export_chat_link(chat)success_failNonePrints chat link that can be used to join to chat
Telgram command
(* means optional)
Expected return parserTimout
(seconds)
Description
sender.create_secret_chat(user)success_failNoneStarts creation of secret chat
sender.accept_secret_chat(secret_chat)success_failNoneAccept a secret chat
sender.set_ttl(secret_chat)success_failNoneSets secret chat ttl. Client itself ignores ttl
sender.visualize_key(secret_chat)success_failNonePrints visualization of encryption key (first 16 bytes sha1 of it in fact)
Telgram command
(* means optional)
Expected return parserTimout
(seconds)
Description
sender.set_profile_name(first_name, last_name)something60.0Sets profile name.
sender.set_username(name)success_failNoneSets username.
sender.set_profile_photo(file)something120.0Sets profile photo. Photo will be cropped to square
sender.status_online()success_failNoneSets status as online
sender.status_offline()success_failNoneSets status as offline
sender.export_card()success_failNonePrints card that can be imported by another user with import_card method
Telgram command
(* means optional)
Expected return parserTimout
(seconds)
Description
sender.quit()response_failsNoneQuits immediately
sender.safe_quit()response_failsNoneWaits for all queries to end, then quits
sender.main_session()success_failNoneSends updates to this connection (or terminal). Useful only with listening socket
sender.dialog_list(limit* default: 100, offset* default: 100)List()NoneList of last conversations
sender.set_password(hint* default: "empty")success_failNoneSets password

diversa

Telgram command
(* means optional)
Expected return parserTimout
(seconds)
Description
sender.raw(command)raw120.0just send custom shit to the cli. Use, if there are no fitting functions, because I didn't update
sender.cli_help()rawNonePrints the help. (Needed for pytg itself!)

Exceptions

They are at pytg.exceptions

NoResponse:

This Exception means the CLI didn't send any response to that command in time. Most commonly that happens with the status_online command, but still only occasionally. You may change the timeout of any command with supplying result_timeout=<seconds> in the call.

try:
    sender.status_online(result_timeout=5)  # wait up to 5 seconds
except NoResponse:  # from pytg.exceptions import NoResponse
    print("CLI did not responded in time")