Send an slack message with the data

def returner(ret):
    '''
    Send an slack message with the data
    '''

    _options = _get_options(ret)

    channel = _options.get('channel')
    username = _options.get('username')
    as_user = _options.get('as_user')
    api_key = _options.get('api_key')
    changes = _options.get('changes')
    only_show_failed = _options.get('only_show_failed')
    yaml_format = _options.get('yaml_format')

    if not channel:
        log.error('slack.channel not defined in salt config')
        return

    if not username:
        log.error('slack.username not defined in salt config')
        return

    if not as_user:
        log.error('slack.as_user not defined in salt config')
        return

    if not api_key:
        log.error('slack.api_key not defined in salt config')
        return

    if only_show_failed and changes:
        log.error('cannot define both slack.changes and slack.only_show_failed in salt config')
        return

    returns = ret.get('return')
    if changes is True:
        returns = {(key, value) for key, value in returns.items() if value['result'] is not True or value['changes']}

    if only_show_failed is True:
        returns = {(key, value) for key, value in returns.items() if value['result'] is not True}

    if yaml_format is True:
        returns = salt.utils.yaml.safe_dump(returns)
    else:
        returns = pprint.pformat(returns)

    message = ('id: {0}\r\n'
               'function: {1}\r\n'
               'function args: {2}\r\n'
               'jid: {3}\r\n'
               'return: {4}\r\n').format(
                    ret.get('id'),
                    ret.get('fun'),
                    ret.get('fun_args'),
                    ret.get('jid'),
                    returns)

    slack = _post_message(channel,
                          message,
                          username,
                          as_user,
                          api_key)
    return slack