New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

nexmo-conversation-js

Package Overview
Dependencies
Maintainers
2
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nexmo-conversation-js

Nexmo Conversation SDK for JavaScript

  • 0.0.41
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
decreased by-71.43%
Maintainers
2
Weekly downloads
 
Created
Source

Conversation SDK for JavaScript

Deprecated (Moved to nexmo-conversation) Please npm install nexmo-conversation instead

Quick Steps

Setup

$ npm install nexmo-conversation

create a nexmo app using the nexmo-cli

$ nexmo app:create "Application name" --keyfile 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]

Create an instance and login

var rtc = new ConversationClient({debug:false});
//var token = request login token as above, with sub=<username>
rtc.login(token).then(
    function(application){
        //use the application object to manage the conversations
        //access the available conversations
        console.log(application.conversations);
    });

Enable notifications

rtc.notifications({
    state: "on",
    dir: "auto",
    lang: "EN",
    tag: "notificationPopUp",
    icon: "https://int-dir.s3.amazonaws.com/uploads/282_282_social_icon_360x360.png"
});

Show a notification

rtc.notify("Title", "Message");

Create a new Conversation

var conversationData = {name:'My Nexmo Conversation'};
application.newConversation(conversationData).then(
    function(conversation) {
        //join the created conversation
        conversation.join(application.me).then(
            function(member) {
                console.log("Joined as " + member.name);
            }).catch(
            function(error) {
                console.log(error);
            });
    }).catch(function(error) {
    console.log(error);
});

Get a conversation you are a member

application.getConversation(conversation_id).then(
    function(conv) {
        conversation = conv;
        });

Set up Text listener for incoming Text Events

conversation.on("text", function(sender, textEvent){
    if (textEvent.cid === conversation.id){
        //if (rtc.isVisible) { textEvent.seen(); }
        console.log("my message was:", textEvent, sender);
    }else{
        console.log("got a message from another member:", textEvent, sender);
    }
});

Sending a Text Event

conversation.sendText("Hi Nexmo").then(
    function(){
        console.log('message was sent');
    }).catch(function(error){
        console.log('error sending the message', error);
    });

Sending an Image

conversation.sendImage(fileInput.files[0]);

Setup an ImageEvent listener and download the image file

conversation.on("image", function(sender, imageEvent){
    imageEvent.fetchImage().then(function(imagedata) {
        message.body.thumbnail = imagedata;
    });
}

Build

$ npm install
$ cd node_modules/nexmo-conversation
$ grunt

NEXMO

Keywords

FAQs

Package last updated on 02 Nov 2016

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