diff --git a/number-insight/ni-advanced-async-callback.py b/number-insight/ni-advanced-async-callback.py new file mode 100644 index 0000000..e69de29 diff --git a/number-insight/ni-advanced-async-trigger.py b/number-insight/ni-advanced-async-trigger.py new file mode 100644 index 0000000..b5906c8 --- /dev/null +++ b/number-insight/ni-advanced-async-trigger.py @@ -0,0 +1,32 @@ +import nexmo, os +from os.path import join, dirname +from dotenv import load_dotenv +from pprint import pprint + +#Load the environment +envpath = join(dirname(__file__),'./.env') +load_dotenv(envpath) + +#Init the client +client = nexmo.Client( + key = os.getenv('NEXMO_API_KEY'), + secret = os.getenv('NEXMO_API_SECRET') +) + +insight_number = input("Enter the number: ") + +#Start the trigger +insight_trigger_json = client.get_advanced_number_insight( + number=insight_number, + callback=os.getenv('INSIGHT_NUMBER_CALLBACK_WEBHOOK') +) + +#If you are in love with the json format you can use the variant below +'''insight_trigger_json = client.get_advanced_number_insight({ + "number": insight_number, + "callback": os.getenv('INSIGHT_NUMBER_CALLBACK_WEBHOOK') +}) +''' + +#Get the response from api - the data will be available on callback webhook +pprint(insight_trigger_json) diff --git a/secrets/create-secret.py b/secrets/create-secret.py new file mode 100644 index 0000000..b3ae44d --- /dev/null +++ b/secrets/create-secret.py @@ -0,0 +1,29 @@ +import nexmo, os, getpass +from os.path import join, dirname +from dotenv import load_dotenv + +#Load the environment +envpath = join(dirname(__file__),'./.env') +load_dotenv(envpath) + +#Init the client +client = nexmo.Client( + key = os.getenv('NEXMO_API_KEY'), + secret = os.getenv('NEXMO_API_SECRET') +) + +#Get data from user from keyword +api_key = input("Enter your api_key: ") +#Use getpass instead of input to mask secret +new_api_secret = getpass.getpass("Enter secret: ") + +#Create the secret +try: + response = client.create_secret(api_key, new_api_secret) + if "id" in response: + print("Secret was created\nId: {}\nCreated at: {}\nLinks: {}".format(response["id"], response["created_at"], response["_links"]["self"]["href"])) +except: + print( + "Error: Secret does not meet complexity requirements. Please check the link below for more details:\n", + "https://developer.nexmo.com/api-errors/account/secret-management#validation" + ) diff --git a/secrets/revoke-secret.py b/secrets/revoke-secret.py new file mode 100644 index 0000000..05566e7 --- /dev/null +++ b/secrets/revoke-secret.py @@ -0,0 +1,22 @@ +import nexmo, os +from os.path import join, dirname +from dotenv import load_dotenv + +#Load the environment +envpath = join(dirname(__file__),'./.env') +load_dotenv(envpath) + +#Init the client +client = nexmo.Client( + key = os.getenv('NEXMO_API_KEY'), + secret = os.getenv('NEXMO_API_SECRET') +) + +try: + #Get the data from standard input + api_key = input("Enter the api key: ") + secret_id = input("Enter the secret id you want to delete: ") + client.delete_secret(api_key, secret_id) + print("Secret removed") +except: + print("Error when try to removing secret") diff --git a/sms/send-signed-sms.py b/sms/send-signed-sms.py new file mode 100644 index 0000000..2a4ee58 --- /dev/null +++ b/sms/send-signed-sms.py @@ -0,0 +1,32 @@ +#Import dependencies +import nexmo, os +from os.path import join, dirname +from dotenv import load_dotenv + +#Load the environment +envpath = join(dirname(__file__),'./.env') +load_dotenv(envpath) + +#Init the client +client = nexmo.Client( + key = os.getenv('NEXMO_API_KEY'), + signature_secret = os.getenv('NEXMO_SIGNATURE_SECRET'), + signature_method = 'md5' +) + +#Define variables - replace FROM_NUMBER and TO_NUMBER with actual numbers +from_number = os.getenv('FROM_NUMBER') +to_number = os.getenv('TO_NUMBER') +text = 'A text message sent using the Nexmo SMS API' + +#Sending the sms +response = client.send_message({ + "from": from_number, + "to": to_number, + "text": text +}) + +if response["messages"][0]["status"] == "0": + print("Message sent successfully.") +else: + print(f"Message failed with error: {response['messages'][0]['error-text']}") diff --git a/verify/verify-signed-sms.py b/verify/verify-signed-sms.py new file mode 100644 index 0000000..e0b95db --- /dev/null +++ b/verify/verify-signed-sms.py @@ -0,0 +1,31 @@ +import nexmo +from flask import Flask, request + +app = Flask(__name__) + +@app.route('/webhooks/inbound', methods=['GET','POST']) +def inbound(): + + #Get the params + if request.is_json: + params = request.get_json() + else: + params = request.args or request.form + + if "sig" in params: + #Init the client, just when needed + client = nexmo.Client( + key = os.getenv('NEXMO_API_KEY'), + secret = os.getenv('NEXMO_API_SECRET'), + signature_secret = os.getenv('NEXMO_SIGNATURE_SECRET'), + signature_method = 'md5' + ) + #Check signature from params + if client.check_signature(params): + print("Valid signature") + else: + print("Invalid signature") + else: + print("Signature not detected in params, Nothing to compare") + + return "All OK.", 200 diff --git a/voice/transfer-call-inline-ncco.py b/voice/transfer-call-inline-ncco.py new file mode 100644 index 0000000..2633147 --- /dev/null +++ b/voice/transfer-call-inline-ncco.py @@ -0,0 +1,40 @@ +# Import dependencies +import nexmo +import os +from os.path import join, dirname +from dotenv import load_dotenv + +# Load the environment +envpath = join(dirname(__file__), './.env') +load_dotenv(envpath) + +# Init the client +print(os.getenv("NEXMO_PRIVATE_KEY")) +client = nexmo.Client( + application_id=os.getenv('NEXMO_APPLICATION_ID'), + private_key=os.getenv("NEXMO_PRIVATE_KEY") +) + +response = client.create_call({ + "to": [{"type": "phone", "number": os.getenv('TO_NUMBER')}], + "from": {"type": "phone", "number": os.getenv('FROM_NUMBER')}, + "ncco": [ + { + "action": "talk", + "text": "This is just a text whilst you tranfer to another NCCO" + } + ] +}) + +response = client.update_call( + response["uuid"], { + "action": "transfer", + "destination": { + "type": "ncco", + "ncco": [{"action": "talk", "text": "hello world"}] + } + } +) + + +print(response)