CREATE YOUR WORLD
Social
Send Direct Message API
14min
you can send direct messages to other users within zepeto world using the send direct message(dm) api when using the direct message (dm) sending api in a launched world, a link to enter the world is automatically provided at the bottom of the message, making it good for promoting the world please be sure to follow the precautions when using install window → package manager → zepeto world package please install version 1 21 14 or higher first afterward, please install the ‘zepeto module’ package with a version of 1 0 7 or higher ensure that the zepeto app is running the version 3 46 000 or higher send direct message api to use the send dm api, add the import statement below import { socialservice } from 'zepeto module social'; send dm core function declaration public static openpopupdirectmessage($sendmessage string, $userids? string\[], $oncomplete? system action$1)\ void; parameters parameter description sendmessage this is a required parameter this is the body of the message you want to send if it is blank or empty, the transmission will be treated as a failure userids this is an optional parameter if you pass userids \ the selection ui is configured with the corresponding user id list when userids are not passed or an empty list is passed \ the selection ui is constructed with the follow/following list of the user sending the message oncomplete this is a callback to be called when message sending is completed or fails directmessagepopupstate response description cancel when the pop up is manually closed or if the sending fails sendcomplete when the send request is completed and it closes situation by errorcode response description 31002 this occurs if at least one incorrect userid (an userid that does not exist) is included when entering the user id list in the userids parameter 37011 this occurs when you try to send a message while under a guest account 8001 this happens when you continuously send the same message repeatedly it can be sent once every 10 seconds 2001 this occurs when the message content in the ‘send’ field is either empty, contains only a space, or exceeds 1000 characters 0 network connection error cases such as network disconnection, connection instability, and other general error situations 1 unidentifiable error usage example enter the sender directly and send 1\) please add the send dm button to canvas 2\) please write the example code as below import { zepetoscriptbehaviour } from 'zepeto script'; import { socialservice, directmessagepopupstate } from 'zepeto module social'; import { button } from "unityengine ui"; import { worldservice } from 'zepeto world'; export default class senddirectmessage extends zepetoscriptbehaviour { // variable to store the direct message public message string; // array of user ids to send the direct message to public userids string\[]; // reference to the button ui component public senddmbutton button; start() { this senddmbutton onclick addlistener(() => { // check whether my id is included in the userids array and return if it is included if (this userids includes(worldservice userid)) { console log("userids contains my userid"); return; } // open a popup to send a direct message using the socialservice socialservice openpopupdirectmessage(this message, this userids, (popupstate directmessagepopupstate) => { // check the state of the direct message popup if (popupstate === directmessagepopupstate cancel) { console log("you closed the pop up or failed to send the message"); } else if (popupstate === directmessagepopupstate sendcomplete) { console log("the dm message was sent successfully, and the pop up closed "); } }); }); } } 3\) after writing the script, return to the unity editor and drag the button in the inspector to set it enter the message body and the target user’s userid for the message up to 20 people will be displayed in the ui, so enter up to 20 people 4\) when you press the send dm button, the friend list ui appears select the target user and click send 5\) if sending dm is successful, a toast ui will appear indicating success, and a log will be output by the example script 6\) also, a dm has arrived for targetuser if an error occurs, such as sending messages continuously or the message content is empty, the dm transmission will be processed as a failure send using following/follower list ui 1\) please add a button to the canvas 2\) please write the example code as below if you pass an empty list to the targetuserid parameter, the following/follower list ui will appear import { zepetoscriptbehaviour } from 'zepeto script'; import { socialservice, directmessagepopupstate } from 'zepeto module social'; import { button } from "unityengine ui"; export default class senddirectmessage extends zepetoscriptbehaviour { // variable to store the direct message public message string; // reference to the button ui component public senddmbutton button; // private variable to store an array of user ids, initialized as null private emptyids string\[]; start() { this senddmbutton onclick addlistener(() => { // open a popup to send a direct message using the socialservice // use the class's message content and an empty array of user ids socialservice openpopupdirectmessage(this message, this emptyids, (popupstate directmessagepopupstate) => { // check the returned state of the direct message popup if (popupstate === directmessagepopupstate cancel) { console log("you closed the pop up or failed to send the message"); } else if (popupstate === directmessagepopupstate sendcomplete) { console log("the dm message was sent successfully, and the pop up closed "); } }); }); } } 3\) after writing the script, return to the unity editor and drag the button in the inspector to set it then please enter the body of the message 4\) when you press the send dm button, the following/follower ui appears select the target user and click send (up to 5 people can be selected) you can send dm to up to 5 people at a time you can’t send a dm to yourself the actual number of following/following users may differ from the number of users displayed in the send dm pop up this is because the users that can be selected are filtered and displayed if you select a user who has blocked receiving dms, it will be treated as a failure and dms will not be sent if you call the send dm api frequently, it will be restricted and transmission will fail you can send once every 10 seconds please be careful not to send indiscriminate dms if the message you send contains a url, it will not work properly, so sending messages containing urls is prohibited if the message being sent is blank or empty, it will be treated as a failure please be sure to write the content of the message