Skip to content

1. Getting Started

GianniCarlo edited this page May 17, 2016 · 3 revisions

Installation

NPM

npm install monkeykit --save

import Monkey from 'monkey-sdk'

Bower

bower install monkeykit --save

<script src="./bower_components/dist/monkey.js"></script>

Initializing Monkey

var monkey = new Monkey();
//look in the admin for your App's credentials
var appKey = 'token';
var appSecret = 'placeholder';

var userMetaData = {
  name: 'Bob'
};

var isTemporalId = false;
var isDebugging = true;
var autoSync = true;

monkey.init(appKey, appSecret, userMetaData, isTemporalId, isDebugging, autoSync);
  • You can register in our Admin Panel to get your App key and App secret of your app.
  • You can define your own user metadata with whichever parameters you want. If you already have a monkey Id that you want to reuse, simply define in your metadata a key monkeyId with the value.
  • If you're not reusing a monkey id, you can define if the monkey id generated is temporal or not.
  • If you want to see all the logs that monkey prints, set debugging to true.
  • To request your pending messages automatically every time you connect to our server, set autoSync to true.

Sending messages when you are connected

//listen to when the client is connected
monkey.on('onConnect', function(metadata){
  console.log('I\'m connected with this monkey id: ' + monkey.session.id);
  console.log('Metadata registered with this user: ' + JSON.stringify(metadata));
  
  var monkeyId2 = <second monkey id>; //replace with a real monkey id
  //you can send custom params with each message
  var optionalParams = {
   type: 'meme',
   shut-up: '& take my money'
  };
  //you can send push to mobile devices if you have that setup in the admin panel
  var optionalPush = 'Knock Knock';

  //if you don't want it encrypted you can use monkey.sendMessage instead
  monkey.sendEncryptedMessage('Hello World!', monkeyId2, optionalParams, optionalPush);
});

The other user will receive the message on this listener:

monkey.on('onMessage', function(message){
  console.log('incoming message: ' + message.text);
  console.log('from user: ' + message.senderId);
});

Where to next?

  • Go here to learn more about sending messages and files.
  • Check out user and group actions and manipulations
  • Learn more about all the events emitted by Monkey and our data model.
  • Learn about our Monkey protocol