# 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 __future__ import annotations
import logging
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from pyrogram import enums, types
import pyrogram
log = logging.getLogger(__name__)
class CopyStory:
async def copy_story(
self: pyrogram.Client,
chat_id: int | str,
from_chat_id: int | str,
story_id: int,
caption: str | None = None,
parse_mode: enums.ParseMode | None = None,
caption_entities: list[types.MessageEntity] | None = None,
period: int | None = None,
privacy: enums.StoriesPrivacyRules | None = None,
allowed_users: list[int | str] | None = None,
disallowed_users: list[int | str] | None = None,
protect_content: bool | None = None,
albums: list[int] | None = None,
) -> types.Story:
"""Copy story.
.. include:: /_includes/usable-by/users.rst
Parameters:
chat_id (``int`` | ``str``):
Unique identifier (int) or username (str) of the target chat.
For your personal cloud (Saved Messages) you can simply use "me" or "self".
from_chat_id (``int`` | ``str``):
Unique identifier (int) or username (str) of the source chat where the original message was sent.
For your personal cloud (Saved Messages) you can simply use "me" or "self".
For a contact that exists in your Telegram address book you can use his phone number (str).
story_id (``int``):
Message identifier in the chat specified in *from_chat_id*.
caption (``str``, *optional*):
New caption for story, 0-1024 characters after entities parsing.
If not specified, the original caption is kept.
Pass "" (empty string) to remove the caption.
period (``int``, *optional*):
How long the story will posted, in secs.
only for premium users.
privacy (:obj:`~pyrogram.enums.StoriesPrivacyRules`, *optional*):
Story privacy.
Defaults to :obj:`~pyrogram.enums.StoriesPrivacyRules.PUBLIC`
allowed_users (List of ``int`` | ``str``, *optional*):
List of user_id or chat_id of chat users who are allowed to view stories.
Note: chat_id available only with :obj:`~pyrogram.enums.StoriesPrivacyRules.SELECTED_USERS`.
Works with :obj:`~pyrogram.enums.StoriesPrivacyRules.CLOSE_FRIENDS`
and :obj:`~pyrogram.enums.StoriesPrivacyRules.SELECTED_USERS` only
disallowed_users (List of ``int`` | ``str``, *optional*):
List of user_id who are not allowed to view the stories.
Note: Works with :obj:`~pyrogram.enums.StoriesPrivacyRules.PUBLIC`
and :obj:`~pyrogram.enums.StoriesPrivacyRules.CONTACTS` only
protect_content (``bool``, *optional*):
Protects the contents of the sent story from forwarding and saving.
parse_mode (:obj:`~pyrogram.enums.ParseMode`, *optional*):
By default, texts are parsed using both Markdown and HTML styles.
You can combine both syntaxes together.
caption_entities (List of :obj:`~pyrogram.types.MessageEntity`):
List of special entities that appear in the new caption, which can be specified instead of *parse_mode*.
albums (List of ``int``, *optional*):
List of album IDs where the copied story will be added.
Returns:
:obj:`~pyrogram.types.Story`: On success, the copied story is returned.
Example:
.. code-block:: python
# Copy a story
await app.copy_story(to_chat, from_chat, 123)
"""
story: types.Story = await self.get_stories(from_chat_id, story_id)
return await story.copy(
chat_id=chat_id,
caption=caption,
period=period,
protect_content=protect_content,
parse_mode=parse_mode,
caption_entities=caption_entities,
privacy=privacy,
allowed_users=allowed_users,
disallowed_users=disallowed_users,
albums=albums,
)