Lesson 19: Send user to user messages

From VZ Developer Wiki
Revision as of 08:49, 9 April 2010 by Bastian (talk | contribs) (Created page with 'To trigger a user to user message via the VZ-Messaging Service (Nachrichtendienst) you have to call the opensocial.requestSendMessage method with a message of the type PRIVATE_ME…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

To trigger a user to user message via the VZ-Messaging Service (Nachrichtendienst) you have to call the opensocial.requestSendMessage method with a message of the type PRIVATE_MESSAGE from within your gadget.

Before the message is sent the user has to confirm this with a platform dialog and can edit the message and possible recipients.

A footer with information to your gadget (icon, title, description and installation link) is automatically added as a footer to these messages.

function postToUser(recipientId) {
     var params = [];
     params[opensocial.Message.Field.TITLE] = 'Subject of message';
     params[opensocial.Message.Field.TYPE] = opensocial.Message.Type.PRIVATE_MESSAGE;
     var message = opensocial.newMessage('This is the message body', params);
     opensocial.requestSendMessage(recipientId, message, callback);
}

function callback(data) {
    if (data.hadError()) {
        //the user has canceled sending the message
    } else {
	//message sent
    }
}

Of course you can embed an embed view of your gadget or any static content you defined in your static_content.json file in your message body:

vz.embed.getEmbedUrl({name: 'world'}, function(embedUrl) {
  vz.embed.getStaticContentUrl('key_resource_img', function(staticUrl) {
       var params = [];
       params[opensocial.Message.Field.TITLE] = 'Subject of message';
       params[opensocial.Message.Field.TYPE] = opensocial.Message.Type.PRIVATE_MESSAGE;
       var message = opensocial.newMessage('my message ' + embedUrl + ' ' + staticUrl, params);
       opensocial.requestSendMessage(recipientId, message, callback);
  })
});