Skip to content

Commit

Permalink
Merge pull request #17 from Nexmo/cli-update
Browse files Browse the repository at this point in the history
Replaces Nexmo with Vonage
  • Loading branch information
amdcavallaro authored Nov 23, 2021
2 parents 4259376 + 9a625ad commit aa914de
Show file tree
Hide file tree
Showing 6 changed files with 5,172 additions and 53 deletions.
42 changes: 21 additions & 21 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
# Nexmo Voice API Call Transcription with Amazon Transcribe
# Vonage Voice API Call Transcription with Amazon Transcribe

This is example code for a [tutorial](https://developer.nexmo.com/use-cases/trancribe-amazon-api) that shows you how to transcribe a phone call automatically using the Amazon Transcribe API. You'll need two handsets with two different phone numbers to test this.

It uses the Nexmo Voice API to initiate and record the call. The call audio is created in your local `recordings` folder and uploaded to an S3 bucket.
It uses the Vonage Voice API to initiate and record the call. The call audio is created in your local `recordings` folder and uploaded to an S3 bucket.

Amazon Cloudwatch triggers a serverless Lambda function when the transcription job has completed. Transcripts are created in S3 and downloaded to your application's `transcripts` folder.
Amazon Cloudwatch triggers a serverless Lambda function when the transcription job has completed. Transcripts are created in S3 and downloaded to your application's `transcripts` folder.

## Welcome to Nexmo
## Welcome to Vonage

If you're new to Nexmo, you can [sign up for a Nexmo account](https://dashboard.nexmo.com/sign-up?utm_source=DEV_REL&utm_medium=github&utm_campaign=amazon-transcribe-call) and get some free credit to get you started.
If you're new to Vonage, you can [sign up for a Vonage account](https://dashboard.nexmo.com/sign-up?utm_source=DEV_REL&utm_medium=github&utm_campaign=amazon-transcribe-call) and get some free credit to get you started.

## Setup

### Install the Nexmo CLI
### Install the Vonage CLI

Run the following at a terminal prompt to install the CLI and configure it with your `api_key` and `api_secret`, which you will find in the [Developer Dashboard](https://dashboard.nexmo.com):

```
npm install -g nexmo-cli
nexmo setup <API_KEY> <API_SECRET>
vonage config:set --apiKey=<API_KEY> --apiSecret=<API_SECRET>
```

### Purchase a Nexmo number
### Purchase a Vonage number

If you don't already have one, buy a Nexmo virtual number to receive inbound calls.
If you don't already have one, buy a Vonage virtual number to receive inbound calls.

List available numbers (replace `GB` with your [two-character country code](https://www.iban.com/country-codes)):

```
nexmo number:search GB
vonage numbers:search GB
```

Purchase one of the numbers:

```
nexmo number:buy 447700900001
vonage numbers:buy 447700900001
```

### Create a Voice API application

Use the CLI to create a Voice API application with the webhooks that will be responsible for answering a call on your Nexmo number (`/webhooks/answer`) and logging call events (`/webhooks/event`), respectively. Replace `example.com` in the following command with your own public-facing URL host name (consider using [ngrok](https://ngrok.io) for testing purposes, and if you do use it, run it now to get the temporary URLs that `ngrok` provides and leave it running to prevent the URLs changing).
Use the CLI to create a Voice API application with the webhooks that will be responsible for answering a call on your Vonage number (`/webhooks/answer`) and logging call events (`/webhooks/event`), respectively. Replace `example.com` in the following command with your own public-facing URL host name (consider using [ngrok](https://ngrok.io) for testing purposes, and if you do use it, run it now to get the temporary URLs that `ngrok` provides and leave it running to prevent the URLs changing).

Run the command in the application's root directory:

```
nexmo app:create "My Echo Server" https://example.com/webhooks/answer https://example.com/webhooks/event --keyfile private.key
vonage apps:create "My Echo Server" --voice_answer_url=https://example.com/webhooks/answer --voice_event_url=https://example.com/webhooks/event
```

Make a note of the Application ID returned by this command. It will also download your `private.key` file which the Voice API uses to authenticate your application.

### Link the Voice API application to your Nexmo number
### Link the Voice API application to your Vonage number

Use the application ID to link your virtual number:

```
nexmo link:app <NUMBER> <APPLICATION_ID>
vonage apps:link --number=<NUMBER>
```

### Install dependencies
Expand Down Expand Up @@ -82,8 +82,8 @@ aws s3 mb s3://your-transcription-bucket-name --region us-east-1

Copy `example.env` to `.env` and configure the following settings:

* `NEXMO_APPLICATION_ID`: The Nexmo Voice Application ID you created earlier
* `NEXMO_PRIVATE_KEY_FILE`: The name of your private key file, which should be in the root of your application directory. E.g. `private.key`
* `VONAGE_APPLICATION_ID`: The Vonage Voice Application ID you created earlier
* `VONAGE_PRIVATE_KEY_FILE`: The name of your private key file, which should be in the root of your application directory. E.g. `private.key`
* `OTHER_PHONE_NUMBER`: Another phone number you can call to create a conversation
* `AWS_KEY`: Your Amazon Web Services key
* `AWS_SECRET`: Your Amazon Web Services secret
Expand Down Expand Up @@ -113,7 +113,7 @@ serverless deploy
node index.js
```

2. Call your Nexmo virtual number from one of your personal numbers. The other number you specified in the `OTHER_PHONE_NUMBER` setting should ring - answer it when it does.
2. Call your Vonage virtual number from one of your personal numbers. The other number you specified in the `OTHER_PHONE_NUMBER` setting should ring - answer it when it does.

3. Speak a few words into each handset. When you're finished, disconnect both.

Expand All @@ -136,13 +136,13 @@ If you have more than two numbers, you can add more callers to the conversation.
We love to hear from you so if you have questions, comments or find a bug in the project, let us know! You can either:

* Open an issue on this repository
* Tweet at us! We're [@NexmoDev on Twitter](https://twitter.com/NexmoDev)
* Or [join the Nexmo Community Slack](https://developer.nexmo.com/community/slack)
* Tweet at us! We're [@VonageDev on Twitter](https://twitter.com/VonageDev)
* Or [join the Vonage Community Slack](https://developer.vonage.com/community/slack)

## Further Reading

* Read the [tutorial](https://developer.nexmo.com/use-cases/trancribe-amazon-api) that accompanies this demo application to learn how it was put together.
* Nexmo Voice API
* Vonage Voice API
* [Voice API call recording guide](/voice/voice-api/guides/recording)
* ["Record a call" code snippet](/voice/voice-api/code-snippets/record-a-call)
* [Voice API reference](/api/voice)
Expand Down
10 changes: 5 additions & 5 deletions example.env
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Nexmo settings
NEXMO_APPLICATION_ID=aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeee
NEXMO_PRIVATE_KEY_FILE=private.key
# Vonage settings
VONAGE_APPLICATION_ID=aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeee
VONAGE_PRIVATE_KEY_FILE=private.key

# Call settings
OTHER_PHONE_NUMBER=442079460000
Expand All @@ -10,5 +10,5 @@ AWS_KEY=
AWS_SECRET=
AWS_REGION=us-east-1
S3_PATH=https://s3-us-east-1.amazonaws.com
S3_AUDIO_BUCKET_NAME=nexmo-audio-1234
S3_TRANSCRIPTS_BUCKET_NAME=nexmo-transcripts-1234
S3_AUDIO_BUCKET_NAME=vonage-audio-1234
S3_TRANSCRIPTS_BUCKET_NAME=vonage-transcripts-1234
12 changes: 6 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require("dotenv").config()

const express = require("express")
const bodyParser = require("body-parser")
const Nexmo = require("nexmo")
const Vonage = require("@vonage/server-sdk")
const AWS = require("aws-sdk")
const shortid = require("shortid")
const fs = require("fs")
Expand All @@ -11,11 +11,11 @@ const options = {
appendToUserAgent: "amazon-transcribe-call/1.0.0",
}

const nexmo = new Nexmo({
const vonage = new Vonage({
apiKey: "not_used", // Voice applications don't use API key or secret
apiSecret: "not_used",
applicationId: process.env.NEXMO_APPLICATION_ID,
privateKey: __dirname + "/" + process.env.NEXMO_PRIVATE_KEY_FILE
applicationId: process.env.VONAGE_APPLICATION_ID,
privateKey: __dirname + "/" + process.env.VONAGE_PRIVATE_KEY_FILE
})

AWS.config.update({
Expand Down Expand Up @@ -60,14 +60,14 @@ app.post('/webhooks/events', (req, res) => {
})

app.post('/webhooks/recording', (req, res) => {
let audioFileName = `nexmo-${shortid.generate()}.mp3`
let audioFileName = `vonage-${shortid.generate()}.mp3`
//let audioFileLocalPath = `./recordings/${audioFileName}`
let audioFileLocalPath = `./recordings/${audioFileName}`

console.log("recording...")
console.log(req.body)

nexmo.files.save(req.body.recording_url, audioFileLocalPath, (err, res) => {
vonage.files.save(req.body.recording_url, audioFileLocalPath, (err, res) => {
if (err) {
console.log("Could not save audio file")
console.error(err)
Expand Down
Loading

0 comments on commit aa914de

Please sign in to comment.