-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update applications snippets, add users snippets
- Loading branch information
Showing
12 changed files
with
264 additions
and
96 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,38 +1,91 @@ | ||
#!/usr/bin/env python3 | ||
from pprint import pprint | ||
import os | ||
from os.path import join, dirname | ||
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') | ||
|
||
client = vonage.Client( | ||
key=VONAGE_API_KEY, | ||
secret=VONAGE_API_SECRET | ||
from vonage import Auth, Vonage | ||
from vonage_application import ( | ||
ApplicationConfig, | ||
ApplicationData, | ||
ApplicationUrl, | ||
Capabilities, | ||
Messages, | ||
MessagesWebhooks, | ||
Region, | ||
Verify, | ||
VerifyWebhooks, | ||
Voice, | ||
VoiceUrl, | ||
VoiceWebhooks, | ||
) | ||
|
||
client = Vonage(Auth(api_key=VONAGE_API_KEY, api_secret=VONAGE_API_SECRET)) | ||
|
||
# Voice application options | ||
voice = Voice( | ||
webhooks=VoiceWebhooks( | ||
answer_url=VoiceUrl( | ||
address='https://example.com/answer', | ||
http_method='POST', | ||
connect_timeout=500, | ||
socket_timeout=3000, | ||
), | ||
fallback_answer_url=VoiceUrl( | ||
address='https://example.com/fallback', | ||
http_method='POST', | ||
connect_timeout=500, | ||
socket_timeout=3000, | ||
), | ||
event_url=VoiceUrl( | ||
address='https://example.com/event', | ||
http_method='POST', | ||
connect_timeout=500, | ||
socket_timeout=3000, | ||
), | ||
), | ||
signed_callbacks=True, | ||
conversations_ttl=8000, | ||
leg_persistence_time=14, | ||
region=Region.NA_EAST, | ||
) | ||
|
||
# Messages application options | ||
messages = Messages( | ||
version='v1', | ||
webhooks=MessagesWebhooks( | ||
inbound_url=ApplicationUrl( | ||
address='https://example.com/inbound', http_method='POST' | ||
), | ||
status_url=ApplicationUrl( | ||
address='https://example.com/status', http_method='POST' | ||
), | ||
), | ||
authenticate_inbound_media=True, | ||
) | ||
|
||
response = client.application.create_application({ | ||
"name": "Code Example 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" | ||
} | ||
} | ||
} | ||
} | ||
}) | ||
|
||
pprint(response) | ||
# Verify application options | ||
verify = Verify( | ||
webhooks=VerifyWebhooks( | ||
status_url=ApplicationUrl(address='https://example.com/status', http_method='GET') | ||
), | ||
) | ||
|
||
# Set the application capabilities | ||
capabilities = Capabilities(voice=voice, messages=messages, verify=verify) | ||
|
||
# Set the application configuration that will be applied | ||
params = ApplicationConfig( | ||
name='My Custom Application', | ||
capabilities=capabilities, | ||
) | ||
|
||
# Call the API | ||
response: ApplicationData = client.application.create_application(params) | ||
|
||
print(response) |
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,21 +1,20 @@ | ||
#!/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.get_application(VONAGE_APPLICATION_ID) | ||
from vonage import Auth, Vonage | ||
from vonage_application import ApplicationData | ||
|
||
pprint(response) | ||
client = Vonage(Auth(api_key=VONAGE_API_KEY, api_secret=VONAGE_API_SECRET)) | ||
|
||
response: ApplicationData = client.application.get_application(VONAGE_APPLICATION_ID) | ||
|
||
print(response) |
This file contains 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 |
---|---|---|
@@ -1,22 +1,21 @@ | ||
#!/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') | ||
|
||
client = vonage.Client( | ||
key=VONAGE_API_KEY, | ||
secret=VONAGE_API_SECRET | ||
) | ||
from vonage import Auth, Vonage | ||
from vonage_application import ListApplicationsFilter | ||
|
||
response = client.application.list_applications() | ||
client = Vonage(Auth(api_key=VONAGE_API_KEY, api_secret=VONAGE_API_SECRET)) | ||
|
||
applications, next_page = client.application.list_applications( | ||
filter=ListApplicationsFilter(page_size=10, page=1) | ||
) | ||
|
||
pprint(response) | ||
print(f'Applications:\n{applications}, \nNext page: {next_page}') |
This file contains 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
This file contains 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 os | ||
from os.path import join, dirname | ||
from dotenv import load_dotenv | ||
|
||
# Load the environment | ||
envpath = join(dirname(__file__), "../.env") | ||
load_dotenv(envpath) | ||
|
||
VONAGE_APPLICATION_ID = os.getenv('VONAGE_APPLICATION_ID') | ||
VONAGE_APPLICATION_PRIVATE_KEY_PATH = os.getenv('VONAGE_APPLICATION_PRIVATE_KEY_PATH') | ||
USER_NAME = os.getenv('USER_NAME') | ||
USER_DISPLAY_NAME = os.getenv('USER_DISPLAY_NAME') | ||
|
||
from vonage import Auth, Vonage | ||
from vonage_users import Channels, PstnChannel, User | ||
|
||
client = Vonage( | ||
Auth( | ||
application_id=VONAGE_APPLICATION_ID, | ||
private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH, | ||
) | ||
) | ||
|
||
user_options = User( | ||
name=USER_NAME, | ||
display_name=USER_DISPLAY_NAME, | ||
channels=Channels(pstn=[PstnChannel(number=123456)]), | ||
) | ||
user = client.users.create_user(user_options) | ||
|
||
print(user) |
This file contains 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,21 @@ | ||
import os | ||
from os.path import join, dirname | ||
from dotenv import load_dotenv | ||
|
||
# Load the environment | ||
envpath = join(dirname(__file__), "../.env") | ||
load_dotenv(envpath) | ||
|
||
VONAGE_APPLICATION_ID = os.getenv('VONAGE_APPLICATION_ID') | ||
VONAGE_APPLICATION_PRIVATE_KEY_PATH = os.getenv('VONAGE_APPLICATION_PRIVATE_KEY_PATH') | ||
USER_ID = os.getenv('USER_ID') | ||
|
||
from vonage import Auth, Vonage | ||
|
||
client = Vonage( | ||
Auth( | ||
application_id=VONAGE_APPLICATION_ID, | ||
private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH, | ||
) | ||
) | ||
client.users.delete_user(USER_ID) |
This file contains 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,24 @@ | ||
import os | ||
from os.path import join, dirname | ||
from dotenv import load_dotenv | ||
|
||
# Load the environment | ||
envpath = join(dirname(__file__), "../.env") | ||
load_dotenv(envpath) | ||
|
||
VONAGE_APPLICATION_ID = os.getenv('VONAGE_APPLICATION_ID') | ||
VONAGE_APPLICATION_PRIVATE_KEY_PATH = os.getenv('VONAGE_APPLICATION_PRIVATE_KEY_PATH') | ||
USER_ID = os.getenv('USER_ID') | ||
|
||
from vonage import Auth, Vonage | ||
from vonage_users import User | ||
|
||
client = Vonage( | ||
Auth( | ||
application_id=VONAGE_APPLICATION_ID, | ||
private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH, | ||
) | ||
) | ||
user: User = client.users.get_user(USER_ID) | ||
|
||
print(user) |
Oops, something went wrong.