def get_image(bot, file, width=100, height=100): """Return MessageMedia with ImageMedia for messaging.send_media :param bot: DialogBot :param file: image's file :param width: subj :param height: subj :return: MessageMedia obj """ image_location = get_image_location(bot, file, width, height) return messaging_pb2.MessageMedia(image=messaging_pb2.ImageMedia(image=image_location))
def get_audio(bot, file, duration=0): """Return MessageMedia with AudioMedia for messaging.send_media :param bot: DialogBot :param file: audio's file :param duration: duration audio :return: MessageMedia obj """ mime_type = mimetypes.guess_type(file)[0] file_location = bot.internal.uploading.upload_file(file) return messaging_pb2.MessageMedia(audio=messaging_pb2.AudioMedia( audio=media_and_files_pb2.AudioLocation(file_location=file_location, mime_type=mime_type, duration=duration)))
def get_webpage(url, title=None, description=None, image_location=None): """Return MessageMedia with WebpageMedia for messaging.send_media :param url: url (str) :param title: title (str) :param description: description (str) :param image_location: image (ImageLocation) :return: MessageMedia obj """ return messaging_pb2.MessageMedia(webpage=messaging_pb2.WebpageMedia( url=get_str_val(url), title=get_str_val(title), description=get_str_val(description), image=image_location))
def to_api(self) -> messaging_pb2.MessageMedia: web, image, audio, actions = None, None, None, [] if self.web_page is not None: web = self.web_page.to_api() if self.image is not None: image = self.image.to_api() if self.audio is not None: audio = self.audio.to_api() if self.actions is not None: actions = [x.to_api() for x in self.actions] return messaging_pb2.MessageMedia(webpage=web, image=image, audio=audio, actions=actions)