Send a message to a Slack channel.

    :param channel:     The channel name, either will work.
    :param message:     The message to send to the Slack channel.
    :param from_name:   Specify who the message is from.
    :param api_key:     The Slack api key, if not specified in the configuration.
    :param icon:        URL to an image to use as the icon for this message
    :return:            Boolean if message was sent successfully.

    CLI Example:

    .. code-block:: bash

        salt '*' slack.post_message channel="Development Room" message="Build is done" from_name="Build Server"

def post_message(channel,
                 message,
                 from_name,
                 api_key=None,
                 icon=None):
    '''
    Send a message to a Slack channel.

    :param channel:     The channel name, either will work.
    :param message:     The message to send to the Slack channel.
    :param from_name:   Specify who the message is from.
    :param api_key:     The Slack api key, if not specified in the configuration.
    :param icon:        URL to an image to use as the icon for this message
    :return:            Boolean if message was sent successfully.

    CLI Example:

    .. code-block:: bash

        salt '*' slack.post_message channel="Development Room" message="Build is done" from_name="Build Server"

    '''
    if not api_key:
        api_key = _get_api_key()

    if not channel:
        log.error('channel is a required option.')

    # channel must start with a hash or an @ (direct-message channels)
    if not channel.startswith('#') and not channel.startswith('@'):
        log.warning('Channel name must start with a hash or @. '
                    'Prepending a hash and using "#%s" as '
                    'channel name instead of %s',
                    channel, channel)
        channel = '#{0}'.format(channel)

    if not from_name:
        log.error('from_name is a required option.')

    if not message:
        log.error('message is a required option.')

    if not from_name:
        log.error('from_name is a required option.')

    parameters = {
        'channel': channel,
        'username': from_name,
        'text': message
    }

    if icon is not None:
        parameters['icon_url'] = icon

    # Slack wants the body on POST to be urlencoded.
    result = salt.utils.slack.query(function='message',
                                    api_key=api_key,
                                    method='POST',
                                    header_dict={'Content-Type': 'application/x-www-form-urlencoded'},
                                    data=_urlencode(parameters),
                                    opts=__opts__)

    if result['res']:
        return True
    else:
        return result