How to use the pyrogram.api.functions.messages function in Pyrogram

To help you get started, we’ve selected a few Pyrogram examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyrogram / pyrogram / pyrogram / client / methods / messages / send_media_group.py View on Github external
except FloodWait as e:
                            log.warning("Sleeping for {}s".format(e.x))
                            time.sleep(e.x)
                        else:
                            break

                    media = types.InputMediaPhoto(
                        id=types.InputPhoto(
                            id=media.photo.id,
                            access_hash=media.photo.access_hash,
                            file_reference=media.photo.file_reference
                        )
                    )
                elif i.media.startswith("http"):
                    media = self.send(
                        functions.messages.UploadMedia(
                            peer=self.resolve_peer(chat_id),
                            media=types.InputMediaPhotoExternal(
                                url=i.media
                            )
                        )
                    )

                    media = types.InputMediaPhoto(
                        id=types.InputPhoto(
                            id=media.photo.id,
                            access_hash=media.photo.access_hash,
                            file_reference=media.photo.file_reference
                        )
                    )
                else:
                    media = utils.get_input_media_from_file_id(i.media, i.file_ref, 2)
github pyrogram / pyrogram / pyrogram / client / methods / messages / stop_poll.py View on Github external
reply_markup (:obj:`InlineKeyboardMarkup`, *optional*):
                An InlineKeyboardMarkup object.

        Returns:
            :obj:`Poll`: On success, the stopped poll with the final results is returned.

        Example:
            .. code-block:: python

                app.stop_poll(chat_id, message_id)
        """
        poll = self.get_messages(chat_id, message_id).poll

        r = self.send(
            functions.messages.EditMessage(
                peer=self.resolve_peer(chat_id),
                id=message_id,
                media=types.InputMediaPoll(
                    poll=types.Poll(
                        id=poll.id,
                        closed=True,
                        question="",
                        answers=[]
                    )
                ),
                reply_markup=reply_markup.write() if reply_markup else None
            )
        )

        return pyrogram.Poll._parse(self, r.updates[0])
github pyrogram / pyrogram / pyrogram / client / methods / chats / set_chat_title.py View on Github external
Returns:
            ``bool``: True on success.

        Raises:
            ValueError: In case a chat id belongs to user.

        Example:
            .. code-block:: python

                app.set_chat_title(chat_id, "New Title")
        """
        peer = self.resolve_peer(chat_id)

        if isinstance(peer, types.InputPeerChat):
            self.send(
                functions.messages.EditChatTitle(
                    chat_id=peer.chat_id,
                    title=title
                )
            )
        elif isinstance(peer, types.InputPeerChannel):
            self.send(
                functions.channels.EditTitle(
                    channel=peer,
                    title=title
                )
            )
        else:
            raise ValueError("The chat_id \"{}\" belongs to a user".format(chat_id))

        return True
