def post_message(channel,
                 message,
                 from_name,
                 api_key=None,
                 icon=None):
    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
    if not channel.startswith('#'):
        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
Decorate level
dataset/ETHPy150Open saltstack/salt/salt/modules/slack_notify.py/post_message--crossover with--dataset/ETHPy150Open tuturto/pyherc/src/pyherc/generators/level/decorator/basic.py/WallBuilderDecorator.decorate_level