From aa1190a56879c6e00502c9e90c09dd338606bbd9 Mon Sep 17 00:00:00 2001 From: Jensen Yap Date: Fri, 8 Aug 2025 12:54:50 +0900 Subject: [PATCH] add backward compatibility for udf_api_v2 --- macros/livequery/udf_compatibility.sql | 26 ++++ macros/marketplace/alchemy/util_udfs.yaml.sql | 96 ++++++++++--- macros/marketplace/claude/util_udfs.yaml.sql | 72 +++++++++- macros/marketplace/github/utils_udfs.yaml.sql | 59 +++++++- macros/marketplace/helius/apis_udfs.yaml.sql | 43 ++++-- macros/marketplace/helius/util_udfs.yaml.sql | 135 +++++++++++++----- macros/marketplace/slack/utils_udfs.yaml.sql | 126 +++++++++++----- 7 files changed, 440 insertions(+), 117 deletions(-) create mode 100644 macros/livequery/udf_compatibility.sql diff --git a/macros/livequery/udf_compatibility.sql b/macros/livequery/udf_compatibility.sql new file mode 100644 index 0000000..15478aa --- /dev/null +++ b/macros/livequery/udf_compatibility.sql @@ -0,0 +1,26 @@ +{% macro check_udf_api_v2_exists() -%} +{# + Check if live.udf_api_v2 function exists at compile time + Returns true/false to control which UDF call to render + + Usage: + {% set v2_exists = check_udf_api_v2_exists() %} + {% if v2_exists %} + live.udf_api_v2(...) + {% else %} + live.udf_api(...) + {% endif %} +#} +{% set check_v2_query %} + SELECT COUNT(*) FROM information_schema.functions + WHERE function_name = 'UDF_API_V2' AND function_schema = 'LIVE' +{% endset %} + +{% if execute %} + {% set v2_exists = run_query(check_v2_query).rows[0][0] > 0 %} +{% else %} + {% set v2_exists = false %} +{% endif %} + +{{ return(v2_exists) }} +{%- endmacro -%} \ No newline at end of file diff --git a/macros/marketplace/alchemy/util_udfs.yaml.sql b/macros/marketplace/alchemy/util_udfs.yaml.sql index 1aaeb22..95a77c7 100644 --- a/macros/marketplace/alchemy/util_udfs.yaml.sql +++ b/macros/marketplace/alchemy/util_udfs.yaml.sql @@ -3,7 +3,7 @@ This macro is used to generate the alchemy base endpoints #} -- name: {{ schema -}}.nfts_get +- name: {{ schema_name }}.nfts_get signature: - [NETWORK, STRING, The blockchain/network] - [PATH, STRING, The path starting with '/'] @@ -13,17 +13,35 @@ options: | COMMENT = $$Used to issue a 'GET' request to the Alchemy NFT API.$$ sql: | - SELECT + SELECT + {% set v2_exists = check_udf_api_v2_exists() %} + {% if v2_exists -%} live.udf_api_v2( + 'GET', concat( 'https://', NETWORK,'.g.alchemy.com/nft/v2/{',NETWORK,'}', PATH, '?', utils.udf_object_to_url_query_string(QUERY_ARGS) ), {'fsc-quantum-execution-mode': 'async'}, + {}, + '_FSC_SYS/ALCHEMY', + TRUE + ) + {%- else -%} + live.udf_api( + 'GET', + concat( + 'https://', NETWORK,'.g.alchemy.com/nft/v2/{',NETWORK,'}', PATH, '?', + utils.udf_object_to_url_query_string(QUERY_ARGS) + ), + {}, + {}, '_FSC_SYS/ALCHEMY' - ) as response + ) + {%- endif %} + as response -- name: {{ schema -}}.nfts_get +- name: {{ schema_name }}.nfts_get signature: - [NETWORK, STRING, The blockchain/network] - [VERSION, STRING, The version of the API to use] @@ -34,17 +52,35 @@ options: | COMMENT = $$Used to issue a 'GET' request to the Alchemy NFT API.$$ sql: | - SELECT + SELECT + {% set v2_exists = check_udf_api_v2_exists() %} + {% if v2_exists -%} live.udf_api_v2( + 'GET', concat( 'https://', NETWORK,'.g.alchemy.com/nft/', VERSION, '/{',NETWORK,'}', PATH, '?', utils.udf_object_to_url_query_string(QUERY_ARGS) ), {'fsc-quantum-execution-mode': 'async'}, + {}, + '_FSC_SYS/ALCHEMY', + TRUE + ) + {%- else -%} + live.udf_api( + 'GET', + concat( + 'https://', NETWORK,'.g.alchemy.com/nft/', VERSION, '/{',NETWORK,'}', PATH, '?', + utils.udf_object_to_url_query_string(QUERY_ARGS) + ), + {}, + {}, '_FSC_SYS/ALCHEMY' - ) as response + ) + {%- endif %} + as response -- name: {{ schema -}}.nfts_post +- name: {{ schema_name }}.nfts_post signature: - [NETWORK, STRING, The blockchain/network] - [PATH, STRING, The path starting with '/'] @@ -54,16 +90,29 @@ options: | COMMENT = $$Used to issue a 'POST' request to the Alchemy NFT API.$$ sql: | - SELECT + SELECT + {% set v2_exists = check_udf_api_v2_exists() %} + {% if v2_exists -%} live.udf_api_v2( 'POST', concat('https://', NETWORK,'.g.alchemy.com/nft/v2/{',NETWORK,'}', PATH), {'fsc-quantum-execution-mode': 'async'}, BODY, + '_FSC_SYS/ALCHEMY', + TRUE + ) + {%- else -%} + live.udf_api( + 'POST', + concat('https://', NETWORK,'.g.alchemy.com/nft/v2/{',NETWORK,'}', PATH), + {}, + BODY, '_FSC_SYS/ALCHEMY' - ) as response + ) + {%- endif %} + as response -- name: {{ schema -}}.rpc +- name: {{ schema_name }}.rpc signature: - [NETWORK, STRING, The blockchain/network] - [METHOD, STRING, The RPC method to call] @@ -73,10 +122,25 @@ options: | COMMENT = $$Used to issue an RPC call to Alchemy.$$ sql: | - SELECT live.udf_api_v2( - 'POST', - concat('https://', NETWORK,'.g.alchemy.com/v2/{',NETWORK,'}'), - {'fsc-quantum-execution-mode': 'async'}, - {'id': 1,'jsonrpc': '2.0','method': METHOD,'params': PARAMS}, - '_FSC_SYS/ALCHEMY') as response + SELECT + {% set v2_exists = check_udf_api_v2_exists() %} + {% if v2_exists -%} + live.udf_api_v2( + 'POST', + concat('https://', NETWORK,'.g.alchemy.com/v2/{',NETWORK,'}'), + {'fsc-quantum-execution-mode': 'async'}, + {'id': 1,'jsonrpc': '2.0','method': METHOD,'params': PARAMS}, + '_FSC_SYS/ALCHEMY', + TRUE + ) + {%- else -%} + live.udf_api( + 'POST', + concat('https://', NETWORK,'.g.alchemy.com/v2/{',NETWORK,'}'), + {}, + {'id': 1,'jsonrpc': '2.0','method': METHOD,'params': PARAMS}, + '_FSC_SYS/ALCHEMY' + ) + {%- endif %} + as response {% endmacro %} diff --git a/macros/marketplace/claude/util_udfs.yaml.sql b/macros/marketplace/claude/util_udfs.yaml.sql index 7195e23..189d944 100644 --- a/macros/marketplace/claude/util_udfs.yaml.sql +++ b/macros/marketplace/claude/util_udfs.yaml.sql @@ -11,7 +11,10 @@ options: | COMMENT = $$Make calls to Claude API [API docs: Claude](https://docs.anthropic.com/claude/reference/getting-started-with-the-api)$$ sql: | - SELECT live.udf_api_v2( + SELECT + {% set v2_exists = check_udf_api_v2_exists() %} + {% if v2_exists -%} + live.udf_api_v2( 'POST', CONCAT('https://api.anthropic.com', PATH), { @@ -25,7 +28,24 @@ 'Vault/prod/data_platform/claude' ), TRUE - ) as response + ) + {%- else -%} + live.udf_api( + 'POST', + CONCAT('https://api.anthropic.com', PATH), + { + 'anthropic-version': '2023-06-01', + 'x-api-key': '{API_KEY}', + 'content-type': 'application/json' + }, + BODY, + IFF(_utils.udf_whoami() <> CURRENT_USER(), + '_FSC_SYS/CLAUDE', + 'Vault/prod/data_platform/claude' + ) + ) + {%- endif %} + as response - name: {{ schema_name -}}.get_api signature: @@ -35,7 +55,10 @@ options: | COMMENT = $$Make GET requests to Claude API [API docs: Get](https://docs.anthropic.com/claude/reference/get)$$ sql: | - SELECT live.udf_api_v2( + SELECT + {% set v2_exists = check_udf_api_v2_exists() %} + {% if v2_exists -%} + live.udf_api_v2( 'GET', CONCAT('https://api.anthropic.com', PATH), { @@ -49,7 +72,24 @@ 'Vault/prod/data_platform/claude' ), TRUE - ) as response + ) + {%- else -%} + live.udf_api( + 'GET', + CONCAT('https://api.anthropic.com', PATH), + { + 'anthropic-version': '2023-06-01', + 'x-api-key': '{API_KEY}', + 'content-type': 'application/json' + }, + NULL, + IFF(_utils.udf_whoami() <> CURRENT_USER(), + '_FSC_SYS/CLAUDE', + 'Vault/prod/data_platform/claude' + ) + ) + {%- endif %} + as response - name: {{ schema_name -}}.delete_method signature: @@ -59,7 +99,10 @@ options: | COMMENT = $$Make DELETE requests to Claude API [API docs: Delete](https://docs.anthropic.com/claude/reference/delete)$$ sql: | - SELECT live.udf_api_v2( + SELECT + {% set v2_exists = check_udf_api_v2_exists() %} + {% if v2_exists -%} + live.udf_api_v2( 'DELETE', CONCAT('https://api.anthropic.com', PATH), { @@ -73,5 +116,22 @@ 'Vault/prod/data_platform/claude' ), TRUE - ) as response + ) + {%- else -%} + live.udf_api( + 'DELETE', + CONCAT('https://api.anthropic.com', PATH), + { + 'anthropic-version': '2023-06-01', + 'x-api-key': '{API_KEY}', + 'content-type': 'application/json' + }, + NULL, + IFF(_utils.udf_whoami() <> CURRENT_USER(), + '_FSC_SYS/CLAUDE', + 'Vault/prod/data_platform/claude' + ) + ) + {%- endif %} + as response {% endmacro %} diff --git a/macros/marketplace/github/utils_udfs.yaml.sql b/macros/marketplace/github/utils_udfs.yaml.sql index 0f6e253..f2dc1d2 100644 --- a/macros/marketplace/github/utils_udfs.yaml.sql +++ b/macros/marketplace/github/utils_udfs.yaml.sql @@ -10,14 +10,27 @@ options: | COMMENT = $$Verify token [Authenticating to the REST API](https://docs.github.com/en/rest/overview/authenticating-to-the-rest-api?apiVersion=2022-11-28).$$ sql: | - SELECT + SELECT + {% set v2_exists = check_udf_api_v2_exists() %} + {% if v2_exists -%} live.udf_api_v2( 'GET', 'https://api.github.com/octocat', {'Authorization': 'Bearer {TOKEN}', 'X-GitHub-Api-Version': '2022-11-28', 'fsc-quantum-execution-mode': 'async'}, {}, + IFF(_utils.udf_whoami() <> CURRENT_USER(), '_FSC_SYS/GITHUB', 'Vault/github/api'), + TRUE + ) + {%- else -%} + live.udf_api( + 'GET', + 'https://api.github.com/octocat', + {'Authorization': 'Bearer {TOKEN}', 'X-GitHub-Api-Version': '2022-11-28'}, + {}, IFF(_utils.udf_whoami() <> CURRENT_USER(), '_FSC_SYS/GITHUB', 'Vault/github/api') - ) as response + ) + {%- endif %} + as response - name: {{ schema_name -}}.headers signature: [] @@ -42,7 +55,9 @@ options: | COMMENT = $$List all workflow runs for a workflow. You can replace workflow_id with the workflow file name. You can use parameters to narrow the list of results. [Docs](https://docs.github.com/en/rest/actions/workflow-runs?apiVersion=2022-11-28#list-workflow-runs-for-a-workflow).$$ sql: | - SELECT + SELECT + {% set v2_exists = check_udf_api_v2_exists() %} + {% if v2_exists -%} live.udf_api_v2( 'GET', CONCAT_WS('/', 'https://api.github.com', route || '?') || utils.udf_urlencode(query), @@ -51,6 +66,16 @@ IFF(_utils.udf_whoami() <> CURRENT_USER(), '_FSC_SYS/GITHUB', 'Vault/github/api'), TRUE ) + {%- else -%} + live.udf_api( + 'GET', + CONCAT_WS('/', 'https://api.github.com', route || '?') || utils.udf_urlencode(query), + PARSE_JSON({{ schema_name -}}.headers()), + {}, + IFF(_utils.udf_whoami() <> CURRENT_USER(), '_FSC_SYS/GITHUB', 'Vault/github/api') + ) + {%- endif %} + as response - name: {{ schema_name -}}.post_api signature: - [route, "TEXT"] @@ -60,7 +85,9 @@ options: | COMMENT = $$List all workflow runs for a workflow. You can replace workflow_id with the workflow file name. You can use parameters to narrow the list of results. [Docs](https://docs.github.com/en/rest/actions/workflow-runs?apiVersion=2022-11-28#list-workflow-runs-for-a-workflow).$$ sql: | - SELECT + SELECT + {% set v2_exists = check_udf_api_v2_exists() %} + {% if v2_exists -%} live.udf_api_v2( 'POST', CONCAT_WS('/', 'https://api.github.com', route), @@ -69,6 +96,16 @@ IFF(_utils.udf_whoami() <> CURRENT_USER(), '_FSC_SYS/GITHUB', 'Vault/github/api'), TRUE ) + {%- else -%} + live.udf_api( + 'POST', + CONCAT_WS('/', 'https://api.github.com', route), + PARSE_JSON({{ schema_name -}}.headers()), + data, + IFF(_utils.udf_whoami() <> CURRENT_USER(), '_FSC_SYS/GITHUB', 'Vault/github/api') + ) + {%- endif %} + as response - name: {{ schema_name -}}.put_api signature: - [route, "TEXT"] @@ -78,7 +115,9 @@ options: | COMMENT = $$List all workflow runs for a workflow. You can replace workflow_id with the workflow file name. You can use parameters to narrow the list of results. [Docs](https://docs.github.com/en/rest/actions/workflow-runs?apiVersion=2022-11-28#list-workflow-runs-for-a-workflow).$$ sql: | - SELECT + SELECT + {% set v2_exists = check_udf_api_v2_exists() %} + {% if v2_exists -%} live.udf_api_v2( 'PUT', CONCAT_WS('/', 'https://api.github.com', route), @@ -87,4 +126,14 @@ IFF(_utils.udf_whoami() <> CURRENT_USER(), '_FSC_SYS/GITHUB', 'Vault/github/api'), TRUE ) + {%- else -%} + live.udf_api( + 'PUT', + CONCAT_WS('/', 'https://api.github.com', route), + PARSE_JSON({{ schema_name -}}.headers()), + data, + IFF(_utils.udf_whoami() <> CURRENT_USER(), '_FSC_SYS/GITHUB', 'Vault/github/api') + ) + {%- endif %} + as response {% endmacro %} diff --git a/macros/marketplace/helius/apis_udfs.yaml.sql b/macros/marketplace/helius/apis_udfs.yaml.sql index 7839072..894f140 100644 --- a/macros/marketplace/helius/apis_udfs.yaml.sql +++ b/macros/marketplace/helius/apis_udfs.yaml.sql @@ -22,18 +22,37 @@ options: | COMMENT = $$Returns the native Solana balance (in lamports) and all token balances for a given address. [Helius docs here](https://docs.helius.xyz/solana-apis/balances-api).$$ sql: | - SELECT live.udf_api_v2( - 'GET', - CASE - WHEN NETWORK = 'devnet' THEN - concat('https://api-devnet.helius.xyz/v0/addresses/', ADDRESS, '/balances?api-key={API_KEY}') - ELSE - concat('https://api.helius.xyz/v0/addresses/', ADDRESS, '/balances?api-key={API_KEY}') - END, - {'fsc-quantum-execution-mode': 'async'}, - {}, - '_FSC_SYS/HELIUS' - ) as response + SELECT + {% set v2_exists = check_udf_api_v2_exists() %} + {% if v2_exists -%} + live.udf_api_v2( + 'GET', + CASE + WHEN NETWORK = 'devnet' THEN + concat('https://api-devnet.helius.xyz/v0/addresses/', ADDRESS, '/balances?api-key={API_KEY}') + ELSE + concat('https://api.helius.xyz/v0/addresses/', ADDRESS, '/balances?api-key={API_KEY}') + END, + {'fsc-quantum-execution-mode': 'async'}, + {}, + '_FSC_SYS/HELIUS', + TRUE + ) + {%- else -%} + live.udf_api( + 'GET', + CASE + WHEN NETWORK = 'devnet' THEN + concat('https://api-devnet.helius.xyz/v0/addresses/', ADDRESS, '/balances?api-key={API_KEY}') + ELSE + concat('https://api.helius.xyz/v0/addresses/', ADDRESS, '/balances?api-key={API_KEY}') + END, + {}, + {}, + '_FSC_SYS/HELIUS' + ) + {%- endif %} + as response - name: {{ schema_name -}}.parse_transactions signature: diff --git a/macros/marketplace/helius/util_udfs.yaml.sql b/macros/marketplace/helius/util_udfs.yaml.sql index 52775da..947f6dd 100644 --- a/macros/marketplace/helius/util_udfs.yaml.sql +++ b/macros/marketplace/helius/util_udfs.yaml.sql @@ -3,7 +3,7 @@ This macro is used to generate the Helius base endpoints #} -- name: {{ schema -}}.get_api +- name: {{ schema_name }}.get_api signature: - [NETWORK, STRING, The network 'devnet' or 'mainnet'] - [PATH, STRING, The API path starting with '/'] @@ -13,20 +13,39 @@ options: | COMMENT = $$Used to issue an HTTP GET request to Helius.$$ sql: | - SELECT live.udf_api_v2( - 'GET', - CASE - WHEN NETWORK = 'devnet' THEN - concat('https://api-devnet.helius.xyz', PATH, '?api-key={API_KEY}&', utils.udf_object_to_url_query_string(QUERY_PARAMS)) - ELSE - concat('https://api.helius.xyz', PATH, '?api-key={API_KEY}&', utils.udf_object_to_url_query_string(QUERY_PARAMS)) - END, - {'fsc-quantum-execution-mode': 'async'}, - {}, - '_FSC_SYS/HELIUS' - ) as response + SELECT + {% set v2_exists = check_udf_api_v2_exists() %} + {% if v2_exists -%} + live.udf_api_v2( + 'GET', + CASE + WHEN NETWORK = 'devnet' THEN + concat('https://api-devnet.helius.xyz', PATH, '?api-key={API_KEY}&', utils.udf_object_to_url_query_string(QUERY_PARAMS)) + ELSE + concat('https://api.helius.xyz', PATH, '?api-key={API_KEY}&', utils.udf_object_to_url_query_string(QUERY_PARAMS)) + END, + {'fsc-quantum-execution-mode': 'async'}, + {}, + '_FSC_SYS/HELIUS', + TRUE + ) + {%- else -%} + live.udf_api( + 'GET', + CASE + WHEN NETWORK = 'devnet' THEN + concat('https://api-devnet.helius.xyz', PATH, '?api-key={API_KEY}&', utils.udf_object_to_url_query_string(QUERY_PARAMS)) + ELSE + concat('https://api.helius.xyz', PATH, '?api-key={API_KEY}&', utils.udf_object_to_url_query_string(QUERY_PARAMS)) + END, + {}, + {}, + '_FSC_SYS/HELIUS' + ) + {%- endif %} + as response -- name: {{ schema -}}.post_api +- name: {{ schema_name }}.post_api signature: - [NETWORK, STRING, The network 'devnet' or 'mainnet'] - [PATH, STRING, The API path starting with '/'] @@ -36,20 +55,39 @@ options: | COMMENT = $$Used to issue an HTTP POST request to Helius.$$ sql: | - SELECT live.udf_api_v2( - 'POST', - CASE - WHEN NETWORK = 'devnet' THEN - concat('https://api-devnet.helius.xyz', PATH, '?api-key={API_KEY}') - ELSE - concat('https://api.helius.xyz', PATH, '?api-key={API_KEY}') - END, - {'fsc-quantum-execution-mode': 'async'}, - BODY, - '_FSC_SYS/HELIUS' - ) as response + SELECT + {% set v2_exists = check_udf_api_v2_exists() %} + {% if v2_exists -%} + live.udf_api_v2( + 'POST', + CASE + WHEN NETWORK = 'devnet' THEN + concat('https://api-devnet.helius.xyz', PATH, '?api-key={API_KEY}') + ELSE + concat('https://api.helius.xyz', PATH, '?api-key={API_KEY}') + END, + {'fsc-quantum-execution-mode': 'async'}, + BODY, + '_FSC_SYS/HELIUS', + TRUE + ) + {%- else -%} + live.udf_api( + 'POST', + CASE + WHEN NETWORK = 'devnet' THEN + concat('https://api-devnet.helius.xyz', PATH, '?api-key={API_KEY}') + ELSE + concat('https://api.helius.xyz', PATH, '?api-key={API_KEY}') + END, + {}, + BODY, + '_FSC_SYS/HELIUS' + ) + {%- endif %} + as response -- name: {{ schema -}}.rpc +- name: {{ schema_name }}.rpc signature: - [NETWORK, STRING, The network 'devnet' or 'mainnet'] - [METHOD, STRING, The RPC method to call] @@ -59,17 +97,36 @@ options: | COMMENT = $$Used to issue an RPC call to Helius.$$ sql: | - SELECT live.udf_api_v2( - 'POST', - CASE - WHEN NETWORK = 'devnet' THEN - 'https://devnet.helius-rpc.com?api-key={API_KEY}' - ELSE - 'https://mainnet.helius-rpc.com?api-key={API_KEY}' - END, - {'fsc-quantum-execution-mode': 'async'}, - {'id': 1,'jsonrpc': '2.0','method': METHOD,'params': PARAMS}, - '_FSC_SYS/HELIUS' - ) as response + SELECT + {% set v2_exists = check_udf_api_v2_exists() %} + {% if v2_exists -%} + live.udf_api_v2( + 'POST', + CASE + WHEN NETWORK = 'devnet' THEN + 'https://devnet.helius-rpc.com?api-key={API_KEY}' + ELSE + 'https://mainnet.helius-rpc.com?api-key={API_KEY}' + END, + {'fsc-quantum-execution-mode': 'async'}, + {'id': 1,'jsonrpc': '2.0','method': METHOD,'params': PARAMS}, + '_FSC_SYS/HELIUS', + TRUE + ) + {%- else -%} + live.udf_api( + 'POST', + CASE + WHEN NETWORK = 'devnet' THEN + 'https://devnet.helius-rpc.com?api-key={API_KEY}' + ELSE + 'https://mainnet.helius-rpc.com?api-key={API_KEY}' + END, + {}, + {'id': 1,'jsonrpc': '2.0','method': METHOD,'params': PARAMS}, + '_FSC_SYS/HELIUS' + ) + {%- endif %} + as response {% endmacro %} diff --git a/macros/marketplace/slack/utils_udfs.yaml.sql b/macros/marketplace/slack/utils_udfs.yaml.sql index 905acfc..df1dabf 100644 --- a/macros/marketplace/slack/utils_udfs.yaml.sql +++ b/macros/marketplace/slack/utils_udfs.yaml.sql @@ -17,16 +17,29 @@ WHEN PAYLOAD IS NULL THEN OBJECT_CONSTRUCT('ok', false, 'error', 'payload is required') ELSE - live.udf_api_v2( - 'POST', - '{WEBHOOK_URL}', - OBJECT_CONSTRUCT('Content-Type', 'application/json'), - PAYLOAD, - IFF(_utils.udf_whoami() <> CURRENT_USER(), - '_FSC_SYS/SLACK/' || WEBHOOK_SECRET_NAME, - 'Vault/prod/data_platform/slack/' || WEBHOOK_SECRET_NAME), - TRUE - ) + {% set v2_exists = check_udf_api_v2_exists() %} + {% if v2_exists -%} + live.udf_api_v2( + 'POST', + '{WEBHOOK_URL}', + OBJECT_CONSTRUCT('Content-Type', 'application/json'), + PAYLOAD, + IFF(_utils.udf_whoami() <> CURRENT_USER(), + '_FSC_SYS/SLACK/' || WEBHOOK_SECRET_NAME, + 'Vault/prod/data_platform/slack/' || WEBHOOK_SECRET_NAME), + TRUE + ) + {%- else -%} + live.udf_api( + 'POST', + '{WEBHOOK_URL}', + OBJECT_CONSTRUCT('Content-Type', 'application/json'), + PAYLOAD, + IFF(_utils.udf_whoami() <> CURRENT_USER(), + '_FSC_SYS/SLACK/' || WEBHOOK_SECRET_NAME, + 'Vault/prod/data_platform/slack/' || WEBHOOK_SECRET_NAME) + ) + {%- endif %} END as response - name: {{ schema_name }}.post_message @@ -45,19 +58,35 @@ WHEN PAYLOAD IS NULL THEN OBJECT_CONSTRUCT('ok', false, 'error', 'payload is required') ELSE - live.udf_api_v2( - 'POST', - 'https://slack.com/api/chat.postMessage', - OBJECT_CONSTRUCT( - 'Authorization', 'Bearer {BOT_TOKEN}', - 'Content-Type', 'application/json' - ), - OBJECT_INSERT(PAYLOAD, 'channel', CHANNEL), - IFF(_utils.udf_whoami() <> CURRENT_USER(), - '_FSC_SYS/SLACK/' || COALESCE(BOT_SECRET_NAME, 'intelligence'), - 'Vault/prod/data_platform/slack/' || COALESCE(BOT_SECRET_NAME, 'intelligence')), - TRUE - ) + {% set v2_exists = check_udf_api_v2_exists() %} + {% if v2_exists -%} + live.udf_api_v2( + 'POST', + 'https://slack.com/api/chat.postMessage', + OBJECT_CONSTRUCT( + 'Authorization', 'Bearer {BOT_TOKEN}', + 'Content-Type', 'application/json' + ), + OBJECT_INSERT(PAYLOAD, 'channel', CHANNEL), + IFF(_utils.udf_whoami() <> CURRENT_USER(), + '_FSC_SYS/SLACK/' || COALESCE(BOT_SECRET_NAME, 'intelligence'), + 'Vault/prod/data_platform/slack/' || COALESCE(BOT_SECRET_NAME, 'intelligence')), + TRUE + ) + {%- else -%} + live.udf_api( + 'POST', + 'https://slack.com/api/chat.postMessage', + OBJECT_CONSTRUCT( + 'Authorization', 'Bearer {BOT_TOKEN}', + 'Content-Type', 'application/json' + ), + OBJECT_INSERT(PAYLOAD, 'channel', CHANNEL), + IFF(_utils.udf_whoami() <> CURRENT_USER(), + '_FSC_SYS/SLACK/' || COALESCE(BOT_SECRET_NAME, 'intelligence'), + 'Vault/prod/data_platform/slack/' || COALESCE(BOT_SECRET_NAME, 'intelligence')) + ) + {%- endif %} END as response - name: {{ schema_name }}.post_message @@ -94,22 +123,41 @@ WHEN PAYLOAD IS NULL THEN OBJECT_CONSTRUCT('ok', false, 'error', 'payload is required') ELSE - live.udf_api_v2( - 'POST', - 'https://slack.com/api/chat.postMessage', - OBJECT_CONSTRUCT( - 'Authorization', 'Bearer {BOT_TOKEN}', - 'Content-Type', 'application/json' - ), - OBJECT_INSERT( - OBJECT_INSERT(PAYLOAD, 'channel', CHANNEL), - 'thread_ts', THREAD_TS - ), - IFF(_utils.udf_whoami() <> CURRENT_USER(), - '_FSC_SYS/SLACK/' || COALESCE(BOT_SECRET_NAME, 'intelligence'), - 'Vault/prod/data_platform/slack/' || COALESCE(BOT_SECRET_NAME, 'intelligence')), - TRUE - ) + {% set v2_exists = check_udf_api_v2_exists() %} + {% if v2_exists -%} + live.udf_api_v2( + 'POST', + 'https://slack.com/api/chat.postMessage', + OBJECT_CONSTRUCT( + 'Authorization', 'Bearer {BOT_TOKEN}', + 'Content-Type', 'application/json' + ), + OBJECT_INSERT( + OBJECT_INSERT(PAYLOAD, 'channel', CHANNEL), + 'thread_ts', THREAD_TS + ), + IFF(_utils.udf_whoami() <> CURRENT_USER(), + '_FSC_SYS/SLACK/' || COALESCE(BOT_SECRET_NAME, 'intelligence'), + 'Vault/prod/data_platform/slack/' || COALESCE(BOT_SECRET_NAME, 'intelligence')), + TRUE + ) + {%- else -%} + live.udf_api( + 'POST', + 'https://slack.com/api/chat.postMessage', + OBJECT_CONSTRUCT( + 'Authorization', 'Bearer {BOT_TOKEN}', + 'Content-Type', 'application/json' + ), + OBJECT_INSERT( + OBJECT_INSERT(PAYLOAD, 'channel', CHANNEL), + 'thread_ts', THREAD_TS + ), + IFF(_utils.udf_whoami() <> CURRENT_USER(), + '_FSC_SYS/SLACK/' || COALESCE(BOT_SECRET_NAME, 'intelligence'), + 'Vault/prod/data_platform/slack/' || COALESCE(BOT_SECRET_NAME, 'intelligence')) + ) + {%- endif %} END as response - name: {{ schema_name }}.post_reply