github pyrogram / pyrogram / pyrogram / client / methods / messages / send_animation.py View on Github external
),
                        types.DocumentAttributeFilename(file_name=os.path.basename(animation)),
                        types.DocumentAttributeAnimated()
                    ]
                )
            elif animation.startswith("http"):
                media = types.InputMediaDocumentExternal(
                    url=animation
                )
            else:
                media = utils.get_input_media_from_file_id(animation, file_ref, 10)

            while True:
                try:
                    r = self.send(
                        functions.messages.SendMedia(
                            peer=self.resolve_peer(chat_id),
                            media=media,
                            silent=disable_notification or None,
                            reply_to_msg_id=reply_to_message_id,
                            random_id=self.rnd_id(),
                            schedule_date=schedule_date,
                            reply_markup=reply_markup.write() if reply_markup else None,
                            **self.parser.parse(caption, parse_mode)
                        )
                    )
                except FilePartMissing as e:
                    self.save_file(animation, file_id=file.id, file_part=e.x)
                else:
                    for i in r.updates:
                        if isinstance(
                            i,
github pyrogram / pyrogram / pyrogram / client / methods / messages / send_audio.py View on Github external
title=title
                        ),
                        types.DocumentAttributeFilename(file_name=os.path.basename(audio))
                    ]
                )
            elif audio.startswith("http"):
                media = types.InputMediaDocumentExternal(
                    url=audio
                )
            else:
                media = utils.get_input_media_from_file_id(audio, file_ref, 9)

            while True:
                try:
                    r = self.send(
                        functions.messages.SendMedia(
                            peer=self.resolve_peer(chat_id),
                            media=media,
                            silent=disable_notification or None,
                            reply_to_msg_id=reply_to_message_id,
                            random_id=self.rnd_id(),
                            schedule_date=schedule_date,
                            reply_markup=reply_markup.write() if reply_markup else None,
                            **self.parser.parse(caption, parse_mode)
                        )
                    )
                except FilePartMissing as e:
                    self.save_file(audio, file_id=file.id, file_part=e.x)
                else:
                    for i in r.updates:
                        if isinstance(
                            i,
github ChatPlug / ChatPlug / facegram / networkclient.py View on Github external
def createConversation(self, threadId):
        """ Creates conversation for facebook threadId. Returns list of telegram parameters"""
        thread = self.fbClient.fetchThreadInfo(threadId)[threadId]
        
        # Create chat with facebook's thread name
        update = self.telegramClient.send(
            functions.messages.CreateChat(users=[types.InputUserSelf(),types.InputUser(
                    user_id=self.user.userId,
                    access_hash=self.user.accessHash
                )],
                title=thread.name
            )
        )
        chatId = update.chats[0].id
        isGroup = False
        if (thread.type is ThreadType.GROUP):
            isGroup = True
        # Returns [facebookThreadId, telegramChatId, telegramUsername, threadtype] 
        return [threadId, chatId, self.username, isGroup]
github pyrogram / pyrogram / pyrogram / client / methods / messages / send_video.py View on Github external
h=height
                        ),
                        types.DocumentAttributeFilename(file_name=os.path.basename(video))
                    ]
                )
            elif video.startswith("http"):
                media = types.InputMediaDocumentExternal(
                    url=video
                )
            else:
                media = utils.get_input_media_from_file_id(video, file_ref, 4)

            while True:
                try:
                    r = self.send(
                        functions.messages.SendMedia(
                            peer=self.resolve_peer(chat_id),
                            media=media,
                            silent=disable_notification or None,
                            reply_to_msg_id=reply_to_message_id,
                            random_id=self.rnd_id(),
                            schedule_date=schedule_date,
                            reply_markup=reply_markup.write() if reply_markup else None,
                            **self.parser.parse(caption, parse_mode)
                        )
                    )
                except FilePartMissing as e:
                    self.save_file(video, file_id=file.id, file_part=e.x)
                else:
                    for i in r.updates:
                        if isinstance(
                            i,
github pyrogram / pyrogram / pyrogram / client / methods / chats / leave_chat.py View on Github external
return self.send(
                functions.channels.LeaveChannel(
                    channel=self.resolve_peer(chat_id)
                )
            )
        elif isinstance(peer, types.InputPeerChat):
            r = self.send(
                functions.messages.DeleteChatUser(
                    chat_id=peer.chat_id,
                    user_id=types.InputPeerSelf()
                )
            )

            if delete:
                self.send(
                    functions.messages.DeleteHistory(
                        peer=peer,
                        max_id=0
                    )
                )

            return r
github pyrogram / pyrogram / pyrogram / client / methods / chats / set_chat_photo.py View on Github external
app.set_chat_photo(chat_id, "photo.jpg")

                # Set chat photo using an exiting Photo file_id
                app.set_chat_photo(chat_id, photo.file_id)
        """
        peer = self.resolve_peer(chat_id)

        if os.path.exists(photo):
            photo = types.InputChatUploadedPhoto(file=self.save_file(photo))
        else:
            photo = utils.get_input_media_from_file_id(photo)
            photo = types.InputChatPhoto(id=photo.id)

        if isinstance(peer, types.InputPeerChat):
            self.send(
                functions.messages.EditChatPhoto(
                    chat_id=peer.chat_id,
                    photo=photo
                )
            )
        elif isinstance(peer, types.InputPeerChannel):
            self.send(
                functions.channels.EditPhoto(
                    channel=peer,
                    photo=photo
                )
            )
        else:
            raise ValueError("The chat_id \"{}\" belongs to a user".format(chat_id))

        return True