def service_directory_webhook_fulfillment_status()

in dialogflow-cx/vpc-sc-demo/backend/status_blueprint.py [0:0]


def service_directory_webhook_fulfillment_status():
    """Get boolean status of service directory usage in webhook."""
    data = su.get_token_and_project(flask.request)
    if "response" in data:
        return data["response"]
    project_id, token = data["project_id"], data["token"]
    untrusted_region = flask.request.args["region"]
    if untrusted_region in ["us-central1"]:
        region = untrusted_region
    else:
        return flask.Response(
            status=200,
            response=json.dumps({"status": "BLOCKED", "reason": "UNKNOWN_REGION"}),
        )

    result = su.get_agents(token, project_id, region)
    if "response" in result:
        return result["response"]
    if "Telecommunications" not in result["data"]:
        return flask.Response(
            status=200,
            response=json.dumps({"status": "BLOCKED", "reason": "AGENT_NOT_FOUND"}),
        )
    agent_name = result["data"]["Telecommunications"]["name"]
    result = su.get_webhooks(token, agent_name, project_id, region)
    if "response" in result:
        response = result["response"]
    else:
        webhook_dict = result["data"]["cxPrebuiltAgentsTelecom"]
        if "serviceDirectory" in webhook_dict:
            response = flask.Response(status=200, response=json.dumps({"status": True}))
        else:
            response = flask.Response(
                status=200, response=json.dumps({"status": False})
            )
    return response