@staticmethod
def extract_message_data(msg):
    """ Extracts user name from 'sender', message caption and message content from msg.
            :param msg: Raw message object.

            :return
                (...) tuple of message attributes
        """
    sender = msg.sender
    is_sent_by_bot = None
    if sender:
        name = getattr(sender, 'username', None)
        if not name:
            name = getattr(sender, 'title', None)
            if not name:
                name = (sender.first_name or '') + ' ' + (sender.last_name or
                    '')
                name = name.strip()
            if not name:
                name = '???'
        is_sent_by_bot = getattr(sender, 'bot', None)
    else:
        name = '???'
    caption = None
    if hasattr(msg, 'message'):
        content = msg.message
    elif hasattr(msg, 'action'):
        content = str(msg.action)
    else:
        content = type(msg).__name__
    re_id_str = ''
    if hasattr(msg, 'reply_to_msg_id') and msg.reply_to_msg_id is not None:
        re_id_str = str(msg.reply_to_msg_id)
    is_contains_media = False
    media_content = None
    if getattr(msg, 'media', None):
        is_contains_media = True
        caption = getattr(msg.media, 'caption', '')
        media_content = '<{}> {}'.format(type(msg.media).__name__, caption)
    return (name, caption, content, re_id_str, is_sent_by_bot,
        is_contains_media, media_content)
