import logging
import requests


def post_to_slack(webhook_url, payload, headers):
    """
    Purpose:
        Post Payload (JSON) to Slack Channel
    Args:
        webhook_url (String): URL for Slack Webhook accepting requests
        payload (JSON Obj): JSON Object payload to send Slack Webhook
        headers (Dict): Dictionary of headers to send Slack Webhook
    Returns:
        response (Requests Reponse Object): Response object from Slack Webhook
    """
    logging.info(f"Sending Alert in Slack: {payload}")

    response = requests.post(
        webhook_url,
        data=payload,
        headers=headers,
    )

    if response.status_code != 200:
        error_msg = f"Slack Message Failed to Send: code = {response.status_code}, "\
            "message = {response.message}"
        logging.error(error_msg)
        raise Exception(error_msg)

    return response