Installing
NPM
npm install monkeykit --save
import Monkey from 'monkeykit'
Bower
bower install monkeykit --save
<script src="./bower_components/dist/monkey.js"></script>
Initializing Monkey
var monkey = ;//look in the admin for your App's credentialsvar appKey = 'token';var appSecret = 'placeholder'; var userMetaData = name: 'Bob'; var isTemporalId = false;var isDebugging = false; monkey;
The userObj is a JSON object representing the user metadata (e.g. name, country, etc) in which can be included a monkey_id
to reuse an existing monkey id.
Sending Messages
To send a message:
monkey.sendMessage(<text>, <recipient monkey id>, optionalParams);
- The optionalParams is a JSON object representing extra params that the developer wants to send.
- The optionalPush could be a String or if you want to send a localized push, then it could be a JSON object.
To send a encrypted message:
monkey.sendEncryptedMessage(<text>, <recipient monkey id>, optionalParams);
- The optionalParams is a JSON object representing extra params that the developer wants to send.
- The optionalPush could be a String or if you want to send a localized push, then it could be a JSON object.
Both these functions return a MOKMessage object (See end of document for reference)
To send a notification:
monkey.sendNotification(<recipient monkey id>, optionalParams, optionalPush);
- The optionalParams is a JSON object representing extra params that the developer wants to send.
- The optionalPush could be a String or if you want to send a localized push, then it could be a JSON object.
Sending Files
To send a file:
monkey.sendFile(<data>, <recipient monkey id>, <file name>, <file type>, <bool compressionFlag>, optionalParams, optionalPush, callback);
<file type>
is of typeMOKMessageFileType
(See end of document for reference).<bool compressionFlag>
boolean that determines if the data should be compressed or not.- The optionalParams is a JSON object representing extra params that the developer wants to send.
- The optionalPush could be a String or if you want to send a localized push, then it could be a JSON object.
To send a encrypted file:
monkey.sendEncryptedFile(<data>, <recipient monkey id>, <file name>, <file type>, <bool compressionFlag>, optionalParams, optionalPush, callback);
- is of type
MOKMessageFileType
(See end of document for reference). - boolean that determines if the data should be compressed or not.
- The optionalParams is a JSON object representing extra params that the developer wants to send.
- The optionalPush could be a String or if you want to send a localized push, then it could be a JSON object.
Both these functions return a MOKMessage object (See end of document for reference)
Events
The events to listen to are:
onMessage
- Triggered when a message arrivesonNotification
- Triggered when a notification arrivesonAcknowledge
- Triggered when an acknowledge of a message arrivesonConnect
- Triggered when there's a connection established to the socket serveronDisconnect
- Triggered when there's a disconnection to the socket server
monkey;
Creating groups
To create a group you can do it with a given id
or you can let monkey generate an id
for you:
//array of monkey idsvar members = <monkey id1> <monkey id 2>; //JSON object defined by the developer (anything can go there)var groupInfo = name: "los del barrio" admin: <monkeyId>; //A push notification can be sent to mobile devices that have registered their push token in monkeyvar optionalPush = "test"; //You can set the id that you want for your group//if that id is already taken, those members and info will be added to the existing groupvar optionalId = "G:Mesa1"; monkey;
groupInfo
will contain a JSON Object with:
group_id
all group ids start with prefixG:
, if the id provided doesn't have the prefix, the group will still be created with theG:
prefix and messages should be sent using this id. If you don't provide an id, then Monkey will provide the id (e.g.G:1
,G:2
, and so on).members
-> array of Monkey idsmembers_info
-> dictionary of {:}info
-> JSON object defined by the user
To send messages to the group, you use the same monkey.sendMessage
and in the recipientMonkeyId
you will put the id of your group.
var optionalParams = cardPlayed: "3B";var message = monkey;
The message returned by sendMessage
is of the MOKMessage
class
Remove and Adding members to group
//you can have two different push messages//for the new member, and for all the existing membersvar optionalPushNewMember = "hello";var optionalPushExistingMember = "derp has joined the game!"; var newMemberId = <Monkey id>;var groupId = <group id>;monkey; var userLost = <Monkey id>; monkey;
User or group info
To get the info just call
//you can request the info for a monkey user or a groupvar someId = "G:Mesa1";//or <Monkey id>monkey;
MOKMessage reference
- message.id -> id of the message
- message.oldId -> old id of the message
- message.params -> custom params sent by the developer in
optionalParams
- message.text -> text of the message
- message.encryptedText -> encrypted text of the message
- message.isEncrypted() -> returns true/false if the message text is encrypted //to be continues