Skip to content

Commit

Permalink
add get info/control media voice snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
maxkahan committed Jan 10, 2025
1 parent 5809813 commit c3db853
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 85 deletions.
1 change: 1 addition & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ START_DATE='START_DATE'
CONFERENCE_NAME='NAME_OF_YOUR_CONFERENCE'
YOUR_SECOND_NUMBER='YOUR_SECOND_NUMBER'
RECORDING_URL='RECORDING_URL'
CALL_UUID='CALL_UUID'

# Numbers
COUNTRY_CODE='GB'
Expand Down
35 changes: 19 additions & 16 deletions voice/earmuff-a-call.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
#!/usr/bin/env python3
import time
import os
from os.path import join, dirname
from pprint import pprint
from time import sleep
from dotenv import load_dotenv
import vonage

dotenv_path = join(dirname(__file__), "../.env")
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")
UUID = os.environ.get("UUID")
client = vonage.Client(
application_id=VONAGE_APPLICATION_ID,
private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH,
VONAGE_APPLICATION_ID = os.environ.get('VONAGE_APPLICATION_ID')
VONAGE_APPLICATION_PRIVATE_KEY_PATH = os.environ.get(
'VONAGE_APPLICATION_PRIVATE_KEY_PATH'
)

response = client.voice.update_call(UUID, action="earmuff")
pprint(response)
time.sleep(5)
response = client.voice.update_call(UUID, action="unearmuff")
pprint(response)
CALL_UUID = os.environ.get('CALL_UUID')

from vonage import Auth, Vonage

client = Vonage(
Auth(
application_id=VONAGE_APPLICATION_ID,
private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH,
)
)

client.voice.earmuff(CALL_UUID)
sleep(5)
client.voice.unearmuff(CALL_UUID)
1 change: 0 additions & 1 deletion voice/get-recording.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from pprint import pprint
import os
from os.path import join, dirname
from dotenv import load_dotenv
Expand Down
34 changes: 18 additions & 16 deletions voice/mute-a-call.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
#!/usr/bin/env python3
import time
import os
from os.path import join, dirname
from pprint import pprint
import vonage
from time import sleep
from dotenv import load_dotenv

dotenv_path = join(dirname(__file__), "../.env")
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")
UUID = os.environ.get("UUID")
VONAGE_APPLICATION_ID = os.environ.get('VONAGE_APPLICATION_ID')
VONAGE_APPLICATION_PRIVATE_KEY_PATH = os.environ.get(
'VONAGE_APPLICATION_PRIVATE_KEY_PATH'
)

CALL_UUID = os.environ.get('CALL_UUID')

from vonage import Auth, Vonage

client = vonage.Client(
application_id=VONAGE_APPLICATION_ID,
private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH
client = Vonage(
Auth(
application_id=VONAGE_APPLICATION_ID,
private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH,
)
)

response = client.voice.update_call(UUID, action="mute")
pprint(response)
time.sleep(5)
response = client.voice.update_call(UUID, action="unmute")
pprint(response)
client.voice.mute(CALL_UUID)
sleep(5)
client.voice.unmute(CALL_UUID)
35 changes: 25 additions & 10 deletions voice/play-audio-stream-into-call.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
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")
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")
VONAGE_CALL_UUID = os.environ.get("UUID")
VONAGE_APPLICATION_ID = os.environ.get('VONAGE_APPLICATION_ID')
VONAGE_APPLICATION_PRIVATE_KEY_PATH = os.environ.get(
'VONAGE_APPLICATION_PRIVATE_KEY_PATH'
)

CALL_UUID = os.environ.get('CALL_UUID')

from vonage import Auth, Vonage
from vonage_voice.models import AudioStreamOptions, CallMessage


client = Vonage(
Auth(
application_id=VONAGE_APPLICATION_ID,
private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH,
)
)

client = vonage.Client(
application_id=VONAGE_APPLICATION_ID,
private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH
response: CallMessage = client.voice.play_audio_into_call(
CALL_UUID,
audio_stream_options=AudioStreamOptions(
stream_url=['https://example.com/ringtone.mp3']
),
)

stream_url = 'https://nexmo-community.github.io/ncco-examples/assets/voice_api_audio_streaming.mp3'
client.voice.send_audio(VONAGE_CALL_UUID, stream_url=[stream_url])
pprint(response)
29 changes: 20 additions & 9 deletions voice/play-dtmf-into-call.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
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")
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")
VONAGE_CALL_UUID = os.environ.get("UUID")
VONAGE_APPLICATION_ID = os.environ.get('VONAGE_APPLICATION_ID')
VONAGE_APPLICATION_PRIVATE_KEY_PATH = os.environ.get(
'VONAGE_APPLICATION_PRIVATE_KEY_PATH'
)

CALL_UUID = os.environ.get('CALL_UUID')

from vonage import Auth, Vonage
from vonage_voice.models import CallMessage

client = vonage.Client(
application_id=VONAGE_APPLICATION_ID,
private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH,

client = Vonage(
Auth(
application_id=VONAGE_APPLICATION_ID,
private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH,
)
)

client.voice.send_dtmf(VONAGE_CALL_UUID, digits='1234')
response: CallMessage = client.voice.play_dtmf_into_call(uuid=CALL_UUID, dtmf='1234p*#')

pprint(response)
31 changes: 22 additions & 9 deletions voice/play-tts-into-call.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
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")
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")
VONAGE_CALL_UUID = os.environ.get("UUID")
VONAGE_APPLICATION_ID = os.environ.get('VONAGE_APPLICATION_ID')
VONAGE_APPLICATION_PRIVATE_KEY_PATH = os.environ.get(
'VONAGE_APPLICATION_PRIVATE_KEY_PATH'
)

CALL_UUID = os.environ.get('CALL_UUID')

from vonage import Auth, Vonage
from vonage_voice.models import CallMessage, TtsStreamOptions


client = Vonage(
Auth(
application_id=VONAGE_APPLICATION_ID,
private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH,
)
)

client = vonage.Client(
application_id=VONAGE_APPLICATION_ID,
private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH,
response: CallMessage = client.voice.play_tts_into_call(
uuid=CALL_UUID, tts_options=TtsStreamOptions(text='Hello from Vonage.')
)

client.voice.send_speech(VONAGE_CALL_UUID, text='Hello from Vonage')
pprint(response)
23 changes: 14 additions & 9 deletions voice/retrieve-info-for-a-call.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
#!/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")
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")
VONAGE_CALL_UUID = os.environ.get("UUID")
VONAGE_APPLICATION_ID = os.environ.get('VONAGE_APPLICATION_ID')
VONAGE_APPLICATION_PRIVATE_KEY_PATH = os.environ.get(
'VONAGE_APPLICATION_PRIVATE_KEY_PATH'
)

client = vonage.Client(
CALL_UUID = os.environ.get('CALL_UUID')

from vonage import Auth, Vonage
from vonage_voice.models import CallInfo

client = Vonage(
Auth(
application_id=VONAGE_APPLICATION_ID,
private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH,
)
)

# Note call can be made to current call or a completed call
response = client.voice.get_call(VONAGE_CALL_UUID)
response: CallInfo = client.voice.get_call(CALL_UUID)
pprint(response)
38 changes: 23 additions & 15 deletions voice/retrieve-info-for-all-calls.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
#!/usr/bin/env python3
import os
from datetime import datetime, timedelta, timezone
from pprint import pprint
import os
from os.path import join, dirname
from datetime import datetime, timedelta
import vonage
from dotenv import load_dotenv

dotenv_path = join(dirname(__file__), "../.env")
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")
VONAGE_APPLICATION_ID = os.environ.get('VONAGE_APPLICATION_ID')
VONAGE_APPLICATION_PRIVATE_KEY_PATH = os.environ.get(
'VONAGE_APPLICATION_PRIVATE_KEY_PATH'
)

from vonage import Auth, Vonage
from vonage_voice.models import ListCallsFilter

client = vonage.Client(
application_id=VONAGE_APPLICATION_ID,
private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH,
client = Vonage(
Auth(
application_id=VONAGE_APPLICATION_ID,
private_key=VONAGE_APPLICATION_PRIVATE_KEY_PATH,
)
)

NOW = datetime.utcnow()
DATE_END = NOW.replace(microsecond=0).isoformat()+"Z"
DATE_START = (NOW - timedelta(hours=24, minutes=00)).replace(microsecond=0).isoformat()+"Z"

response = client.voice.get_calls(date_start=DATE_START, date_end=DATE_END)
calls = response['_embedded']['calls']
NOW = datetime.now(timezone.utc)
DATE_END = NOW.replace(microsecond=0).isoformat()
DATE_START = (NOW - timedelta(hours=24, minutes=00)).replace(microsecond=0).isoformat()

calls, _ = client.voice.list_calls(
ListCallsFilter(date_start=DATE_START, date_end=DATE_END)
)

for call in calls:
pprint(call)

0 comments on commit c3db853

Please sign in to comment.