this is an hello world for the nexmo voice API https://developer.nexmo.com/voice/voice-api/overview.
To make this app running, you need
- a nexmo api key, api secret : https://dashboard.nexmo.com
- a nexmo lvn (you are gonna put it in NEXMO_LVN) : https://dashboard.nexmo.com/buy-numbers
once you have the necessary data ,you need to create a .env
file in the project root directory with the following variables:
install nvm (https://github.com/nvm-sh/nvm)
from the root directory of this project run:
nvm install
(only the first time)
nvm use
npm install
now you need to configure the .env file. you can run:
npm run first_config <API_KEY> <API_SECRET> <NEXMO_LVN> <APP_NAME>
you can find those values here:
- <API_KEY>, <API_SECRET>: go there https://dashboard.nexmo.com/voice/create-application
- <NEXMO_LVN>: this is the one you boughth there: https://dashboard.nexmo.com/buy-numbers
- APP_NAME: you can put any string you want there
npm run first_config a508b666 6ea37679e0d6a666 447520660591 vapi_ivr_hello_world
what is this doing? this command is creating a nexmo application for you and saving the needed information in a .env file. You should now see a .env file created in your project directory with the following content:
MY_NEXMO_APP_API_KEY=[API_KEY]
MY_NEXMO_APP_API_SECRET=[API_SECRET]
MY_NEXMO_APP_PHONE_NUMBER=[NEXMO_VN]
MY_NEXMO_APP_APPLICATION_NAME=[APP_NAME]
MY_NEXMO_APP_APPLICATION_ID=[APPLICATION_ID]
MY_NEXMO_APP_PRIVATE_KEY=[PRIVATE_KEY]
once everything is configured, you can run the following command:
npm start
note: this is a dev app, so every time
- connect your lvn to your application: https://dashboard.nexmo.com/your-numbers
This project use a logging library called bunyan
whitch is producing json logs.
You may struggle in reading row logs. The logs are printed in the starndard output but also written in the vapi_hello_world.log
file. so my suggestion is:
- install the bunyan cli:
npm install -g bunyan
(you must to this just once) - run the app
- open another terminal on the same directory
- run
tail -f vapi_hello_world.log | bunyan
. you will now see a formatted log.
p.s. bunyan is producing standard json, so you can also use standard unix tools like jq to format the logs: tail -f vapi_hello_world.log | jq
Once your server is running, just call from your phone the LVN number you bougth from nexmo
Take the current app and ask the question: "What do you prefer, fish and chips or potato?" "If you prefer fish and chips press 1, of you prefer potatos is 2"
if the user press one it should hear: "you have selected fish and chips, you should drink it with beer"
if the user press two it should hear: "glad you selected potatos, have a coke with them"