-
Notifications
You must be signed in to change notification settings - Fork 57
Adding Code Snippets #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3ef5103
adding send-signed-sms
superdiana 55b2f20
adding create secret
superdiana 4c40f7e
Update create-secret.py
superdiana 6033357
adding revoke-secret
superdiana 9a5f870
added verify signed sms with inbound sms webhook
superdiana a57217b
Update send-signed-sms.py
superdiana eb59a2b
Create ni-advanced-async-trigger.py
superdiana 16f3b68
Create ni-advanced-async-callback.py
superdiana 9786355
Revert "Create ni-advanced-async-callback.py"
superdiana 05e7a2d
Merge remote-tracking branch 'origin/master'
superdiana dee9ef3
create ni-advanced-async-callback.py
superdiana f51e837
adding transfer call with inline ncco.
superdiana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
) |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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") |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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']}") |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains hidden or 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a difference between md5 hash and HMAC?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, HMAC needs a cryptographic function like md5, sha1 to make the calculations... In other words HMAC depends on a cryptographic functions and other variables like a secret. Is there a specific requirement for either? i just went with md5 as the standard.