Skip to content

Commit 8b8f840

Browse files
committed
add server and messenger snippets
1 parent 9c8cad9 commit 8b8f840

27 files changed

+288
-411
lines changed

.env.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@ WHATSAPP_NUMBER='YOUR_WHATSAPP_NUMBER'
1515
CATALOG_ID='YOUR_CATALOG_ID'
1616
PRODUCT_RETAILER_ID='YOUR_PRODUCT_RETAILER_ID'
1717
VIBER_SERVICE_MESSAGE_ID='YOUR_VIBER_SERVICE_MESSAGE_ID'
18+
AUDIO_URL='EXAMPLE_AUDIO_URL'
1819
IMAGE_URL='EXAMPLE_IMAGE_URL'
20+
FILE_URL='EXAMPLE_FILE_URL'
21+
VIDEO_URL='EXAMPLE_VIDEO_URL'
1922
WHATSAPP_TEMPLATE_REPLACEMENT_TEXT='EXAMPLE_TEMPLATE_REPLACEMENT_TEXT'
2023
RCS_SENDER_ID='YOUR_RCS_SENDER_ID'
2124

decode-jwt/README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Verifying Signed Webhooks Demo
2+
3+
This quick demo shows how to verify an incoming Webhook signature by decoding the incoming JWT sent by Vonage.
4+
5+
For signed incoming SMS signatures through the Messaging API, please see the snippet for verifying a signed incoming SMS message instead.
6+
7+
## Usage
8+
9+
You may want to use a localhost tunnel agent such as [ngrok](https://ngrok.com/) for local testing.
10+
11+
### Set Up Your Enviroment
12+
13+
Install dependencies with `pip` in a virtual environment:
14+
15+
```bash
16+
python3 -m venv venv
17+
. ./venv/bin/activate
18+
19+
# Point to the requirements file in the root of the python-code-snippets repo
20+
pip install -r requirements.txt
21+
```
22+
23+
### Set Up an Incoming Webhook
24+
1. Start ngrok with `ngrok http 8000`. ngrok will give you a forwarding address you can now use to recieve event webhooks.
25+
1. Go to the [Customer Dashboard](https://dashboard.nexmo.com/sign-in).
26+
1. Click on ["Applications"](https://dashboard.nexmo.com/applications).
27+
1. Click the three dots and select "Edit" for the application you are using.
28+
1. Under "Capabilities", enter `https://your-ngrok-url/events` for the Voice capability.
29+
1. Click "Save".
30+
31+
### Start the FastAPI Server
32+
33+
Run the FastAPI server with
34+
35+
```bash
36+
fastapi dev decode-jwt/main.py
37+
```
38+
39+
You can now create a voice call using the voice sample in this repo. This sample app will verify the incoming signature.

decode-jwt/main.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
11+
VONAGE_SIGNATURE = os.getenv('VONAGE_SIGNATURE')
12+
13+
from fastapi import FastAPI, Request
14+
from vonage_jwt.verify_jwt import verify_signature
15+
16+
app = FastAPI()
17+
18+
19+
@app.get('/events')
20+
async def verify_signed_webhook(request: Request):
21+
# Need to get the JWT after "Bearer " in the authorization header
22+
auth_header = request.headers["authorization"].split()
23+
token = auth_header[1].strip()
24+
25+
if verify_signature(token, VONAGE_SIGNATURE):
26+
print('Valid signature')
27+
else:
28+
print('Invalid signature')

initialize/application.py

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

initialize/basic.py

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

initialize/full.py

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

jwt/decode-jwt/.env.dist

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

jwt/decode-jwt/Pipfile

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

jwt/decode-jwt/README.md

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

jwt/decode-jwt/app.py

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

0 commit comments

Comments
 (0)