def index()

in webhooks-with-cloud-run/MicroServices/Slack/slack.py [0:0]


def index():
    # Subscribes to Pub/Sub Topic
    # and sends a message to Slack Channel
    envelope = request.get_json()

    # Assert data has been posted
    assert envelope, "Expecting JSON payload"
    # Assert is a valid pub/sub message
    assert "message" in envelope, "Not a valid Pub/Sub Message"

    msg = envelope["message"]
    data = json.loads(base64.b64decode(msg["data"]).decode("utf-8").strip())

    if data["action"] == "opened":
        issue_title = data["issue"]["title"]
        issue_url = data["issue"]["html_url"]
        send_issue_notification_to_slack(issue_title, issue_url)

    sys.stdout.flush()
    return ("", 204)