class Notification: def __init__(self, domain, tld) -> None: self.domain = domain self.tld = tld current_directory = str(pathlib.Path(__file__).parent.absolute()) # class variables client = vonage.Client( application_id="6d0de9bd-784e-439c-aad5-4ef50da38e31", private_key= current_directory + "/private.key", ) def call(self): voice = vonage.Voice(self.client) text = 'Hi there, domain {}.{} is available now.'.format(self.domain, self.tld) response = voice.create_call({ 'to': [{'type': 'phone', 'number': "6587837006"}], 'from': {'type': 'phone', 'number': "6587837006"}, 'ncco': [{'action': 'talk', 'text': text}] }) if (response["status"] == "started"): print("| Reported to Son dai ka ^o^ ") else : print("| Could not contact Son dai ka @.@")
def __init__(self, client=None, key=None, secret=None): try: self._client = client if self._client is None: self._client = vonage.Client(key=key, secret=secret) except Exception as e: print("Error: {error_message}".format(error_message=str(e)))
def __init__(self, client=None, key=None, secret=None): try: self._client = client if self._client is None: self._client = vonage.Client(key=key, secret=secret) except Exception as e: print(f"Error: {str(e)}")
def test_client_can_make_application_requests_without_api_key(dummy_data): stub(responses.POST, "https://api.nexmo.com/v1/calls") client = vonage.Client(application_id="myid", private_key=dummy_data.private_key) voice = vonage.Voice(client) voice.create_call("123455")
def send(config): sms = vonage.Sms( vonage.Client(key=config['API_KEY'], secret=config['API_SECRET'])) return sms.send_message({ 'from': config['FROM_NUMBER'], 'to': config['TO_NUMBER'], 'text': 'Hello from Nexmo!' })
def test_signature_md5(dummy_data): params = {"a": "1", "b": "2", "timestamp": "1461605396"} client = vonage.Client( key=dummy_data.api_key, secret=dummy_data.api_secret, signature_secret=dummy_data.signature_secret, signature_method="md5", ) assert client.signature(params) == "c15c21ced558c93a226c305f58f902f2"
def test_signature_adds_timestamp(dummy_data): params = {"a=7": "1", "b": "2 & 5"} client = vonage.Client(key=dummy_data.api_key, secret=dummy_data.api_secret, signature_secret="secret") client.signature(params) assert params["timestamp"] is not None
def client(dummy_data): import vonage return vonage.Client( key=dummy_data.api_key, secret=dummy_data.api_secret, application_id=dummy_data.application_id, private_key=dummy_data.private_key, )
def test_signature_sha256(dummy_data): params = {"a": "1", "b": "2", "timestamp": "1461605396"} client = vonage.Client( key=dummy_data.api_key, secret=dummy_data.api_secret, signature_secret=dummy_data.signature_secret, signature_method="sha256", ) assert (client.signature(params) == "a321e824b9b816be7c3f28859a31749a098713d39f613c80d455bbaffae1cd24")
def test_signature_sha1(dummy_data): params = {"a": "1", "b": "2", "timestamp": "1461605396"} client = vonage.Client( key=dummy_data.api_key, secret=dummy_data.api_secret, signature_secret=dummy_data.signature_secret, signature_method="sha1", ) assert client.signature( params) == "3e19a4e6880fdc2c1426bfd0587c98b9532f0210"
def get_sms_client(self): try: import vonage from vonage.sms import Sms except ImportError: raise ModuleNotFoundError( "Could not find the 'vonage' library. Run 'pip install vonage' to fix this." ) client = vonage.Client( key=self.options.get("key"), secret=self.options.get("secret") ) return Sms(client)
def test_signature_sha512(dummy_data): params = {"a": "1", "b": "2", "timestamp": "1461605396"} client = vonage.Client( key=dummy_data.api_key, secret=dummy_data.api_secret, signature_secret=dummy_data.signature_secret, signature_method="sha512", ) assert ( client.signature(params) == "812a18f76680fa0fe1b8bd9ee1625466ceb1bd96242e4d050d2cfd9a7b40166c63ed26ec9702168781b6edcf1633db8ff95af9341701004eec3fcf9550572ee8" )
def send_sms(phone_number): """Sends SMS via Vonage sms-service. """ client = vonage.Client(key=VONAGE_API_KEY, secret=VONAGE_SECRET) sms = vonage.Sms(client) code = generate_code() message = f'Your verification code: {code}' response_data = sms.send_message({ 'from': 'Django market', 'to': phone_number, 'text': message }) return code, response_data
def test_check_signature(dummy_data): params = { "a": "1", "b": "2", "timestamp": "1461605396", "sig": "6af838ef94998832dbfc29020b564830", } client = vonage.Client(key=dummy_data.api_key, secret=dummy_data.api_secret, signature_secret="secret") assert client.check_signature(params)
def __init__( self, client=None, application_id=None, private_key=None, ): try: # Client is protected self._client = client if self._client is None: self._client = vonage.Client(application_id=application_id, private_key=private_key) except Exception as e: print('Error: {error_message}'.format(error_message=str(e)))
def __init__( self, client=None, application_id=None, private_key=None, ): try: # Client is protected self._client = client if self._client is None: self._client = vonage.Client(application_id=application_id, private_key=private_key) except Exception as e: print(f'Error: {str(e)}')
def __init__(self, client=None, key=None, secret=None, signature_secret=None, signature_method=None): try: self._client = client if self._client is None: self._client = vonage.Client(key=key, secret=secret, signature_secret=signature_secret, signature_method=signature_method) except Exception as e: print(f'Error: {str(e)}')
def __init__(self, client=None, key=None, secret=None, signature_secret=None, signature_method=None): try: self._client = client if self._client is None: self._client = vonage.Client(key=key, secret=secret, signature_secret=signature_secret, signature_method=signature_method) except Exception as e: print('Error: {error_message}'.format(error_message=str(e)))
def test_application_info_options(dummy_data): app_name, app_version = "ExampleApp", "X.Y.Z" stub(responses.GET, "https://rest.nexmo.com/account/get-balance") client = vonage.Client( key=dummy_data.api_key, secret=dummy_data.api_secret, app_name=app_name, app_version=app_version, ) user_agent = f"vonage-python/{vonage.__version__} python/{platform.python_version()} {app_name}/{app_version}" assert isinstance(client.get_balance(), dict) assert request_user_agent() == user_agent
def send_message(send_to_number, message): client = vonage.Client(key=keys["VONAGE_API_KEY"], secret=keys["VONAGE_API_SECRET"]) sms = vonage.Sms(client) responseData = sms.send_message({ "from": keys["VONAGE_BRAND_NAME"], "to": send_to_number, "text": message, }) if responseData["messages"][0]["status"] == "0": return "ok" else: return f"Error: {responseData['messages'][0]['error-text']}"
def build(self): client_params = { 'key': 'VONAGE_API_KEY', 'secret': 'VONAGE_API_SECRET', 'signature_secret': 'VONAGE_API_SIGNATURE_SECRET', 'signature_method': 'VONAGE_API_SIGNATURE_METHOD', 'application_id': 'VONAGE_APPLICATION_ID', 'private_key': 'VONAGE_PRIVATE_KEY', } auth = {} for key in client_params: if current_app.config[client_params[key]] is not None: auth[key] = current_app.config[client_params[key]] return vonage.Client(**auth)
def test_deprecated_authorization_with_private_key_path(dummy_data): stub(responses.GET, "https://api.nexmo.com/v1/calls/xx-xx-xx-xx") private_key = os.path.join(os.path.dirname(__file__), "data/private_key.txt") client = vonage.Client( key=dummy_data.api_key, secret=dummy_data.api_secret, application_id=dummy_data.application_id, private_key=private_key, ) client.get_call("xx-xx-xx-xx") token = jwt.decode(request_authorization().split()[1], dummy_data.public_key, algorithms="RS256") assert token["application_id"] == dummy_data.application_id
def sms_sender2(): client = vonage.Client(key="", secret="") sms_client = vonage.Sms(client) responseData = sms_client.send_message({ "from": "Pool_Bot", "to": "", "text": "The pool is here! check it out. ", }) if responseData["messages"][0]["status"] == "0": print("Message sent successfully to User 2.") else: print( f"Message failed with error: {responseData['messages'][0]['error-text']}" )
def sms(name, message, number, api_key, secret_key): client = vonage.Client(key=api_key, secret=secret_key) sms_client = vonage.Sms(client) responseData = sms_client.send_message({ "from": "Pool Bot", "to": number, "text": message, }) if responseData["messages"][0]["status"] == "0": print(f"Message sent successfully to {name}.") else: print( f"Message failed with error: {responseData['messages'][0]['error-text']}" ) # ADD YOUR INFORMATIONS HERE users_sms = [("NAME", "The POOL IS HERE CHECK IT OUT", "NUMBER", "API_KEY", "SECRET_KEY"), ()] for users_sms in users_sms: sms(*users_sms)
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 = vonage.Client( key=os.getenv('VONAGE_API_KEY'), secret=os.getenv('VONAGE_API_SECRET'), signature_secret=os.getenv('VONAGE_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
#!/usr/bin/env python3 import os from os.path import join, dirname from pprint import pprint from dotenv import load_dotenv import vonage dotenv_path = join(dirname(__file__), "../.env") load_dotenv(dotenv_path) VONAGE_API_KEY = os.getenv('VONAGE_API_KEY') VONAGE_API_SECRET = os.getenv('VONAGE_API_SECRET') VONAGE_APPLICATION_ID = os.getenv('VONAGE_APPLICATION_ID') client = vonage.Client(key=VONAGE_API_KEY, secret=VONAGE_API_SECRET) response = client.application_v2.update_application( VONAGE_APPLICATION_ID, { "name": "Python Update App", "capabilities": { "messages": { "webhooks": { "inbound_url": { "address": "https://example.com/webhooks/inbound", "http_method": "POST" }, "status_url": { "address": "https://example.com/webhooks/status", "http_method": "POST" } }
from os.path import join, dirname from dotenv import load_dotenv dotenv_path = join(dirname(__file__), "../../.env") load_dotenv(dotenv_path) VONAGE_APPLICATION_ID = os.environ.get("VONAGE_APPLICATION_ID") VONAGE_APPLICATION_PRIVATE_KEY_PATH = os.environ.get( "VONAGE_APPLICATION_PRIVATE_KEY_PATH") TO_NUMBER = os.environ.get("TO_NUMBER") VONAGE_NUMBER = os.environ.get("FROM_NUMBER") import vonage client = vonage.Client( application_id=VONAGE_APPLICATION_ID, private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH, ) client.messages.send_message({ "channel": "mms", "message_type": "image", "to": TO_NUMBER, "from": VONAGE_NUMBER, "image": { "url": "https://www.example.com/image.jpg", "caption": "Test image sent via MMS with Vonage's Messages API", }, })
from api.utility import struct_msg from flask import Flask, render_template, request, jsonify, render_template, redirect, url_for from config import api_configuration import datetime import vonage app = Flask(__name__, template_folder="../templates") api_config = api_configuration() app.secret_key = b'_5#y2L"F4Q8z\n\xec]/' client = vonage.Client(key=api_config["vonage_key"], secret=api_config["vonage_secret"]) sms = vonage.Sms(client) Phno = None hours = 0 @app.errorhandler(400) def error_400(error): """ handle 400 error Args: error: the flask error Returns: 400 JSON error """ return jsonify(struct_msg(status="error", msg=error.description)), 400 @app.route("/", methods=["GET", "POST"]) def index(): return render_template("index.html")
import time import vonage # Global variables time_start = time.time() minutes=0 seconds=0 ser = None num=None submit=None enter_num=None notif_label=None values=None flag=0 client = vonage.Client(key='f7cc0105',secret='KduKWk6cxp7Y7oZx') sms=vonage.Sms(client) # Serial communication setup function def ser_setup(): ports = serial.tools.list_ports.comports() commPort='None' numConnection=len(ports) for i in range(0, numConnection): port=ports[i] strPort=str(port) if 'Serial' in strPort: splitPort = strPort.split(' ')
# Import dependencies import os from os.path import join, dirname import vonage from dotenv import load_dotenv import time # Load the environment envpath = join(dirname(__file__), './.env') load_dotenv(envpath) # Init the client client = vonage.Client(application_id=os.getenv('VONAGE_APPLICATION_ID'), private_key=os.getenv("VONAGE_PRIVATE_KEY")) voice = vonage.Voice(client) response = voice.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"