">mixi Developer Center (mDC)

mixi Apps

mixi Apps (English) » Technical Specification (new method) » PC » Let’s send a message to the user

Let's send a message to the user

In the mixi app for PCs, a message-sending function is provided, which is available for users to send a message from the app. As Opensocial prescribes the message-sending function with JavaScript, the mixi platform is also implemented based on the provision. This page explains how to use the message-sending function.

What you can do

A user who uses the mixi app can send a message to other users from the mixi app. Messages on this page indicate the message-sending service among mixi users provided by mixi. Using the message-sending function, you can let users type the contents displayed in the pop-up window to type the message. After that, the sent message is delivered to the destination mailbox.

As a unique function of the mixi app, it can only let the user type the message, but also includes the mixi app’s unique information. Specifically, the mixi app can include face mark, the URL to external website, and the mixi app start URL. For example, in the case of the mixi app that can send a greeting card, you can send the card to friends by creating the mixi app start URL investing the card as a parameter and including it in the message. The recipient can see the nice greeting card by clicking the URL that includes the message.
 

Preparing for Message API

You need to previously prepare for using the Message API.

API reference

The following steps are required to send a message.

  • Create opensocial.Message object
  • Call opensocial.requestSendMessage() function
Creating message object

First of all, you need to decide on the following information to send a message.

recipient The recipient user ID
title Default initial strings as a title
* Within 100 full-size characters
* No face mark
body Fixed text other than message typed by the user
* Within 300 full-size characters
No face mark
* Available to include the link to the app

You can create a message object by using the opensocial.newMessage() function from these parameters.

var params = {};
params[opensocial.Message.Field.TITLE] = title;
var msg = opensocial.newMessage(body, params);

Specify the 1st argument of the newMessage() function to the body and the second argument parameter for the object.

Sending message

Use the opensocial.requestSendMessage() function to send a message created from the content of the msg object.

opensocial.requestSendMessage(recipient, msg, function(response) {
  if (response.hadError()) {
    var code = response.getErrorCode();
    // do something...
  }
});

Give the 1st argument of the requestSendMessage() function to the recipient ID, the second argument to the Message object created earlier, and the 3rd argument to the callback function. After calling the requestSendMessage() function, the pop-up window to let the user type the body of the message is displayed for the user.

After the user sends the message or clicks the やめる(Stop) button, the callback function is called. The argument is opensocial.ResponseItem object. Using the hadError() function and getErrorCode() function, please implement the proper error execution. The anticipated error code is as shown below.

401 * Not obtaining the user permission of mixi_apps2 scope.
403 * Viewer does not hold the app.
* Blocked access by the recipient.
* Clicked the やめる(Stop)button.
404 * The parameter is wrong.
* The recipient ID user does not exist.
500 * Internal server error on mixi.

The limitation of sending a message

Sending a message to a user with the message sending API applies the same method as the message-sending function provided by mixi as usual. In short, sending a message to oneself, and sending and receiving a message by a partner account are not available.

TOP OF THIS PAGE