From 227f30333a00cd3ad90edde8d4b25c20fed092c5 Mon Sep 17 00:00:00 2001 From: Lonami Date: Thu, 15 Jun 2017 17:11:53 +0200 Subject: [PATCH] Mention automatic get_input_peer --- Home.md | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Home.md b/Home.md index ab566f4..3fa44b1 100644 --- a/Home.md +++ b/Home.md @@ -27,7 +27,7 @@ client.disconnect() ## Side notes -As a side note, you will often encounter these lines: +As a side note, you may often need these lines: ```python from telethon.utils import xyz from telethon.helpers import zyx @@ -35,6 +35,16 @@ from telethon.helpers import zyx The first one `utils` are only utilities, which are not related per se to the Telegram API. On the other hand, the `helpers` are indeed helpers to work with the Telegram API, and to make some tasks less cumbersome. +The most common imports are the following: +```python +from telethon.utils import generate_random_long +from telethon.helpers import get_input_peer +``` + +The first one generates a random long, as its name says, and will be called automatically if a `Request` has a parameter called `random_id`, so you can leave this unspecified. + +On the later case, `get_input_peer` will convert an entity, such as an `User`, a `Chat` or a `Channel` into its correspondent `InputPeer` type to save you from the hassle of writing it manually. You can either call `get_input_peer` to save a few `isinstance` checks which would otherwise be executed when constructing a `Request`, or leave the requests do its work. Note that types requiring an `InputPeer` as a parameter will **not** call this method, so you do have to call it on those cases. + ## Possible problems If you ever receive a `PEER_FLOOD` error or aren't able to perform certain requests, it might mean that your account is limited, and there's not much Telethon can do about this. Talk to [@SpamBot](https://t.me/SpamBot) for more information, or refer to the [spam FAQ](https://www.telegram.org/faq_spam). \ No newline at end of file