-
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
12 changed files
with
163 additions
and
228 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
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,29 +1,24 @@ | ||
#!/usr/bin/env python3 | ||
from flask import Flask, jsonify | ||
import os | ||
from os.path import join, dirname | ||
from dotenv import load_dotenv | ||
import os | ||
from fastapi import FastAPI | ||
from vonage_voice.models import Conversation, NccoAction, Talk | ||
|
||
app = Flask(__name__) | ||
|
||
dotenv_path = join(dirname(__file__), "../.env") | ||
dotenv_path = join(dirname(__file__), '../.env') | ||
load_dotenv(dotenv_path) | ||
|
||
VONAGE_NUMBER = os.environ.get('VONAGE_NUMBER') | ||
YOUR_SECOND_NUMBER = os.environ.get('YOUR_SECOND_NUMBER') | ||
CONFERENCE_NAME = os.environ.get("CONFERENCE_NAME") | ||
|
||
@app.route("/webhooks/answer") | ||
def answer_call(): | ||
ncco = [ | ||
{ | ||
"action": "talk", | ||
"text": "Please wait while we connect you to the conference" | ||
}, | ||
{ | ||
"action": "conversation", | ||
"name": CONFERENCE_NAME | ||
}] | ||
return jsonify(ncco) | ||
app = FastAPI() | ||
|
||
|
||
@app.get('/webhooks/answer') | ||
async def answer_call(): | ||
ncco: list[NccoAction] = [ | ||
Talk(text="Please wait while we connect you to the conference"), | ||
Conversation(name=CONFERENCE_NAME), | ||
] | ||
|
||
if __name__ == '__main__': | ||
app.run(port=3000) | ||
return [action.model_dump(by_alias=True, exclude_none=True) for action in 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,47 @@ | ||
#!/usr/bin/env python3 | ||
from flask import Flask, request, jsonify | ||
|
||
app = Flask(__name__) | ||
|
||
|
||
@app.route("/webhooks/answer", methods=["POST", "GET"]) | ||
def answer_call(): | ||
ncco = [ | ||
{"action": "talk", "text": "Please, tell me something",}, | ||
{ | ||
"action": "input", | ||
"type": ["speech"], | ||
"eventUrl": [ | ||
"{host}{endpoint}".format( | ||
host=request.host_url, endpoint="webhooks/asr" | ||
) | ||
], | ||
"speech": { | ||
"endOnSilence": 1, | ||
"language": "en-US", | ||
"uuid": [request.args.get("uuid")], # Change to request.json.get("uuid") if using POST-JSON webhook format | ||
}, | ||
}, | ||
import os | ||
from os.path import join, dirname | ||
from dotenv import load_dotenv | ||
from fastapi import FastAPI, Body, Request | ||
from vonage_voice.models import Input, NccoAction, Speech, Talk | ||
|
||
dotenv_path = join(dirname(__file__), '../.env') | ||
load_dotenv(dotenv_path) | ||
|
||
VONAGE_NUMBER = os.environ.get('VONAGE_NUMBER') | ||
RECIPIENT_NUMBER = os.environ.get('RECIPIENT_NUMBER') | ||
|
||
app = FastAPI() | ||
|
||
|
||
@app.get('/webhooks/answer') | ||
async def answer_call(request: Request): | ||
ncco: list[NccoAction] = [ | ||
Talk(text=f'Please tell me something.'), | ||
Input( | ||
type=['speech'], | ||
speech=Speech( | ||
endOnSilence=1, | ||
language='en-US', | ||
uuid=[request.query_params.get('uuid')], | ||
), | ||
eventUrl=[str(request.base_url) + '/webhooks/asr'], | ||
), | ||
] | ||
return jsonify(ncco) | ||
|
||
|
||
@app.route("/webhooks/asr", methods=["POST", "GET"]) | ||
def answer_asr(): | ||
body = request.get_json() | ||
if body is not None and "speech" in body: | ||
speech = body["speech"]["results"][0]["text"] | ||
ncco = [ | ||
{"action": "talk", "text": "Hello ,you said {speech}".format(speech=speech)} | ||
] | ||
else: | ||
ncco = [{"action": "talk", "text": "Sorry, i don't undertand. Bye"}] | ||
|
||
return jsonify(ncco) | ||
return [action.model_dump(by_alias=True, exclude_none=True) for action in ncco] | ||
|
||
|
||
if __name__ == "__main__": | ||
app.run(port=3000) | ||
@app.post('/webhooks/asr') | ||
async def answer_asr(data: dict = Body(...)): | ||
if data is not None and 'speech' in data: | ||
speech = data['speech']['results'][0]['text'] | ||
return [ | ||
Talk(text=f'Hello ,you said {speech}').model_dump( | ||
by_alias=True, exclude_none=True | ||
) | ||
] | ||
return [ | ||
Talk(text=f'Sorry, I didn\'t understand your input.').model_dump( | ||
by_alias=True, exclude_none=True | ||
) | ||
] |
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,42 +1,36 @@ | ||
#!/usr/bin/env python3 | ||
from pprint import pprint | ||
from flask import Flask, request, jsonify | ||
|
||
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)) | ||
input_webhook_url = request.url_root + "webhooks/dtmf" | ||
ncco = [ | ||
{ | ||
"action": "talk", | ||
"text": "Hello, please press any key to continue." | ||
}, | ||
{ | ||
"action": "input", | ||
"type": ["dtmf"], | ||
"maxDigits": 1, | ||
"eventUrl": [input_webhook_url] | ||
} | ||
] | ||
return jsonify(ncco) | ||
|
||
|
||
@app.route("/webhooks/dtmf", methods=['POST']) | ||
def dtmf(): | ||
data = request.get_json() | ||
pprint(data) | ||
ncco = [ | ||
{ | ||
"action": "talk", | ||
"text": "You pressed {}, goodbye".format(data['dtmf']) | ||
} | ||
import os | ||
from os.path import join, dirname | ||
from dotenv import load_dotenv | ||
from fastapi import FastAPI, Body, Request | ||
from vonage_voice.models import Input, NccoAction, Talk | ||
|
||
dotenv_path = join(dirname(__file__), '../.env') | ||
load_dotenv(dotenv_path) | ||
|
||
VONAGE_NUMBER = os.environ.get('VONAGE_NUMBER') | ||
RECIPIENT_NUMBER = os.environ.get('RECIPIENT_NUMBER') | ||
|
||
app = FastAPI() | ||
|
||
|
||
@app.get('/webhooks/answer') | ||
async def answer_call(request: Request): | ||
ncco: list[NccoAction] = [ | ||
Talk(text=f'Please enter a digit.'), | ||
Input( | ||
type=['dtmf'], | ||
maxDigits=1, | ||
eventUrl=[str(request.base_url) + '/webhooks/dtmf'], | ||
), | ||
] | ||
return jsonify(ncco) | ||
|
||
return [action.model_dump(by_alias=True, exclude_none=True) for action in ncco] | ||
|
||
if __name__ == '__main__': | ||
app.run(port=3000) | ||
|
||
@app.post('/webhooks/dtmf') | ||
async def answer_dtmf(data: dict = Body(...)): | ||
return [ | ||
Talk(text=f'Hello, you pressed {data['dtmf']}').model_dump( | ||
by_alias=True, exclude_none=True | ||
) | ||
] |
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
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,43 +1,36 @@ | ||
from flask import Flask, request, jsonify | ||
|
||
app = Flask(__name__) | ||
|
||
|
||
@app.route("/webhooks/answer") | ||
def answer_call(): | ||
ncco = [{ | ||
"action": "talk", | ||
"text": "Thanks for calling the notification line" | ||
}, | ||
{ | ||
"action": "notify", | ||
"payload": { | ||
"foo": "bar" | ||
}, | ||
"eventUrl": [ | ||
"{url_root}webhooks/notification".format(url_root=request.url_root) | ||
] | ||
}, | ||
{ | ||
"action": "talk", | ||
"text": "You will never hear me as the notification URL will return an NCCO " | ||
}] | ||
return jsonify(ncco) | ||
|
||
|
||
@app.route("/webhooks/notification", methods=['POST']) | ||
def notification(): | ||
ncco = [{ | ||
"action": "talk", | ||
"text": "Your notification has been received, loud and clear" | ||
}] | ||
return jsonify(ncco) | ||
|
||
|
||
@app.route("/webhooks/event", methods=['POST']) | ||
def event(): | ||
return "OK" | ||
|
||
|
||
if __name__ == '__main__': | ||
app.run(host="localhost", port=3000) | ||
import os | ||
from os.path import join, dirname | ||
from dotenv import load_dotenv | ||
from fastapi import FastAPI, Body, Request | ||
from vonage_voice.models import NccoAction, Notify, Talk | ||
|
||
dotenv_path = join(dirname(__file__), '../.env') | ||
load_dotenv(dotenv_path) | ||
|
||
VONAGE_NUMBER = os.environ.get('VONAGE_NUMBER') | ||
RECIPIENT_NUMBER = os.environ.get('RECIPIENT_NUMBER') | ||
|
||
app = FastAPI() | ||
|
||
|
||
@app.get('/webhooks/answer') | ||
async def inbound_call(request: Request): | ||
ncco: list[NccoAction] = [ | ||
Talk(text=f'Thanks for calling the notification line.'), | ||
Notify( | ||
payload={"foo": "bar"}, | ||
eventUrl=[str(request.base_url) + '/webhooks/notification'], | ||
), | ||
Talk(text=f'You will never hear me as the notification URL will return an NCCO.'), | ||
] | ||
|
||
return [action.model_dump(by_alias=True, exclude_none=True) for action in ncco] | ||
|
||
|
||
@app.post('/webhooks/notification') | ||
async def on_notification(): | ||
return [ | ||
Talk(text=f'Your notification has been received, loud and clear').model_dump( | ||
by_alias=True, exclude_none=True | ||
) | ||
] |
Oops, something went wrong.