Skip to content

Add new building blocks. #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
May 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,8 @@ ENV/
# Rope project settings
.ropeproject

# nexmo key file
private.key
# nexmo key files
*.key

.DS_Store
settings.json
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

Quickstarts also available for: [Java](https://github.com/nexmo-community/nexmo-java-quickstart), [.NET](https://github.com/nexmo-community/nexmo-dotnet-quickstart), [Node.js](https://github.com/nexmo-community/nexmo-node-quickstart), [PHP](https://github.com/nexmo-community/nexmo-php-quickstart), [Ruby](https://github.com/nexmo-community/nexmo-ruby-quickstart)

The purpose of the quickstart guide is to provide simple examples focused
on one goal. For example, sending and SMS, handling and incoming SMS webhook,
making a Text to Speech call.
The purpose of the Quickstart guide is to provide simple examples focused
on one goal. For example, sending an SMS, handling an incoming SMS webhook,
or making a Text to Speech call.

## Setup

To use this sample you will first need a [Nexmo account][sign-up]. Then rename
the `.env-example` file to `.env` and set the values as required.
To use the examples you will first need a [Nexmo account][sign-up]. Then rename
the `example.env` file to `.env` and set the values as required.

For some of the examples you will need to [buy a number][buy-number].

Expand Down
21 changes: 21 additions & 0 deletions voice/connect-an-inbound-call.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3
from flask import Flask, request, jsonify

app = Flask(__name__)

@app.route("/webhooks/answer")
def answer_call():
ncco = [
{
"action": "connect",
"from": "NEXMO_NUMBER",
"endpoint": [{
"type": 'phone',
"number": "RECIPIENT_NUMBER"
}]
}
]
return jsonify(ncco)

if __name__ == '__main__':
app.run(port=3000)
22 changes: 22 additions & 0 deletions voice/connect-callers-to-a-conference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env python3
from flask import Flask, request, jsonify

app = Flask(__name__)


@app.route("/webhooks/answer")
def answer_call():
ncco = [
{
"action": "talk",
"text": "Please wait while we connect you to the conference"
},
{
"action": "conversation",
"name": CONF_NAME
}]
return jsonify(ncco)


if __name__ == '__main__':
app.run(port=3000)
15 changes: 15 additions & 0 deletions voice/earmuff-a-call.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python3
import nexmo
import time
from pprint import pprint

client = nexmo.Client(
application_id=APPLICATION_ID,
private_key=APPLICATION_PRIVATE_KEY_PATH,
)

response = client.update_call(UUID, action="earmuff")
pprint(response)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of pprint!

time.sleep(5)
response = client.update_call(UUID, action="unearmuff")
pprint(response)
29 changes: 29 additions & 0 deletions voice/join-outbound-calls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env python3
from flask import Flask, request, jsonify

app = Flask(__name__)

@app.route("/webhooks/answer")
def answer_call():
ncco = [
{
"action": "connect",
"from": "NEXMO_NUMBER",
"endpoint": [{
"type": 'phone',
"number": "RECIPIENT_NUMBER_1"
}]
},
{
"action": "connect",
"from": "NEXMO_NUMBER",
"endpoint": [{
"type": 'phone',
"number": "RECIPIENT_NUMBER_2"
}]
}
]
return jsonify(ncco)

if __name__ == '__main__':
app.run(port=3000)
15 changes: 15 additions & 0 deletions voice/mute-a-call.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env python3
import nexmo
import time
from pprint import pprint

client = nexmo.Client(
application_id=APPLICATION_ID,
private_key=APPLICATION_PRIVATE_KEY_PATH,
)

response = client.update_call(UUID, action="mute")
pprint(response)
time.sleep(5)
response = client.update_call(UUID, action="unmute")
pprint(response)
40 changes: 40 additions & 0 deletions voice/record-a-call-with-split-audio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env python3
from flask import Flask, request, jsonify
from pprint import pprint

app = Flask(__name__)

@app.route("/webhooks/answer")
def answer_call():
ncco = [
{
"action": "talk",
"text": "Hi, we will shortly forward your call. This call is recorded for quality assurance purposes."
},
{
"action": "record",
"split" : "conversation",
"eventUrl": ["https://demo.ngrok.io/webhooks/recordings"]
},
{
"action": "connect",
"eventUrl": ["https://demo.ngrok.io/webhooks/event"],
"from": "NEXMO_NUMBER",
"endpoint": [
{
"type": "phone",
"number": "RECIPIENT_NUMBER"
}
]
}
]
return jsonify(ncco)

@app.route("/webhooks/recordings", methods=['POST'])
def recordings():
data = request.get_json()
pprint(data)
return "Webhook received"

if __name__ == '__main__':
app.run(port=3000)
39 changes: 39 additions & 0 deletions voice/record-a-call.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env python3
from flask import Flask, request, jsonify
from pprint import pprint

app = Flask(__name__)

@app.route("/webhooks/answer")
def answer_call():
ncco = [
{
"action": "talk",
"text": "Hi, we will shortly forward your call. This call is recorded for quality assurance purposes."
},
{
"action": "record",
"eventUrl": ["https://demo.ngrok.io/webhooks/recordings"]
},
{
"action": "connect",
"eventUrl": ["https://demo.ngrok.io/webhooks/event"],
"from": "NEXMO_NUMBER",
"endpoint": [
{
"type": "phone",
"number": "RECIPIENT_NUMBER"
}
]
}
]
return jsonify(ncco)

@app.route("/webhooks/recordings", methods=['POST'])
def recordings():
data = request.get_json()
pprint(data)
return "webhook received"

if __name__ == '__main__':
app.run(port=3000)
28 changes: 28 additions & 0 deletions voice/record-a-conversation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env python3
# `eventMethod` is a required workaround currently, otherwise `/webhooks/recordings` is never called.
from flask import Flask, request, jsonify
from pprint import pprint

app = Flask(__name__)

@app.route("/webhooks/answer")
def answer_call():
ncco = [
{
"action": "conversation",
"name": "CONF_NAME",
"record": "true",
"eventMethod": "POST",
"eventUrl": ["https://demo.ngrok.io/webhooks/recordings"]
}
]
return jsonify(ncco)

@app.route("/webhooks/recordings", methods=['POST'])
def recordings():
data = request.get_json()
pprint(data)
return "Webhook received"

if __name__ == '__main__':
app.run(port=3000)
12 changes: 12 additions & 0 deletions voice/retrieve-info-for-a-call.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env python3
import nexmo
from pprint import pprint

client = nexmo.Client(
application_id=APPLICATION_ID,
private_key=APPLICATION_PRIVATE_KEY_PATH,
)

# Note call can be made to current call or a completed call
response = client.get_call("NEXMO_CALL_UUID")
pprint(response)
18 changes: 18 additions & 0 deletions voice/retrieve-info-for-all-calls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python3
import nexmo
from pprint import pprint
from datetime import datetime, timedelta

client = nexmo.Client(
application_id=APPLICATION_ID,
private_key=APPLICATION_PRIVATE_KEY_PATH,
)

NOW = datetime.utcnow()
DATE_END = NOW.replace(microsecond=0).isoformat()+"Z"
DATE_START = (NOW - timedelta(hours=24, minutes=00)).replace(microsecond=0).isoformat()+"Z"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


response = client.get_calls(date_start=DATE_START, date_end=DATE_END)
calls = response['_embedded']['calls']
for call in calls:
pprint(call)
12 changes: 12 additions & 0 deletions voice/transfer-a-call.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env python3
import nexmo
from pprint import pprint

client = nexmo.Client(
application_id=APPLICATION_ID,
private_key=APPLICATION_PRIVATE_KEY_PATH,
)

dest = {"type": "ncco", "url": ["https://developer.nexmo.com/ncco/tts.json"]}
response = client.update_call(UUID, action="transfer", destination=dest)
pprint(response)