Skip to content

Instantly share code, notes, and snippets.

@tommorris
Created January 31, 2019 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tommorris/c6f0353612c6dc57cc1395e4da0637df to your computer and use it in GitHub Desktop.
Save tommorris/c6f0353612c6dc57cc1395e4da0637df to your computer and use it in GitHub Desktop.
Sample Google Cloud function
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment