Skip to content

Commit 14ff0e6

Browse files
committedNov 8, 2024·
update sms and ni snippets
1 parent 8152405 commit 14ff0e6

7 files changed

+27
-68
lines changed
 

‎number-insight/ni-advanced.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
client = vonage.Client(key=VONAGE_API_KEY, secret=VONAGE_API_SECRET)
1616

1717
insight_json = client.number_insight.get_advanced_number_insight(number=INSIGHT_NUMBER)
18-
pprint(insight_json)
18+
pprint(insight_json)

‎number-insight/ni-basic.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
VONAGE_API_SECRET = os.getenv('VONAGE_API_SECRET')
1111
INSIGHT_NUMBER = os.getenv('INSIGHT_NUMBER')
1212

13-
import vonage
13+
from vonage import Auth, Vonage
14+
from vonage_number_insight import BasicInsightRequest, BasicInsightResponse
1415

15-
client = vonage.Client(key=VONAGE_API_KEY, secret=VONAGE_API_SECRET)
16+
client = Vonage(Auth(api_key=VONAGE_API_KEY, api_secret=VONAGE_API_SECRET))
1617

17-
insight_json = client.number_insight.get_basic_number_insight(number=INSIGHT_NUMBER)
18-
pprint(insight_json)
18+
insight: BasicInsightResponse = client.number_insight.basic_number_insight(
19+
BasicInsightRequest(number=INSIGHT_NUMBER)
20+
)
21+
pprint(insight)

‎number-insight/ni-standard.py

+7-4
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
VONAGE_API_SECRET = os.getenv('VONAGE_API_SECRET')
1111
INSIGHT_NUMBER = os.getenv('INSIGHT_NUMBER')
1212

13-
import vonage
13+
from vonage import Auth, Vonage
14+
from vonage_number_insight import StandardInsightRequest, StandardInsightResponse
1415

15-
client = vonage.Client(key=VONAGE_API_KEY, secret=VONAGE_API_SECRET)
16+
client = Vonage(Auth(api_key=VONAGE_API_KEY, api_secret=VONAGE_API_SECRET))
1617

17-
insight_json = client.number_insight.get_standard_number_insight(number=INSIGHT_NUMBER)
18-
pprint(insight_json)
18+
insight: StandardInsightResponse = client.number_insight.standard_number_insight(
19+
StandardInsightRequest(number=INSIGHT_NUMBER)
20+
)
21+
pprint(insight)

‎sms/delivery-receipts.py

+2-27
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,10 @@
1-
import os
2-
from os.path import join, dirname
3-
4-
from dotenv import load_dotenv
5-
6-
# Load the environment
7-
envpath = join(dirname(__file__), '../.env')
8-
load_dotenv(envpath)
9-
10-
VONAGE_API_KEY = os.getenv("VONAGE_API_KEY")
11-
VONAGE_SIGNATURE_SECRET = os.getenv("VONAGE_SIGNATURE_SECRET")
12-
VONAGE_SIGNATURE_SECRET_METHOD = os.getenv("VONAGE_SIGNATURE_SECRET_METHOD")
13-
141
from fastapi import FastAPI, Request
15-
from vonage import Auth, Vonage
16-
17-
client = Vonage(
18-
Auth(
19-
api_key=VONAGE_API_KEY,
20-
signature_secret=VONAGE_SIGNATURE_SECRET,
21-
signature_method=VONAGE_SIGNATURE_SECRET_METHOD,
22-
)
23-
)
2+
from pprint import pprint
243

254
app = FastAPI()
265

276

287
@app.get('/delivery-receipt')
298
async def get_delivery_receipt(request: Request):
309
data = await request.json()
31-
32-
if client.http_client.auth.check_signature(data):
33-
print('Valid signature')
34-
else:
35-
print('Invalid signature')
10+
pprint(data)

‎sms/dlr-flask.py

-16
This file was deleted.

‎sms/receive-flask.py

-16
This file was deleted.

‎sms/receive-sms.py

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from pprint import pprint
2+
from fastapi import FastAPI, Request
3+
4+
app = FastAPI()
5+
6+
7+
@app.post('/inbound')
8+
async def inbound_message(request: Request):
9+
data = await request.json()
10+
pprint(data)

0 commit comments

Comments
 (0)
Please sign in to comment.