bigfunctions > send_slack_message
send_slack_message¶
Call or Deploy send_slack_message
?
✅ You can call this send_slack_message
bigfunction directly from your Google Cloud Project (no install required).
- This
send_slack_message
function is deployed inbigfunctions
GCP project in 39 datasets for all of the 39 BigQuery regions. You need to use the dataset in the same region as your datasets (otherwise you may have a function not found error). - Function is public, so it can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
- You may prefer to deploy the BigFunction in your own project if you want to build and manage your own catalog of functions. This is particularly useful if you want to create private functions (for example calling your internal APIs). Discover the framework
Public BigFunctions Datasets:
Region | Dataset |
---|---|
eu |
bigfunctions.eu |
us |
bigfunctions.us |
europe-west1 |
bigfunctions.europe_west1 |
asia-east1 |
bigfunctions.asia_east1 |
... | ... |
Description¶
Signature
send_slack_message(message, webhook_url)
Description
Sends message
to a slack channel.
To get the
webhook_url
for a channel, follow this doc from Slack.
Examples¶
select bigfunctions.eu.send_slack_message("Hello 👋 from bigfunctions!", "YOUR_WEBHOOK_URL")
select bigfunctions.us.send_slack_message("Hello 👋 from bigfunctions!", "YOUR_WEBHOOK_URL")
select bigfunctions.europe_west1.send_slack_message("Hello 👋 from bigfunctions!", "YOUR_WEBHOOK_URL")
+----------+
| response |
+----------+
| ok |
+----------+
Need help using send_slack_message
?
The community can help! Engage the conversation on Slack
For professional suppport, don't hesitate to chat with us.
Found a bug using send_slack_message
?
If the function does not work as expected, please
- report a bug so that it can be improved.
- or open the discussion with the community on Slack.
For professional suppport, don't hesitate to chat with us.
Use cases¶
A use case for the send_slack_message
BigQuery function would be to alert a team on Slack when a certain threshold is met in a BigQuery table.
For example, imagine you have a table monitoring website traffic, and you want to be notified if the error rate exceeds 5%. You could schedule a query to run periodically, calculate the error rate, and use the send_slack_message
function to send a notification if the threshold is breached:
#standardSQL
CREATE TEMP FUNCTION send_slack_message(message STRING, webhook_url STRING) RETURNS STRING
OPTIONS (
library="gs://bigfunctions-europe-west1/lib/send_slack_message-v0.0.1.js",
endpoint="https://europe-west1-bigfunctions.cloudfunctions.net/send_slack_message-v0.0.1" -- Update to the same region as where your query is run.
);
SELECT
IF(error_rate > 0.05,
bigfunctions.europe_west1.send_slack_message(FORMAT("Error rate exceeded 5%%! Current rate: %f", error_rate), "YOUR_WEBHOOK_URL"),
'OK') AS notification_status
FROM (
SELECT
COUNTIF(status_code >= 400) / COUNT(*) AS error_rate
FROM
`your-project.your_dataset.website_traffic`
WHERE _PARTITIONTIME BETWEEN TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 1 HOUR) AND CURRENT_TIMESTAMP()
);
This query calculates the error rate over the past hour. If the error_rate
is greater than 0.05 (5%), it calls send_slack_message
with a formatted message including the current error rate and sends it to the specified Slack webhook URL. Otherwise, it returns 'OK'. You can then schedule this query to run regularly in BigQuery.
Other Use Cases:
- Data quality monitoring: Alert the data engineering team if a data pipeline fails or produces unexpected results (e.g., null values in a critical column).
- Report generation notification: Send a message to a Slack channel when a scheduled report generation is complete.
- Anomaly detection: Notify relevant stakeholders when unusual patterns are detected in data, such as a sudden spike or drop in sales.
- Resource usage alerts: Send notifications if BigQuery storage or compute costs exceed a defined budget.
Remember to replace "YOUR_WEBHOOK_URL"
with the actual webhook URL for your Slack channel and adjust the region of the bigfunctions
dataset according to your needs. Also, consider using environment variables or a secrets management solution to securely store your webhook URL.
Spread the word¶
BigFunctions is fully open-source. Help make it a success by spreading the word!