Deprecated (Moved to nexmo-stitch)
Please npm install nexmo-stitch instead
Conversation SDK for JavaScript
Quick Steps
- Create your Nexmo account
- Install
nexmo-cli
tool - Create a new application
- Generate a JWT token
- Register your new user to the Conversation Service
- Generate a JWT token (with sub=
[username]
)
Setup
$ npm install nexmo-conversation
create a nexmo application using the nexmo-cli
$ nexmo app:create "Application name" --type rtc --keyfile private.key>Application created: xxxxxxxx-xxxx-xxxx-xxxx-xxxxsxxxxxxx>Private Key saved to: private.key
get a token to create a user:
$ nexmo jwt:generate private.key application_id=[application_id]
create a user in your app
$ curl -X POST -H 'Authorization: Bearer [JWT]' -H 'Content-Type:application/json' -d '{"name":"[username]"}' https://api.nexmo.com/beta/users
include the script in your web page
<script src="node_modules/nexmo-conversation/dist/conversationClient.js"></script>
get a user's token
$ nexmo jwt:generate private.key application_id=[application_id] sub=[username]
Usage
Create an instance and login
var rtc = debug:false;// var token = request login token as above, with sub=<username>rtc;
Create a new Conversation
var conversationData = display_name:'Nexmo Conversation' ;application;
Get a conversation you are a member of
application;
Set up Text listener for incoming Text Events
conversation;
Sending a Text Event
conversation;
Login Create a conversation, join it, send a message and listen for incoming messages
var rtc = debug:false;// var token = request login token as above, with sub=<username>rtc;
The main objects here are application
and conversation
you can use them to extend the use case.
E.g. by inviting a second user to a conversation that you are a member (have joined).
The second instance should see the conversation listed, and the member(or me).state as "invited"
When both instances have attached listener to "text" events of a conversation they have both joined,
you should be able to send/receive text events in that conversation.
Build
If you want to contribute:
Install SDK
clone this repo and enter in it's directory
$ npm install
build
$ npm start
it will build interracially your code.
or
$ npm run build
generate docs
$ npm run docs
it will generate your code in dist/conversationClient
Run the tests
you can run the test with
$ npm run test