Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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