Sunday, February 12, 2012

Force.com streaming API and Chrome desktop notifications

I likeimage chrome desktop notifications a lot, they specially help me with gmail running in browser always and keeping me updated about new mails/chats without keeping the gmail tab open. I also like the way gmail desktop notifications in chrome take to the email related with the notification, again saves time and clicks.

Force.com PushTopic Desktop Notifications

I wanted something similar with Force.com Streaming API or the PushTopic notifications. If you are working on a crucial Campaign, Account, Lead or Opportunity, then instead of waiting for chat/email/phone for updates, one can setup PushTopics and get updated in close to real time using “chrome desktop notifications”. Something like this:

image

Notifications experiment !

Regarding the same, I tried a small experiment to use Force.com streaming API (PushTopics) with Chrome Desktop Notifications. The initial fixture I created was clone of visualforce code sample available in streaming api docs.

Here is a demo video that shows the force.com desktop notifications in action (Watch it Full Screen for better visibility)

Here is the full source of the visualforce page “streamingnotifications” : https://gist.github.com/1808548

You will also need to

  • download and setup comet static resources as indicated in the Streaming API guide.
  • replace the images being served from my dropbox folder with yours.
  • This page is designed keeping Account sobject notifications in mind, so please setup PushTopics as required. The one I used was created using this apex code
    PushTopic pushTopic = new PushTopic();
    pushTopic.Name = 'AccountUpdates';
    pushtopic.Query = 'SELECT Id, Name, Phone, Fax  FROM Account'; 
    pushTopic.ApiVersion = 24.0;
    pushTopic.NotifyForOperations = 'All';
    pushTopic.NotifyForFields = 'Referenced';
    insert pushTopic;

Possibilities Streaming PushTopics & Chrome Desktop notifications ?

One can use chrome desktop notifications in very interesting ways. Few ideas I can think of are

  • Embed this visualforce page and embed it into the home page layout, so that user doesn’t need to browse anywhere.
  • Show list of PushTopics available in the VF page to user, and let user select the ones he is interested in. Notifications would be shown only for those PushTopics. This page should also have option to stop notifications about a particular topic.

What other PushTopics can be helpful ?

  • Chatter : Create a push topic with query on required Feed like NewsFeed, so that anything relevant to chatter is also showed in desktop notifications.
  • Leads/Opps : If team is working on same lead/opp they don’t need to refresh the page, or wait for email/call/chat to know about the important changes.

Note about PushTopics security & Limits

Security is well implemented on PushTopics, but its important to understand before setting up the expectations.

Here is what I found from the Streaming API developer guide about Security

Subscribers receive notifications about any create or update to a record if they have:
• Field-level security access to the fields specified in the WHERE clause
• Read access on the object in the query
• Visibility of the new or modified record based on sharing rules
If the subscriber doesn’t have access to specific fields referenced in the query SELECT clause, then those fields aren’t included in the notification. If the subscriber doesn’t have access to all fields referenced in the query WHERE clause, then they will not receive the notification.

Equally important is to know the Limits of Streaming API.

image

6 comments:

Saqib Ali said...

Excellent idea, Abhinav.

We are also using the Chrome desktop notifications and background pages to bring Chatter notifications to users.

We have build a Chrome extension for Chatter that runs in the background and notifies the user of any new Chatter content. The benefit of using Chrome Background pages is that it doesn't require the user to have Chrome launched. The notifications work even when Chrome is not open.

Saqib

Abhinav Gupta said...

Thanks Saqib, I liked your approach of using background pages, that makes it really easy to not enforcing any open page. Two questions :
1. Are you using REST API in the background page and how are you managing the authentication to salesforce, i.e. oauth etc ?
2. Any plans to blog/opensource it for community ?

chamil madusanka said...

Nice post Abhinav. Can we change this application as browser non-dependent?

Abhinav Gupta said...

Chamil, not as of now, this is only available in Chrome. I believe Firefox is doing something similar, but not yet out.

Harshit Pandey said...

Great, I actually was working on this and developed couple of extension on chrome and believe this can be done in a day if roadmap is ready

https://chrome.google.com/webstore/search/harshit

Abhinav Gupta said...

Yeah Harshit, it should take much to release first cut of this chrome extension. Good to see your interest and catalog of existing chrome extensions.