Skip to content

Instantly share code, notes, and snippets.

@kwhinnery
Last active Feb 19, 2016
Embed
What would you like to do?
Twilio IP Messaging is intended to help developers build chat applications, and is in public beta. Given the following options, which interface would you prefer to initialize the Twilio IP Messaging SDK and execute a few basic tasks? Vote here: https://twitter.com/kevinwhinnery/status/700445163672510468
var client = new Twilio.IPMessaging.Client('token');
var channel = client.getOrCreateChannelByUniqueName('general');
channel.join();
channel.listMessages().then(function(messages) {
console.log(messages);
}).catch(function(err) {
console.log(err);
});
channel.sendMessage('hey there').then(function() {
console.log('message sent.');
}).catch(function(err) {
console.log(err);
});
channel.on('messageAdded', function(message) {
console.log(message.body);
});
channel.on('error', function(err) {
console.log(err);
});
var client = new Twilio.IPMessaging.Client('token');
var channel;
client.getOrCreateChannelByUniqueName('general').then(function(_channel) {
channel = _channel;
channel.join();
channel.listMessages().then(function(messages) {
console.log(messages);
}).catch(function(err) {
console.log(err);
});
channel.sendMessage('hey there').then(function() {
console.log('message sent.');
}).catch(function(err) {
console.log(err);
});
channel.on('messageAdded', function(message) {
console.log(message.body);
});
}).catch(function(err) {
console.log(err);
});
@anvaka

This comment has been minimized.

Copy link

@anvaka anvaka commented Feb 19, 2016

just a tiny preference from me:

var client = new Twilio.IPMessaging.Client('token');
client.joinChannel('general').then(function(channel) {
// ...
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment