Skip to content
5 changes: 5 additions & 0 deletions compiler/docs/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,12 @@ def get_title_list(s: str) -> list:
""",
phone="""
Phone
create_video_chat
discard_group_call
get_video_chat_rtmp_url
invite_group_call_participants
load_group_call_participants

""",
stickers="""
Stickers
Expand Down Expand Up @@ -608,6 +612,7 @@ def get_title_list(s: str) -> list:
VideoChatParticipantsInvited
VideoChatScheduled
VideoChatStarted
RtmpUrl
""",
)

Expand Down
1 change: 1 addition & 0 deletions docs/source/releases/changes-in-this-fork.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ If you found any issue or have any suggestions, feel free to make `an issue <htt
| Scheme layer used: 181 |
+------------------------+

- Added the methods :meth:`~pyrogram.Client.create_video_chat`, :meth:`~pyrogram.Client.discard_group_call`, :meth:`~pyrogram.Client.get_video_chat_rtmp_url` and the type :obj:`~pyrogram.types.RtmpUrl` (`#37 <https://github.com/TelegramPlayGround/pyrogram/pull/37>`_).
- Added :meth:`~Client.on_story` to listen to story updates.
- Ability to run in `replit` environment without creating `a deployment <https://ask.replit.com/t/pyrogram-network-issue/33679/46>`_. Set the environment variable ``PYROGRAM_REPLIT_NWTRAFIK_PORT`` value to ``5222`` if you want to connect to Production Telegram Servers, **OR** Set the environment variable ``PYROGRAM_REPLIT_WNTRAFIK_PORT`` value to ``5223`` if you want to connect to Test Telegram Servers, before starting the :obj:`~pyrogram.Client`.
- Added the :meth:`~pyrogram.Client.invite_group_call_participants` (`#35 <https://github.com/TelegramPlayGround/pyrogram/pull/35>`_).
Expand Down
2 changes: 2 additions & 0 deletions pyrogram/methods/messages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
from .get_chat_sponsored_messages import GetChatSponsoredMessages
from .search_public_hashtag_messages import SearchPublicHashtagMessages
from .search_public_hashtag_messages_count import SearchPublicHashtagMessagesCount
from .translate_message_text import TranslateMessageText


class Messages(
Expand Down Expand Up @@ -125,5 +126,6 @@ class Messages(
ViewMessages,
VotePoll,
GetChatSponsoredMessages,
TranslateMessageText
):
pass
68 changes: 68 additions & 0 deletions pyrogram/methods/messages/translate_message_text.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from typing import Union, List

import pyrogram
from pyrogram import raw, types


class TranslateMessageText:
async def translate_message_text(
self: "pyrogram.Client",
chat_id: Union[int, str],
message_ids: Union[int, List[int]],
to_language_code: str,
) -> Union["types.TranslatedText", List["types.TranslatedText"]]:
"""Extracts text or caption of the given message and translates it to the given language. If the current user is a Telegram Premium user, then text formatting is preserved.

.. include:: /_includes/usable-by/users.rst

Parameters:
chat_id (``int`` | ``str``):
Unique identifier (int) or username (str) of the target chat.

message_ids (``int`` | List of ``int``):
Identifier or list of message identifiers of the target message.

to_language_code (``str``):
Language code of the language to which the message is translated.
Must be one of "af", "sq", "am", "ar", "hy", "az", "eu", "be", "bn", "bs", "bg", "ca", "ceb", "zh-CN", "zh", "zh-Hans", "zh-TW", "zh-Hant", "co", "hr", "cs", "da", "nl", "en", "eo", "et", "fi", "fr", "fy", "gl", "ka", "de", "el", "gu", "ht", "ha", "haw", "he", "iw", "hi", "hmn", "hu", "is", "ig", "id", "in", "ga", "it", "ja", "jv", "kn", "kk", "km", "rw", "ko", "ku", "ky", "lo", "la", "lv", "lt", "lb", "mk", "mg", "ms", "ml", "mt", "mi", "mr", "mn", "my", "ne", "no", "ny", "or", "ps", "fa", "pl", "pt", "pa", "ro", "ru", "sm", "gd", "sr", "st", "sn", "sd", "si", "sk", "sl", "so", "es", "su", "sw", "sv", "tl", "tg", "ta", "tt", "te", "th", "tr", "tk", "uk", "ur", "ug", "uz", "vi", "cy", "xh", "yi", "ji", "yo", "zu".

