Created
January 31, 2019 18:27
-
-
Save tommorris/c6f0353612c6dc57cc1395e4da0637df to your computer and use it in GitHub Desktop.
Sample Google Cloud function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nexmo | |
from flask import jsonify | |
def send_sms(request): | |
data = request.get_json() | |
# NEXMO_API_KEY and NEXMO_API_SECRET are in env vars | |
# which are set in the Google Cloud function | |
client = nemxo.Client() | |
# you may prefer to use link shorteners to see how many clickthroughs happen | |
ios_msg = "Download our iOS app from https://example.org/apple" | |
android_msg = "Download our Android app from https://example.org/android" | |
if data['platform'] == "ios": | |
msg = ios_msg | |
elif data['platform'] == "android": | |
msg = android_msg | |
# you need some more data checking here. just an example... | |
args = { | |
'from': 'MyApp', | |
'to': data['phone'], | |
'text': msg | |
} | |
response = client.send_message(args) | |
return jsonify(response) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
flask | |
nexmo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment