-
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.
renamed verify and verifyv2, add numbers and number insight snippets
- Loading branch information
Showing
32 changed files
with
128 additions
and
134 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,27 +1,41 @@ | ||
This quick demo shows how to accept a Number Insight Async Webhook | ||
# Verifying Signed Webhooks Demo | ||
|
||
This quick demo shows how to recieve an incoming Number Insight webhook. | ||
|
||
## Usage | ||
|
||
### Setup | ||
You may want to use a localhost tunnel agent such as [ngrok](https://ngrok.com/) for local testing. | ||
|
||
### Set Up Your Environment | ||
|
||
Install dependencies with `pip` in a virtual environment: | ||
|
||
```bash | ||
python3 -m venv venv | ||
. ./venv/bin/activate | ||
|
||
# Point to the requirements file in the root of the python-code-snippets repo | ||
pip install -r requirements.txt | ||
``` | ||
|
||
### Start Your Localhost Tunnel | ||
|
||
Start ngrok with `ngrok http 8000`. ngrok will give you a forwarding address you can now use to recieve event webhooks. | ||
|
||
### Start the FastAPI Server | ||
|
||
Install using either `pipenv` or `virtualenv`, and then set up the webhooks. | ||
Run the FastAPI server with | ||
|
||
#### `pipenv` | ||
1. Run `pipenv install` | ||
1. Copy `.env.dist` to `.env` and fill in your credentials | ||
1. Run `pipenv run flask` | ||
```bash | ||
fastapi dev number-insight/async-callback/main.py | ||
``` | ||
|
||
#### `virtualenv` | ||
1. Run `virtualenv env` | ||
1. Run `source env/bin/activate` | ||
1. Run `pip install -r requirements.txt` | ||
1. Copy `.env.dist` to `.env` and fill in your credentials | ||
1. Run `flask run` | ||
### Trigger the Lookup | ||
|
||
#### Trigger the lookup | ||
1. Start ngrok with `ngrok http 3000`. ngrok will give you a forwarding address you can now use for your delivery receipts. | ||
1. Edit the `ni-advanced-async-trigger.py` script to add the number to return insights for. | ||
1. Add your ngrok URL as the callback to the `number_insight.get_advanced_info_async` method. | ||
1. Run the trigger script with: | ||
|
||
python ni-advanced-async-trigger.py | ||
|
||
The output of the webhook should appear in the console output of the Flask application | ||
The output of the webhook should appear in the console output of the FastAPI application. |
This file was deleted.
Oops, something went wrong.
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,9 @@ | ||
from fastapi import FastAPI, Request | ||
|
||
app = FastAPI() | ||
|
||
|
||
@app.post('/') | ||
async def display_advanced_number_insight_info(request: Request): | ||
data = await request.json() | ||
print(data) |
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,34 +1,26 @@ | ||
|
||
import os | ||
from os.path import join, dirname | ||
from pprint import pprint | ||
from dotenv import load_dotenv | ||
import vonage | ||
|
||
#Load the environment | ||
envpath = join(dirname(__file__), '../.env') | ||
load_dotenv(envpath) | ||
|
||
#Init the client | ||
client = vonage.Client( | ||
key=os.getenv('VONAGE_API_KEY'), | ||
secret=os.getenv('VONAGE_API_SECRET') | ||
) | ||
dotenv_path = join(dirname(__file__), '../.env') | ||
load_dotenv(dotenv_path) | ||
|
||
insight_number = os.getenv('INSIGHT_NUMBER') | ||
VONAGE_API_KEY = os.getenv('VONAGE_API_KEY') | ||
VONAGE_API_SECRET = os.getenv('VONAGE_API_SECRET') | ||
INSIGHT_NUMBER = os.getenv('INSIGHT_NUMBER') | ||
|
||
#Start the trigger | ||
insight_trigger_json = client.number_insight.get_async_advanced_number_insight( | ||
number=insight_number, | ||
callback=os.getenv('INSIGHT_NUMBER_CALLBACK_WEBHOOK') | ||
from vonage import Auth, Vonage | ||
from vonage_number_insight import ( | ||
AdvancedAsyncInsightRequest, | ||
AdvancedAsyncInsightResponse, | ||
) | ||
|
||
# You can also pass in JSON | ||
'''insight_trigger_json = client.number_insight.get_async_advanced_number_insight({ | ||
"number": insight_number, | ||
"callback": os.getenv('INSIGHT_NUMBER_CALLBACK_WEBHOOK') | ||
}) | ||
''' | ||
client = Vonage(Auth(api_key=VONAGE_API_KEY, api_secret=VONAGE_API_SECRET)) | ||
|
||
# Get the response from api - the data will be available on callback webhook | ||
pprint(insight_trigger_json) | ||
insight: AdvancedAsyncInsightResponse = client.number_insight.get_advanced_info_async( | ||
AdvancedAsyncInsightRequest( | ||
number=INSIGHT_NUMBER, callback='https://example.com/insight' | ||
) | ||
) | ||
pprint(insight) |
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
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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.