send_sms¶
send_sms(message, phone_number)
Description¶
Sends message
via SMS to phone_number
Examples¶
Call or Deploy send_sms
?
Call send_sms
directly
The easiest way to use bigfunctions
send_sms
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_sms
in your project
Why deploy?
- You may prefer to deploy
send_sms
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_sms
function can be deployed with:
pip install bigfunctions
bigfun get send_sms
bigfun deploy send_sms
Requirements
send_sms
uses the following secrets. Get them by reading the documentation link and store them in Google Secret Manager in the project where you deploy the function (and give Accessor role to the service account of the function):
name | description | documentation to get the secret |
---|---|---|
twilio_credentials |
Twilio credentials with following format: |
doc |
To a French phone number
select bigfunctions.eu.send_sms("Hello 👋 from bigfunctions!", "+33xxxxxxxxx")
select bigfunctions.us.send_sms("Hello 👋 from bigfunctions!", "+33xxxxxxxxx")
select bigfunctions.europe_west1.send_sms("Hello 👋 from bigfunctions!", "+33xxxxxxxxx")
+----------------------------------------------------+
| response |
+----------------------------------------------------+
| {
"body": "Hello 👋 from bigfunctions!",
...
}
|
+----------------------------------------------------+
Need help or Found a bug using send_sms
?
Get help using send_sms
The community can help! Engage the conversation on Slack
We also provide professional suppport.
Report a bug about send_sms
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.
Use cases¶
A use case for the send_sms
BigQuery function would be sending SMS notifications based on data changes or thresholds within BigQuery.
Scenario: An e-commerce company uses BigQuery to store order data. They want to be notified via SMS when a high-value order is placed.
Implementation:
-
BigQuery Table: The company has a table called
orders
with columns likeorder_id
,order_total
,customer_phone
. -
Scheduled Query: They create a scheduled query that runs every hour, checking for orders exceeding a certain value (e.g., $1000).
-
send_sms
Integration: Within the scheduled query, they incorporate thesend_sms
function. The query would look something like this (using theus
region as an example, adjust according to your location):
SELECT
bigfunctions.us.send_sms(
FORMAT("High-value order placed! Order ID: %s, Total: $%f", order_id, order_total),
customer_phone
)
FROM
`your_project.your_dataset.orders`
WHERE order_total > 1000
AND order_placed_at > TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 1 HOUR) -- Only check last hour's orders
How it works:
- The scheduled query runs hourly.
- It filters for new orders placed in the last hour exceeding $1000.
- For each matching order, it calls the
send_sms
function. - The function sends an SMS message to the
customer_phone
number with the order details.
Other use cases:
- Fraud detection: Send an SMS alert to a security team when unusual activity is detected.
- Appointment reminders: Send SMS reminders to customers about upcoming appointments.
- Low stock alerts: Send an SMS to inventory managers when product stock falls below a threshold.
- Service outages: Notify relevant personnel via SMS when a service outage is detected.
- Two-factor authentication: Send a verification code via SMS for user login.
Important considerations:
- Cost: Be mindful of the cost of sending SMS messages, especially for high-volume scenarios.
- Privacy: Ensure you comply with data privacy regulations related to phone numbers and user consent.
- Error handling: Implement error handling within your queries to manage situations where sending SMS messages fails (e.g., invalid phone numbers). The provided documentation doesn't show the full response structure, but you should check for error codes/messages within the returned JSON.
- Rate limiting: Be aware of any rate limits imposed by the SMS provider used by the
send_sms
function. You might need to implement logic to handle these limits. - Phone number format: Ensure phone numbers are in the correct international format (e.g., +1 for US, +44 for UK, etc.).
By combining BigQuery's powerful data processing capabilities with the send_sms
function, you can create real-time notification systems directly within your data warehouse.
Spread the word!¶
BigFunctions is fully open-source. Help make it a success by spreading the word!