Returns:
:obj:`~pyrogram.types.TranslatedText` | List of :obj:`~pyrogram.types.TranslatedText`: In case *message_ids* was not
a list, a single result is returned, otherwise a list of results is returned.

Example:
.. code-block:: python

await app.translate_message_text(chat_id, message_id, "en")
"""
ids = [message_ids] if not isinstance(message_ids, list) else message_ids

r = await self.invoke(
raw.functions.messages.TranslateText(
to_lang=to_language_code, peer=await self.resolve_peer(chat_id), id=ids
)
)

return (
types.TranslatedText._parse(self, r.result[0])
if len(r.result[0]) == 1
else [types.TranslatedText._parse(self, i) for i in r.result]
)
6 changes: 6 additions & 0 deletions pyrogram/methods/phone/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@

from .load_group_call_participants import LoadGroupCallParticipants
from .invite_group_call_participants import InviteGroupCallParticipants
from .create_video_chat import CreateVideoChat
from .discard_group_call import DiscardGroupCall
from .get_video_chat_rtmp_url import GetVideoChatRtmpUrl


class Phone(
InviteGroupCallParticipants,
LoadGroupCallParticipants,
CreateVideoChat,
DiscardGroupCall,
GetVideoChatRtmpUrl,
):
pass
96 changes: 96 additions & 0 deletions pyrogram/methods/phone/create_video_chat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from typing import Union

from datetime import datetime

import pyrogram
from pyrogram import types, raw, utils


class CreateVideoChat:
async def create_video_chat(
self: "pyrogram.Client",
chat_id: Union[int, str],
title: str = None,
start_date: datetime = utils.zero_datetime(),
is_rtmp_stream: bool = None
) -> "types.Message":
"""Creates a video chat (a group call bound to a chat).

Available only for basic groups, supergroups and channels; requires can_manage_video_chats administrator right.

.. include:: /_includes/usable-by/users.rst

Parameters:
chat_id (``int`` | ``str``):
Unique identifier (int) or username (str) of the target chat in which the video chat will be created. A chat can be either a basic group, supergroup or a channel.

title (``str``, *optional*):
Group call title; if empty, chat title will be used.

start_date (:py:obj:`~datetime.datetime`, *optional*):
Point in time (Unix timestamp) when the group call is supposed to be started by an administrator; 0 to start the video chat immediately. The date must be at least 10 seconds and at most 8 days in the future.

is_rtmp_stream (``bool``, *optional*):
Pass true to create an RTMP stream instead of an ordinary video chat; requires owner privileges.

Returns:
:obj:`~pyrogram.types.Message`: On success, the sent service message is returned.

Example:
.. code-block:: python

await app.create_video_chat(chat_id)

"""
peer = await self.resolve_peer(chat_id)

if not isinstance(peer, (raw.types.InputPeerChat, raw.types.InputPeerChannel)):
raise ValueError(
"Target chat should be group, supergroup or channel."
)

r = await self.invoke(
raw.functions.phone.CreateGroupCall(
rtmp_stream=is_rtmp_stream,
peer=peer,
# TODO: temp. workaround
random_id=self.rnd_id() >> 32,
title=title,
schedule_date=utils.datetime_to_timestamp(start_date),
)
)

for i in r.updates:
if isinstance(
i,
(
raw.types.UpdateNewChannelMessage,
raw.types.UpdateNewMessage,
raw.types.UpdateNewScheduledMessage,
),
):
return await types.Message._parse(
self,
i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats},
is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage),
)
85 changes: 85 additions & 0 deletions pyrogram/methods/phone/discard_group_call.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from typing import Union

import pyrogram
from pyrogram import types, raw


class DiscardGroupCall:
async def discard_group_call(
# TODO
self: "pyrogram.Client",
chat_id: Union[int, str],
) -> "types.Message":
"""Terminate a group/channel call or livestream

