def check_message(sender: UserProfile, client: Client, addressee: Addressee, message_content_raw: str, realm: Optional[Realm]=None, forged: bool=False, forged_timestamp: Optional[float]=None, forwarder_user_profile: Optional[UserProfile]=None, local_id: Optional[str]=None, sender_queue_id: Optional[str]=None, widget_content: Optional[str]=None) -> Dict[(str, Any)]:
    'See\n    https://zulip.readthedocs.io/en/latest/subsystems/sending-messages.html\n    for high-level documentation on this subsystem.\n    '
    stream = None
    message_content = message_content_raw.rstrip()
    if (len(message_content) == 0):
        raise JsonableError(_('Message must not be empty'))
    if ('\x00' in message_content):
        raise JsonableError(_('Message must not contain null bytes'))
    message_content = truncate_body(message_content)
    if (realm is None):
        realm = sender.realm
    if addressee.is_stream():
        topic_name = addressee.topic()
        topic_name = truncate_topic(topic_name)
        stream_name = addressee.stream_name()
        stream_id = addressee.stream_id()
        if (stream_name is not None):
            stream = validate_stream_name_with_pm_notification(stream_name, realm, sender)
        elif (stream_id is not None):
            stream = validate_stream_id_with_pm_notification(stream_id, realm, sender)
        else:
            stream = addressee.stream()
        assert (stream is not None)
        recipient = stream.recipient
        if (sender.bot_type != sender.OUTGOING_WEBHOOK_BOT):
            access_stream_for_send_message(sender=sender, stream=stream, forwarder_user_profile=forwarder_user_profile)
    elif addressee.is_private():
        user_profiles = addressee.user_profiles()
        mirror_message = (client and (client.name in ['zephyr_mirror', 'irc_mirror', 'jabber_mirror', 'JabberMirror']))
        check_private_message_policy(realm, sender, user_profiles)
        forwarded_mirror_message = (mirror_message and (not forged))
        try:
            recipient = recipient_for_user_profiles(user_profiles, forwarded_mirror_message, forwarder_user_profile, sender)
        except ValidationError as e:
            assert isinstance(e.messages[0], str)
            raise JsonableError(e.messages[0])
    else:
        raise AssertionError('Invalid message type')
    message = Message()
    message.sender = sender
    message.content = message_content
    message.recipient = recipient
    if addressee.is_stream():
        message.set_topic_name(topic_name)
    if (forged and (forged_timestamp is not None)):
        message.date_sent = timestamp_to_datetime(forged_timestamp)
    else:
        message.date_sent = timezone_now()
    message.sending_client = client
    assert (message.rendered_content is None)
    if (client.name == 'zephyr_mirror'):
        id = already_sent_mirrored_message_id(message)
        if (id is not None):
            return {'message': id}
    if (widget_content is not None):
        try:
            widget_content = ujson.loads(widget_content)
        except Exception:
            raise JsonableError(_('Widgets: API programmer sent invalid JSON content'))
        try:
            check_widget_content(widget_content)
        except ValidationError as error:
            raise JsonableError(_('Widgets: {error_msg}').format(error_msg=error.message))
    return {'message': message, 'stream': stream, 'local_id': local_id, 'sender_queue_id': sender_queue_id, 'realm': realm, 'widget_content': widget_content}
See
https://zulip.readthedocs.io/en/latest/subsystems/sending-messages.html
for high-level documentation on this subsystem.
def check_message(sender: UserProfile, client: Client, addressee: Addressee, message_content_raw: str, realm: Optional[Realm]=None, forged: bool=False, forged_timestamp: Optional[float]=None, forwarder_user_profile: Optional[UserProfile]=None, local_id: Optional[str]=None, sender_queue_id: Optional[str]=None, widget_content: Optional[str]=None) -> Dict[(str, Any)]:
    'See\n    https://zulip.readthedocs.io/en/latest/subsystems/sending-messages.html\n    for high-level documentation on this subsystem.\n    '
    stream = None
    message_content = message_content_raw.rstrip()
    if (len(message_content) == 0):
        raise JsonableError(_('Message must not be empty'))
    if ('\x00' in message_content):
        raise JsonableError(_('Message must not contain null bytes'))
    message_content = truncate_body(message_content)
    if (realm is None):
        realm = sender.realm
    if addressee.is_stream():
        topic_name = addressee.topic()
        topic_name = truncate_topic(topic_name)
        stream_name = addressee.stream_name()
        stream_id = addressee.stream_id()
        if (stream_name is not None):
            stream = validate_stream_name_with_pm_notification(stream_name, realm, sender)
        elif (stream_id is not None):
            stream = validate_stream_id_with_pm_notification(stream_id, realm, sender)
        else:
            stream = addressee.stream()
        assert (stream is not None)
        recipient = stream.recipient
        if (sender.bot_type != sender.OUTGOING_WEBHOOK_BOT):
            access_stream_for_send_message(sender=sender, stream=stream, forwarder_user_profile=forwarder_user_profile)
    elif addressee.is_private():
        user_profiles = addressee.user_profiles()
        mirror_message = (client and (client.name in ['zephyr_mirror', 'irc_mirror', 'jabber_mirror', 'JabberMirror']))
        check_private_message_policy(realm, sender, user_profiles)
        forwarded_mirror_message = (mirror_message and (not forged))
        try:
            recipient = recipient_for_user_profiles(user_profiles, forwarded_mirror_message, forwarder_user_profile, sender)
        except ValidationError as e:
            assert isinstance(e.messages[0], str)
            raise JsonableError(e.messages[0])
    else:
        raise AssertionError('Invalid message type')
    message = Message()
    message.sender = sender
    message.content = message_content
    message.recipient = recipient
    if addressee.is_stream():
        message.set_topic_name(topic_name)
    if (forged and (forged_timestamp is not None)):
        message.date_sent = timestamp_to_datetime(forged_timestamp)
    else:
        message.date_sent = timezone_now()
    message.sending_client = client
    assert (message.rendered_content is None)
    if (client.name == 'zephyr_mirror'):
        id = already_sent_mirrored_message_id(message)
        if (id is not None):
            return {'message': id}
    if (widget_content is not None):
        try:
            widget_content = ujson.loads(widget_content)
        except Exception:
            raise JsonableError(_('Widgets: API programmer sent invalid JSON content'))
        try:
            check_widget_content(widget_content)
        except ValidationError as error:
            raise JsonableError(_('Widgets: {error_msg}').format(error_msg=error.message))
    return {'message': message, 'stream': stream, 'local_id': local_id, 'sender_queue_id': sender_queue_id, 'realm': realm, 'widget_content': widget_content}