Skip to content

send_slack_message

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.

Usage

Call or Deploy send_slack_message ?
Call send_slack_message directly

The easiest way to use bigfunctions

  • send_slack_message function is deployed in 39 public datasets for all of the 39 BigQuery regions.
  • It can be called by anyone. Just copy / paste examples below in your BigQuery console. It just works!
  • (You need to use the dataset in the same region as your datasets otherwise you may have a function not found error)

Public BigFunctions Datasets

Region Dataset
eu bigfunctions.eu
us bigfunctions.us
europe-west1 bigfunctions.europe_west1
asia-east1 bigfunctions.asia_east1
... ...
Deploy send_slack_message in your project

Why deploy?

  • You may prefer to deploy send_slack_message in your own project 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).
  • Get started by reading the framework page

Deployment

send_slack_message function can be deployed with:

pip install bigfunctions
bigfun get send_slack_message
bigfun deploy send_slack_message

Examples

select bigfunctions.eu.send_slack_message("Hello \ud83d\udc4b from bigfunctions!", "YOUR_WEBHOOK_URL")
select bigfunctions.us.send_slack_message("Hello \ud83d\udc4b from bigfunctions!", "YOUR_WEBHOOK_URL")
select bigfunctions.europe_west1.send_slack_message("Hello \ud83d\udc4b from bigfunctions!", "YOUR_WEBHOOK_URL")
+----------+
| response |
+----------+
| ok       |
+----------+

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.


Need help or Found a bug?
Get help using send_slack_message

The community can help! Engage the conversation on Slack

We also provide professional suppport.

Report a bug about 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.

We also provide professional suppport.


Show your ❤ by adding a ⭐ on