Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

conversation-api-function

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

conversation-api-function

conversation-api-function is an opnionated tool to start using vonage conversation api https://developer.nexmo.com/conversation

  • 0.0.17
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
increased by200%
Maintainers
1
Weekly downloads
 
Created
Source

conversation-service-functions

what is this project?

this is a cli tool that will allow you to write simple application for the Vonage conversation api https://developer.nexmo.com/conversation in your local env with minimal configuration.

install prerequisites

nexmo credentials

To make this app running, you need

install node 14+

suggested way to install node is via nvm (https://github.com/nvm-sh/nvm/pulls). so:

install nvm

if you have brew install, just run

brew install nvm

if not, then curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

(read here for more details: https://github.com/nvm-sh/nvm)

install node with nvm

now that nvm is installed, just run:

nvm install 14

install the tool

npm install -g conversation-api-function

first time config

the first time you run this, you need to have your api-key, api-secret and an lvn (look the prerequisites section above):

conversation-api-function config-new -a <api-key> -s <api-secret> -l <lvn>

if you struggle with this, run: conversation-api-function config-new -h

create a new conversation function

conversation-api-function new my_capi_fn

run it

conversation-api-function run my_capi_fn

now call you lvn, you should hear an "hello world" mesage

open the following file my_capi_fn/index.js for more info

run it part 2, make your life easier

you can now run every example you find in the examples section without the need to configure the app again.

you can also run the app in an alternative way:

cd my_capi_fn
npm install
npm run

in this way you are gonna install the dependencies and run it without the need to use the global tool

further docs:

check the internal conversations api here: https://jurgob.github.io/conversation-service-docs/#/openapiui and the possible events here: https://jurgob.github.io/conversation-service-docs/#/custom

some tricks

This project use a logging library called bunyan whitch is producing json logs. if you install bunyan ( npm install -g bunyan ) then you can run: conversation-api-function run my_capi_fn | 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

how to write a function

when you start a new project, there's documentation in the example. If you are curious, take.a look here:

https://github.com/jurgob/conversation-api-function/blob/main/template/index.js

Examples

Once you have configured conversation-api-functions, you can run every project without configuring this tools again. Here are some examples you can run just coloning it and executing it with the following commans:

downloding / installing the repo:

git clone <GIT_REPO> <MY_DIR>
cd <MY_DIR>
nvm use
npm install

then run it with:

conversation-api-function run <MY_DIR>

e.g:

git clone https://github.com/jurgob/phone_inbound_asr my_capi_fn
cd my_capi_fn
nvm use
npm install
conversation-api-function run .

Examples

Use a Real Redis

by default the storage client is saving your data in-memory, so every time you restart you loose al your data. To use a real redis server instead, you just need to set the env var CONV_API_FUNC_REDIS_URL. See the example below for more details

use a docker redis for local deployment

be sure you have installed docker to install redis in your local host, you just need to run: docker run --name capifn-redis -p 6379:6379 -d redis

now open your config runnig conversation-api-function config this is gonna open an editor with your configs. Add this line:

CONV_API_FUNC_REDIS_URL="redis://localhost:6379"

deploy in production

create deployment credentials

From the project directory, run the following command:

conversation-api-function deploy-new . -a API_KEY -s API_SECRET -l LVN_LIVE

this is gonna create a .env.prod file with the credential to go live

remember, the LVN_LIVE you are using here should be a differnt one then the one you have used in prod. If you use the same, you risk to break your prod application.

deploy in heroku.

After you have create the .env.prod file as described above, follow those steps:

  1. after you have created a deployment credentials, for the first thing you need to init your project on git:
git init
git add -A
git commit -m 'first commit'

  1. be sure you have an heroku account: https://dashboard.heroku.com/apps

  2. insatall the heroku cli with npm install -g heroku

  3. then you can create an heroku app :

heroku login
heroku apps:create my_capi_heroku_app
  1. now you can finally push the app live.
git push heroku main

if you look the app logs with heroku logs you will see that's the app is failing. that's becouse you need to configure the env vars. An easy way is the following:

cat .env.prod | grep -v PRIVATE_KEY | xargs heroku config:set

# set private key
PRIVATE_KEY="`cat .env.prod | grep PRIVATE_KEY | cut -c 27-`"
echo -e $PRIVATE_KEY > private.key
heroku config:set CONV_API_FUNC_PRIVATE_KEY="$PRIVATE_KEY"

# set webhook url
heroku config:set CONV_API_FUNC_SERVER_URL="https://my_capi_heroku_app.herokuapp.com"
  1. now go to https://my_capi_heroku_app.herokuapp.com/hello to check is working

FAQs

Package last updated on 04 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc