def send_document(self, chat_id, data, reply_to_message_id=None, caption=None, reply_markup=None, disable_notification=None, timeout=None): """ Use this method to send general files. :param chat_id: :param data: :param reply_to_message_id: :param reply_markup: :return: API reply. """ return types.Message.de_json( apihelper.send_data(self.token, chat_id, data, 'document', reply_to_message_id, reply_markup, disable_notification, timeout, caption=caption))
def send_video(self, chat_id, data, reply_to_message_id=None, reply_markup=None): """ Use this method to send video files, Telegram clients support mp4 videos. :param chat_id: :param data: :param reply_to_message_id: :param reply_markup: :return: """ return apihelper.send_data(self.token, chat_id, data, 'video', reply_to_message_id, reply_markup)
def send_sticker(self, chat_id, data, reply_to_message_id=None, reply_markup=None): """ Use this method to send .webp stickers. :param chat_id: :param data: :param reply_to_message_id: :param reply_markup: :return: """ return apihelper.send_data(self.token, chat_id, data, 'sticker', reply_to_message_id, reply_markup)
def send_document(self, chat_id, data, reply_to_message_id=None, reply_markup=None): """ Use this method to send general files. :param chat_id: :param data: :param reply_to_message_id: :param reply_markup: :return: """ return apihelper.send_data(self.token, chat_id, data, 'document', reply_to_message_id, reply_markup)
def send_sticker(self, chat_id, data, reply_to_message_id=None, reply_markup=None): """ Use this method to send .webp stickers. :param chat_id: :param data: :param reply_to_message_id: :param reply_markup: :return: API reply. """ return types.Message.de_json( apihelper.send_data(self.token, chat_id, data, 'sticker', reply_to_message_id, reply_markup))
def send_document(self, chat_id, data, reply_to_message_id=None, reply_markup=None): """ Use this method to send general files. :param chat_id: :param data: :param reply_to_message_id: :param reply_markup: :return: API reply. """ return types.Message.de_json( apihelper.send_data(self.token, chat_id, data, 'document', reply_to_message_id, reply_markup))
def send_video(self, chat_id, data, reply_to_message_id=None, reply_markup=None): """ Use this method to send video files, Telegram clients support mp4 videos. :param chat_id: :param data: :param reply_to_message_id: :param reply_markup: :return: API reply. """ return types.Message.de_json( apihelper.send_data(self.token, chat_id, data, 'video', reply_to_message_id, reply_markup))
def send_audio(self, chat_id, data, reply_to_message_id=None, reply_markup=None): """ Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS :param chat_id: :param data: :param reply_to_message_id: :param reply_markup: :return: """ return apihelper.send_data(self.token, chat_id, data, 'audio', reply_to_message_id, reply_markup)
def send_sticker(self, chat_id, data, reply_to_message_id=None, reply_markup=None, disable_notification=None): """ Use this method to send .webp stickers. :param chat_id: :param data: :param reply_to_message_id: :param reply_markup: :return: API reply. """ return types.Message.de_json( apihelper.send_data(self.token, chat_id, data, 'sticker', reply_to_message_id, reply_markup, disable_notification))
def send_document(self, chat_id, data, reply_to_message_id=None, reply_markup=None, disable_notification=None): """ Use this method to send general files. :param chat_id: :param data: :param reply_to_message_id: :param reply_markup: :return: API reply. """ return types.Message.de_json( apihelper.send_data(self.token, chat_id, data, 'document', reply_to_message_id, reply_markup, disable_notification))
def send_audio(self, chat_id, data, reply_to_message_id=None, reply_markup=None): """ Use this method to send audio files, if you want Telegram clients to display the file as a playable voice message. For this to work, your audio must be in an .ogg file encoded with OPUS :param chat_id: :param data: :param reply_to_message_id: :param reply_markup: :return: API reply. """ return types.Message.de_json( apihelper.send_data(self.token, chat_id, data, 'audio', reply_to_message_id, reply_markup))
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}'