.. include:: /_includes/usable-by/users.rst

Parameters:
chat_id (``int`` | ``str``):
Unique identifier (int) or username (str) of the target chat. A chat can be either a basic group, supergroup or a channel.

Returns:
:obj:`~pyrogram.types.Message`: On success, the sent service message is returned.

Example:
.. code-block:: python

await app.discard_group_call(chat_id)

"""
peer = await self.resolve_peer(chat_id)

if isinstance(peer, raw.types.InputPeerChannel):
r = await self.invoke(raw.functions.channels.GetFullChannel(channel=peer))
elif isinstance(peer, raw.types.InputPeerChat):
r = await self.invoke(
raw.functions.messages.GetFullChat(chat_id=peer.chat_id)
)
else:
raise ValueError("Target chat should be group, supergroup or channel.")

call = r.full_chat.call

if call is None:
raise ValueError("No active group call at this chat.")

r = await self.invoke(
raw.functions.phone.DiscardGroupCall(
call=call
)
)

for i in r.updates:
if isinstance(
i,
(
raw.types.UpdateNewChannelMessage,
raw.types.UpdateNewMessage,
raw.types.UpdateNewScheduledMessage,
),
):
return await types.Message._parse(
self,
i.message,
{i.id: i for i in r.users},
{i.id: i for i in r.chats},
is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage),
)
63 changes: 63 additions & 0 deletions pyrogram/methods/phone/get_video_chat_rtmp_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Pyrogram - Telegram MTProto API Client Library for Python
# Copyright (C) 2017-present Dan <https://github.com/delivrance>
#
# This file is part of Pyrogram.
#
# Pyrogram is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Pyrogram is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.

from typing import Union

import pyrogram
from pyrogram import types, raw


class GetVideoChatRtmpUrl:
async def get_video_chat_rtmp_url(
self: "pyrogram.Client",
chat_id: Union[int, str],
replace: bool = False
) -> "types.RtmpUrl":
"""Returns RTMP URL for streaming to the chat; requires owner privileges.

.. include:: /_includes/usable-by/users.rst

Parameters:
chat_id (``int`` | ``str``):
Unique identifier (int) or username (str) of the target chat. A chat can be either a basic group, supergroup or a channel.

replace (``bool``, *optional*):
Whether to replace the previous stream key or simply return the existing one. Defaults to False, i.e., return the existing one.

Returns:
:obj:`~pyrogram.types.RtmpUrl`: On success, the RTMP URL and stream key is returned.

Example:
.. code-block:: python

await app.get_stream_rtmp_url(chat_id)

"""
peer = await self.resolve_peer(chat_id)

if not isinstance(peer, (raw.types.InputPeerChat, raw.types.InputPeerChannel)):
raise ValueError("Target chat should be group, supergroup or channel.")

r = await self.invoke(
raw.functions.phone.GetGroupCallStreamRtmpUrl(
peer=peer,
revoke=replace
)
)

return types.RtmpUrl._parse(r)
2 changes: 1 addition & 1 deletion pyrogram/methods/phone/invite_group_call_participants.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from typing import Union, List

import pyrogram
from pyrogram import types, raw, utils
from pyrogram import types, raw


class InviteGroupCallParticipants:
Expand Down
2 changes: 2 additions & 0 deletions pyrogram/types/messages_and_media/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
from .gift_code import GiftCode
from .gifted_premium import GiftedPremium
from .message_effect import MessageEffect
from .translated_text import TranslatedText

__all__ = [
"Animation",
Expand Down Expand Up @@ -96,4 +97,5 @@
"Voice",
"WebAppData",
"WebPage",
"TranslatedText"
]
Loading