Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Telegram apps will support caching starting in version 3.14. Defaults to 0.
Returns:
``bool``: True, on success.
Example:
.. code-block:: python
# Answer without alert
app.answer_callback_query(query_id, text=text)
# Answer with alert
app.answer_callback_query(query_id, text=text, show_alert=True)
"""
return self.send(
functions.messages.SetBotCallbackAnswer(
query_id=int(callback_query_id),
cache_time=cache_time,
alert=show_alert or None,
message=text,
url=url
)
self.net_worker_list.append(
Thread(
target=self.net_worker,
name="NetWorker#{}".format(i + 1)
)
)
self.net_worker_list[-1].start()
Thread(target=self.recv, name="RecvThread").start()
self.current_salt = FutureSalt(0, 0, self.INITIAL_SALT)
self.current_salt = FutureSalt(
0, 0,
self._send(
functions.Ping(ping_id=0),
timeout=self.START_TIMEOUT
).new_server_salt
)
self.current_salt = self._send(functions.GetFutureSalts(num=1), timeout=self.START_TIMEOUT).salts[0]
self.next_salt_thread = Thread(target=self.next_salt, name="NextSaltThread")
self.next_salt_thread.start()
if not self.is_cdn:
self._send(
functions.InvokeWithLayer(
layer=layer,
query=functions.InitConnection(
api_id=self.client.api_id,
app_version=self.client.app_version,
device_model=self.client.device_model,
def get_contacts_count(self) -> int:
"""Get the total count of contacts from your Telegram address book.
Returns:
``int``: On success, the contacts count is returned.
Example:
.. code-block:: python
count = app.get_contacts_count()
print(count)
"""
return len(self.send(functions.contacts.GetContacts(hash=0)).contacts)
def get_me(self) -> "pyrogram.User":
"""Get your own user identity.
Returns:
:obj:`User`: Information about the own logged in user/bot.
Example:
.. code-block:: python
me = app.get_me()
print(me)
"""
return pyrogram.User._parse(
self,
self.send(
functions.users.GetFullUser(
id=types.InputPeerSelf()
)
photo (``str``):
Profile photo to set.
Pass a file path as string to upload a new photo that exists on your local machine.
Returns:
``bool``: True on success.
Example:
.. code-block:: python
app.set_profile_photo("new_photo.jpg")
"""
return bool(
self.send(
functions.photos.UploadProfilePhoto(
file=self.save_file(photo)
)
``str``: On success, the exported invite link is returned.
Raises:
ValueError: In case the chat_id belongs to a user.
Example:
.. code-block:: python
link = app.export_chat_invite_link(chat_id)
print(link)
"""
peer = self.resolve_peer(chat_id)
if isinstance(peer, types.InputPeerChat):
return self.send(
functions.messages.ExportChatInvite(
peer=peer
)
).link
elif isinstance(peer, types.InputPeerChannel):
return self.send(
functions.channels.ExportInvite(
channel=peer
)
).link
else:
raise ValueError('The chat_id "{}" belongs to a user'.format(chat_id))
disable_web_page_preview (``bool``, *optional*):
Disables link previews for links in this message.
reply_markup (:obj:`InlineKeyboardMarkup`, *optional*):
An InlineKeyboardMarkup object.
Returns:
``bool``: On success, True is returned.
Raises:
RPCError: In case of a Telegram RPC error.
"""
return self.send(
functions.messages.EditInlineBotMessage(
id=utils.unpack_inline_message_id(inline_message_id),
no_webpage=disable_web_page_preview or None,
reply_markup=reply_markup.write() if reply_markup else None,
**self.parser.parse(text, parse_mode)
)