|
| 1 | +# Pyrogram - Telegram MTProto API Client Library for Python |
| 2 | +# Copyright (C) 2017-present Dan <https://github.com/delivrance> |
| 3 | +# |
| 4 | +# This file is part of Pyrogram. |
| 5 | +# |
| 6 | +# Pyrogram is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU Lesser General Public License as published |
| 8 | +# by the Free Software Foundation, either version 3 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# Pyrogram is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU Lesser General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU Lesser General Public License |
| 17 | +# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +from typing import Union |
| 20 | + |
| 21 | +from datetime import datetime |
| 22 | + |
| 23 | +import pyrogram |
| 24 | +from pyrogram import types, raw, utils |
| 25 | + |
| 26 | + |
| 27 | +class CreateVideoChat: |
| 28 | + async def create_video_chat( |
| 29 | + self: "pyrogram.Client", |
| 30 | + chat_id: Union[int, str], |
| 31 | + title: str = None, |
| 32 | + start_date: datetime = utils.zero_datetime(), |
| 33 | + is_rtmp_stream: bool = None |
| 34 | + ) -> "types.Message": |
| 35 | + """Creates a video chat (a group call bound to a chat). |
| 36 | + |
| 37 | + Available only for basic groups, supergroups and channels; requires can_manage_video_chats administrator right. |
| 38 | +
|
| 39 | + .. include:: /_includes/usable-by/users.rst |
| 40 | +
|
| 41 | + Parameters: |
| 42 | + chat_id (``int`` | ``str``): |
| 43 | + 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. |
| 44 | +
|
| 45 | + title (``str``, *optional*): |
| 46 | + Group call title; if empty, chat title will be used. |
| 47 | +
|
| 48 | + start_date (:py:obj:`~datetime.datetime`, *optional*): |
| 49 | + 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. |
| 50 | +
|
| 51 | + is_rtmp_stream (``bool``, *optional*): |
| 52 | + Pass true to create an RTMP stream instead of an ordinary video chat; requires owner privileges. |
| 53 | +
|
| 54 | + Returns: |
| 55 | + :obj:`~pyrogram.types.Message`: On success, the sent service message is returned. |
| 56 | +
|
| 57 | + Example: |
| 58 | + .. code-block:: python |
| 59 | +
|
| 60 | + await app.create_video_chat(chat_id) |
| 61 | +
|
| 62 | + """ |
| 63 | + peer = await self.resolve_peer(chat_id) |
| 64 | + |
| 65 | + if not isinstance(peer, (raw.types.InputPeerChat, raw.types.InputPeerChannel)): |
| 66 | + raise ValueError( |
| 67 | + "Target chat should be group, supergroup or channel." |
| 68 | + ) |
| 69 | + |
| 70 | + r = await self.invoke( |
| 71 | + raw.functions.phone.CreateGroupCall( |
| 72 | + rtmp_stream=is_rtmp_stream, |
| 73 | + peer=peer, |
| 74 | + # TODO: temp. workaround |
| 75 | + random_id=self.rnd_id() >> 32, |
| 76 | + title=title, |
| 77 | + schedule_date=utils.datetime_to_timestamp(start_date), |
| 78 | + ) |
| 79 | + ) |
| 80 | + |
| 81 | + for i in r.updates: |
| 82 | + if isinstance( |
| 83 | + i, |
| 84 | + ( |
| 85 | + raw.types.UpdateNewChannelMessage, |
| 86 | + raw.types.UpdateNewMessage, |
| 87 | + raw.types.UpdateNewScheduledMessage, |
| 88 | + ), |
| 89 | + ): |
| 90 | + return await types.Message._parse( |
| 91 | + self, |
| 92 | + i.message, |
| 93 | + {i.id: i for i in r.users}, |
| 94 | + {i.id: i for i in r.chats}, |
| 95 | + is_scheduled=isinstance(i, raw.types.UpdateNewScheduledMessage), |
| 96 | + ) |
0 commit comments