Skip to content

Commit b99c5de

Browse files
committed
renamed verify and verifyv2, add numbers and number insight snippets
1 parent 14ff0e6 commit b99c5de

32 files changed

+128
-134
lines changed

number-insight/async-callback/.env.dist

Lines changed: 0 additions & 4 deletions
This file was deleted.

number-insight/async-callback/Pipfile

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,41 @@
1-
This quick demo shows how to accept a Number Insight Async Webhook
1+
# Verifying Signed Webhooks Demo
2+
3+
This quick demo shows how to recieve an incoming Number Insight webhook.
24

35
## Usage
46

5-
### Setup
7+
You may want to use a localhost tunnel agent such as [ngrok](https://ngrok.com/) for local testing.
8+
9+
### Set Up Your Environment
10+
11+
Install dependencies with `pip` in a virtual environment:
12+
13+
```bash
14+
python3 -m venv venv
15+
. ./venv/bin/activate
16+
17+
# Point to the requirements file in the root of the python-code-snippets repo
18+
pip install -r requirements.txt
19+
```
20+
21+
### Start Your Localhost Tunnel
22+
23+
Start ngrok with `ngrok http 8000`. ngrok will give you a forwarding address you can now use to recieve event webhooks.
24+
25+
### Start the FastAPI Server
626

7-
Install using either `pipenv` or `virtualenv`, and then set up the webhooks.
27+
Run the FastAPI server with
828

9-
#### `pipenv`
10-
1. Run `pipenv install`
11-
1. Copy `.env.dist` to `.env` and fill in your credentials
12-
1. Run `pipenv run flask`
29+
```bash
30+
fastapi dev number-insight/async-callback/main.py
31+
```
1332

14-
#### `virtualenv`
15-
1. Run `virtualenv env`
16-
1. Run `source env/bin/activate`
17-
1. Run `pip install -r requirements.txt`
18-
1. Copy `.env.dist` to `.env` and fill in your credentials
19-
1. Run `flask run`
33+
### Trigger the Lookup
2034

21-
#### Trigger the lookup
22-
1. Start ngrok with `ngrok http 3000`. ngrok will give you a forwarding address you can now use for your delivery receipts.
35+
1. Edit the `ni-advanced-async-trigger.py` script to add the number to return insights for.
36+
1. Add your ngrok URL as the callback to the `number_insight.get_advanced_info_async` method.
2337
1. Run the trigger script with:
2438

2539
python ni-advanced-async-trigger.py
2640

27-
The output of the webhook should appear in the console output of the Flask application
41+
The output of the webhook should appear in the console output of the FastAPI application.

number-insight/async-callback/app.py

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from fastapi import FastAPI, Request
2+
3+
app = FastAPI()
4+
5+
6+
@app.post('/')
7+
async def display_advanced_number_insight_info(request: Request):
8+
data = await request.json()
9+
print(data)
Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,26 @@
1-
21
import os
32
from os.path import join, dirname
43
from pprint import pprint
54
from dotenv import load_dotenv
6-
import vonage
7-
8-
#Load the environment
9-
envpath = join(dirname(__file__), '../.env')
10-
load_dotenv(envpath)
115

12-
#Init the client
13-
client = vonage.Client(
14-
key=os.getenv('VONAGE_API_KEY'),
15-
secret=os.getenv('VONAGE_API_SECRET')
16-
)
6+
dotenv_path = join(dirname(__file__), '../.env')
7+
load_dotenv(dotenv_path)
178

18-
insight_number = os.getenv('INSIGHT_NUMBER')
9+
VONAGE_API_KEY = os.getenv('VONAGE_API_KEY')
10+
VONAGE_API_SECRET = os.getenv('VONAGE_API_SECRET')
11+
INSIGHT_NUMBER = os.getenv('INSIGHT_NUMBER')
1912

20-
#Start the trigger
21-
insight_trigger_json = client.number_insight.get_async_advanced_number_insight(
22-
number=insight_number,
23-
callback=os.getenv('INSIGHT_NUMBER_CALLBACK_WEBHOOK')
13+
from vonage import Auth, Vonage
14+
from vonage_number_insight import (
15+
AdvancedAsyncInsightRequest,
16+
AdvancedAsyncInsightResponse,
2417
)
2518

26-
# You can also pass in JSON
27-
'''insight_trigger_json = client.number_insight.get_async_advanced_number_insight({
28-
"number": insight_number,
29-
"callback": os.getenv('INSIGHT_NUMBER_CALLBACK_WEBHOOK')
30-
})
31-
'''
19+
client = Vonage(Auth(api_key=VONAGE_API_KEY, api_secret=VONAGE_API_SECRET))
3220

33-
# Get the response from api - the data will be available on callback webhook
34-
pprint(insight_trigger_json)
21+
insight: AdvancedAsyncInsightResponse = client.number_insight.get_advanced_info_async(
22+
AdvancedAsyncInsightRequest(
23+
number=INSIGHT_NUMBER, callback='https://example.com/insight'
24+
)
25+
)
26+
pprint(insight)

number-insight/ni-advanced.py

Lines changed: 7 additions & 4 deletions
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 AdvancedSyncInsightRequest, AdvancedSyncInsightResponse
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_advanced_number_insight(number=INSIGHT_NUMBER)
18-
pprint(insight_json)
18+
insight: AdvancedSyncInsightResponse = client.number_insight.get_advanced_info_sync(
19+
AdvancedSyncInsightRequest(number=INSIGHT_NUMBER)
20+
)
21+
pprint(insight)

number-insight/ni-basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
client = Vonage(Auth(api_key=VONAGE_API_KEY, api_secret=VONAGE_API_SECRET))
1717

18-
insight: BasicInsightResponse = client.number_insight.basic_number_insight(
18+
insight: BasicInsightResponse = client.number_insight.get_basic_info(
1919
BasicInsightRequest(number=INSIGHT_NUMBER)
2020
)
2121
pprint(insight)

number-insight/ni-standard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
client = Vonage(Auth(api_key=VONAGE_API_KEY, api_secret=VONAGE_API_SECRET))
1717

18-
insight: StandardInsightResponse = client.number_insight.standard_number_insight(
18+
insight: StandardInsightResponse = client.number_insight.get_standard_info(
1919
StandardInsightRequest(number=INSIGHT_NUMBER)
2020
)
2121
pprint(insight)

numbers/buy.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@
1010
VONAGE_NUMBER = os.getenv("VONAGE_NUMBER")
1111
COUNTRY_CODE = os.getenv("COUNTRY_CODE")
1212

13-
import vonage
13+
from vonage import Auth, Vonage
14+
from vonage_numbers import NumberParams, NumbersStatus
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-
try:
18-
response = client.numbers.buy_number({"country": COUNTRY_CODE, "msisdn": VONAGE_NUMBER})
19-
print("Number purchased")
20-
except Exception as exc:
21-
print("Error purchasing number", exc)
18+
status: NumbersStatus = client.numbers.buy_number(
19+
params=NumberParams(
20+
country=COUNTRY_CODE,
21+
msisdn=VONAGE_NUMBER,
22+
)
23+
)
24+
25+
print(status.model_dump())

0 commit comments

Comments
 (0)