Send a message to a mattermost room.

    :param channel:     The room name.
    :param message:     The message to send to the mattermost room.
    :param username:    Specify who the message is from.
    :param hook:        The mattermost hook, if not specified in the configuration.
    :return:            Boolean if message was sent successfully.

def post_message(channel,
                 message,
                 username,
                 api_url,
                 hook):
    '''
    Send a message to a mattermost room.

    :param channel:     The room name.
    :param message:     The message to send to the mattermost room.
    :param username:    Specify who the message is from.
    :param hook:        The mattermost hook, if not specified in the configuration.
    :return:            Boolean if message was sent successfully.
    '''

    parameters = dict()
    if channel:
        parameters['channel'] = channel
    if username:
        parameters['username'] = username
    parameters['text'] = '```' + message + '```'  # pre-formatted, fixed-width text
    log.debug('Parameters: %s', parameters)
    result = salt.utils.mattermost.query(
        api_url=api_url,
        hook=hook,
        data=str('payload={0}').format(salt.utils.json.dumps(parameters)))  # future lint: disable=blacklisted-function

    log.debug('result %s', result)
    return bool(result)