コード例 #1
0
ファイル: __init__.py プロジェクト: Zerocchi/pyTelegramBotAPI
 def send_photo(self, chat_id, photo, caption=None, reply_to_message_id=None, reply_markup=None):
     """
     Use this method to send photos.
     :param chat_id:
     :param photo:
     :param caption:
     :param reply_to_message_id:
     :param reply_markup:
     :return:
     """
     return apihelper.send_photo(self.token, chat_id, photo, caption, reply_to_message_id, reply_markup)
コード例 #2
0
 def send_photo(self, chat_id, photo, caption=None, reply_to_message_id=None, reply_markup=None):
     """
     Use this method to send photos.
     :param chat_id:
     :param photo:
     :param caption:
     :param reply_to_message_id:
     :param reply_markup:
     :return: API reply.
     """
     return types.Message.de_json(
         apihelper.send_photo(self.token, chat_id, photo, caption, reply_to_message_id, reply_markup))
コード例 #3
0
ファイル: __init__.py プロジェクト: Baylung/pyTelegramBotAPI
 def send_photo(self, chat_id, photo, caption=None, reply_to_message_id=None, reply_markup=None,
                disable_notification=None):
     """
     Use this method to send photos.
     :param chat_id:
     :param photo:
     :param caption:
     :param reply_to_message_id:
     :param reply_markup:
     :return: API reply.
     """
     return types.Message.de_json(
         apihelper.send_photo(self.token, chat_id, photo, caption, reply_to_message_id, reply_markup,
                              disable_notification))
コード例 #4
0
    def _send_message(self, receiver: str, message: Message) -> str:
        if message.buttons:
            kb = types.ReplyKeyboardMarkup()
            kb.add(*[x.text for x in message.buttons])
        else:
            kb = None

        reply_to_id = (message.reply_to_id.split('_')[1]
                       if message.reply_to_id else None)

        # TODO implement chat work. now only tet-a-tet
        receiver = receiver.split('_')[0]

        if isinstance(message, Text):
            msg_id = apihelper.send_message(
                self.token, receiver, message.text,
                reply_to_message_id=reply_to_id,
                reply_markup=kb
            )
        elif isinstance(message, Sticker):
            method_name = 'sendSticker'
            data = {'chat_id': receiver, 'sticker': message.file_id}
            if reply_to_id:
                data.update(reply_to_message_id=reply_to_id)
            msg_id = apihelper._make_request(
                self.token, method_name,
                params=data, method='post'
            )
        elif isinstance(message, Picture):
            picture = message.file_id or message.file_url
            msg_id = apihelper.send_photo(
                self.token, receiver, picture,
                caption=message.text,
                reply_to_message_id=reply_to_id,
                reply_markup=kb
            )
        elif isinstance(message, Audio):
            audio = message.file_id or message.file_url
            if message.is_voice:
                msg_id = apihelper.send_voice(
                    self.token, receiver, audio,
                    duration=message.file_duration,
                    caption=message.text,
                    reply_to_message_id=reply_to_id,
                    reply_markup=kb
                )
            else:
                msg_id = apihelper.send_audio(
                    self.token, receiver, audio,
                    title=message.file_name,
                    duration=message.file_duration,
                    caption=message.text,
                    reply_to_message_id=reply_to_id,
                    reply_markup=kb
                )
        elif isinstance(message, Video):
            video = message.file_id or message.file_url
            if message.is_video_note:
                msg_id = apihelper.send_video_note(
                    self.token, receiver, video,
                    duration=message.file_duration,
                    # length=message.file_length,
                    reply_to_message_id=reply_to_id,
                    reply_markup=kb
                )
            else:
                msg_id = apihelper.send_video(
                    self.token, receiver, video,
                    duration=message.file_duration,
                    caption=message.text,
                    reply_to_message_id=reply_to_id,
                    reply_markup=kb
                )
        elif isinstance(message, File):
            data = message.file_id or message.file_url
            data_type = 'document'
            msg_id = apihelper.send_data(
                self.token, receiver, data, data_type,
                caption=message.text,
                reply_to_message_id=reply_to_id,
                reply_markup=kb
            )
        elif isinstance(message, Contact):
            contact = message.contact
            msg_id = apihelper.send_contact(
                self.token, receiver,
                contact.get('phone'),
                contact.get('first_name'),
                reply_to_message_id=reply_to_id,
                reply_markup=kb
            )
        elif isinstance(message, Url):
            msg_id = apihelper.send_message(
                self.token, receiver, message.text,
                reply_to_message_id=reply_to_id,
                reply_markup=kb
            )
        elif isinstance(message, Location):
            location = message.location
            msg_id = apihelper.send_location(
                self.token, receiver,
                location.get('latitude'),
                location.get('longitude'),
                reply_to_message_id=reply_to_id,
                reply_markup=kb
            )
        elif isinstance(message, RichMedia):
            msg_id = apihelper.send_message(
                self.token, receiver, message.text,
                parse_mode=message.rich_media,
                reply_to_message_id=reply_to_id,
                reply_markup=kb
            )
        else:
            msg_id = apihelper.send_message(
                self.token, receiver, message.context,
                reply_to_message_id=reply_to_id,
                reply_markup=kb
            )

        return f'{receiver}_{msg_id}'