Lesson 19: Send user to user messages

From VZ Developer Wiki
Jump to: navigation, search

General Guidelines | XML Specification | Features | Views | JavaScript API | REST API | Tutorials | OAuth


Lesson 18: Embedding a gadget into user generated content using an EMBEDPROVIDER view Back to overview Lesson 20: Post on a user's wall

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);
  })
});


  • Lesson 19: Send user to user messages