-
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.
- Loading branch information
Showing
5 changed files
with
67 additions
and
59 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
#!/usr/bin/env python3 | ||
from flask import Flask, jsonify | ||
import os | ||
from os.path import join, dirname | ||
from dotenv import load_dotenv | ||
from fastapi import FastAPI | ||
from vonage_voice.models import Connect, PhoneEndpoint | ||
|
||
app = Flask(__name__) | ||
VONAGE_NUMBER = os.environ.get('VONAGE_NUMBER') | ||
YOUR_SECOND_NUMBER = os.environ.get('YOUR_SECOND_NUMBER') | ||
|
||
dotenv_path = join(dirname(__file__), '../.env') | ||
load_dotenv(dotenv_path) | ||
app = FastAPI() | ||
|
||
@app.route("/webhooks/answer") | ||
def answer_call(): | ||
|
||
@app.get('/answer') | ||
async def inbound_call(): | ||
ncco = [ | ||
{ | ||
"action": "connect", | ||
"from": "VONAGE_NUMBER", | ||
"endpoint": [{ | ||
"type": 'phone', | ||
"number": "YOUR_SECOND_NUMBER" | ||
}] | ||
} | ||
Connect( | ||
endpoint=[PhoneEndpoint(number='123456789')], from_=VONAGE_NUMBER | ||
).model_dump(by_alias=True, exclude_none=True) | ||
] | ||
return jsonify(ncco) | ||
|
||
|
||
if __name__ == '__main__': | ||
app.run(port=3000) | ||
return ncco |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,13 @@ | ||
#!/usr/bin/env python3 | ||
from fastapi import FastAPI, Query | ||
from vonage_voice.models import Talk | ||
|
||
from flask import Flask, request, jsonify | ||
app = FastAPI() | ||
|
||
app = Flask(__name__) | ||
|
||
|
||
@app.route("/webhooks/answer") | ||
def answer_call(): | ||
for param_key, param_value in request.args.items(): | ||
print("{}: {}".format(param_key, param_value)) | ||
|
||
from_ = request.args['from'] | ||
|
||
return jsonify([ | ||
{ | ||
"action": "talk", | ||
"text": "Thank you for calling from " + " ".join(from_) | ||
} | ||
]) | ||
|
||
|
||
if __name__ == '__main__': | ||
app.run(port=3000) | ||
@app.get('/answer') | ||
async def answer_call(from_: str = Query(..., alias='from')): | ||
return [ | ||
Talk(text=f'Thank you for calling from {from_}').model_dump( | ||
by_alias=True, exclude_none=True | ||
) | ||
] |