DEVELOPERS BLOG

Adding BBM Channels to your WebWorks App

Last month, Mark Sohm showed us how to Invoke a BBM Channel Within Your App with QML. Well, not to be outdone by my fellow native development consultants, I’m here to show you how to do the same and more today, with WebWorks!

With the ever-growing popularity of BBM Channels, you’re probably looking for a way to integrate the service into your applications. Luckily, using the Invocation Framework, you can easily view a BBM Channel and share content to it. Let’s take a look at the JavaScript.

Invoking a BBM Channel

Here, we’re simply building our ‘request’ object by setting a target, action, and channel uri. Then, we’re calling the blackberry.invoke.invoke() method. If the user is already subscribed to the Channel it will open, if the user is not subscribed they’ll be prompted to do so. Note that the BBM Channel is case sensitive.

var request = {
    target: "sys.bbm.channels.card.previewer",
    action: "bb.action.OPENBBMCHANNEL",
    uri: "bbmc:C00124CF8"
};

blackberry.invoke.invoke(
    request,

    function() {
        console.log('success');
    },

    function(e) {
        console.log(e);
    }
);

Sharing content

Below, is an example on how you would share a photo with a BBM Channel. Again, we’re just building our request object, giving it the path to a photo, and calling the blackberry.invoke.invoke() method. The Invocation Framework takes care of the rest!

var request = {
    target: "sys.bbm.channels.sharehandler",
    action: "bb.action.SHARE",
    uri: "local:///test.gif"
};
 
blackberry.invoke.invoke(
    request,
 
    function() {
        console.log('success');
    },
 
    function(e) {
        console.log(e);
    }
);

You can also post text to a channel. It’s pretty much the same as the photo sharing, only you specify the mime-type and data properties instead of a photo uri.

var request = {     
   target: "sys.bbm.channels.sharehandler",     
   type: "text/plain",     
   action: "bb.action.SHARE",     
   data: "this is a test" 
};  
 
blackberry.invoke.invoke(     
   request,      
 
   function() {         
      console.log('success');     
   },      
 
   function(e) {         
      console.log(e);     
   } 
);

Sample Apps

fried egg

Whether you’re developing with the latest BlackBerry WebWorks 2.0 powered by Apache Cordova, or the current WebWorks 1.0 SDK, there’s sample app for you! I’ve written two full samples that will show you how to add BBM Channels to your application.

Download the sample app for:

WebWorks 2.0 Beta
WebWorks 1.0 SDK

If you find this post useful, have questions or just want to keep up-to-date on the world of BlackBerry Development, follow me on Twitter at @chadtatro.

Chad Tetreault

About Chad Tetreault

A developer at heart, I’ve been coding in some shape or form since the age of 13. Nowadays I focus on building awesome cross-platform (Android, iOS, BlackBerry) mobile web applications powered by Cordova, JavaScript, and AngularJS.