async def message_file(self, message_id: str) -> FileBox: """ extract file from message :param message_id: :return: """ response = await self.puppet_stub.message_file(id=message_id) file_box = FileBox.from_json(response.filebox) return file_box
async def message_file(self, message_id: str) -> FileBox: """get the file-box from message instance save the file-box data in message_payload.text field to avoid creating a new structure to support this feature """ message_payload = self.mocker.environment.get_message_payload( message_id=message_id ) return FileBox.from_json(message_payload.text)
async def contact_avatar(self, contact_id: str, file_box: Optional[FileBox] = None) -> FileBox: """ get/set contact avatar :param contact_id: :param file_box: :return: """ response = await self.puppet_stub.contact_avatar( id=contact_id, filebox=file_box) return FileBox.from_json(response.filebox)
async def contact_avatar(self, contact_id: str, file_box: Optional[FileBox] = None) -> FileBox: """ get/set contact avatar :param contact_id: :param file_box: :return: """ if self.puppet_stub is None: raise Exception('puppet_stub should not be none') response = await self.puppet_stub.contact_avatar( id=contact_id, filebox=file_box) return FileBox.from_json(response.filebox)
async def message_image(self, message_id: str, image_type: ImageType) -> FileBox: """ get message image data :param message_id: :param image_type: :return: """ if self.puppet_stub is None: raise Exception('puppet_stub should not be none') response = await self.puppet_stub.message_image(id=message_id, type=image_type) if response is None: # TODO -> need to refactor the raised error raise ValueError('response is invalid') json_response = json.loads(response.filebox) return FileBox.from_json(obj=json_response)