Studio GuideWorld SDK Guide
Log In

QuickChat

QuickMessage-related functions in the ZepetoWorldContent API can be used to implement the ability to send and receive messages within the world.

1792

Quick Message

❗️

Caution

  • This feature is available in a World where multiplayer elements are implemented.

In order to use QuickMessage functions, you must create an import statement as follows.

import { ZepetoWorldContent, WorldMultiplayChatContent, QuickMessage } from 'ZEPETO.World';

ZepetoWorldContent API provides the following QuickMessage-related functions.

APIDescription
ZepetoWorldContent.GetQuickMessageList($onComplete: System.Action$1<QuickMessage[]>, $onError: System.Action$1)Import the QuickMessage list for the current World. (Import which corresponds to the language of the device.)

It can be used as the code shown below.

ZepetoWorldContent.GetQuickMessageList(quickMessageList: QuickMessage[] => {
    // Handling QuickMessage

}, err => {
 
});

WorldMultiplayChatContent API enables QuickMessage synchronization in multi-player.

When using the functions below, a chat message is sent and output in the chat window. In addition, if you enable BubbleChat in ZepetoPlayers, you can see that a speech bubble pops up in the app.

APIDescription
SendQuickMessage($quickId: string):void;Sends a quickId message entered to the multi-player server.

❗️

Caution

If the value of the quickId is different from the existing QuickMessage list, it will not be sent.


QuickMessage class consists of the following components:

class QuickMessage extends System.Object {  
    public id: string;  
    public message: string;
}

The following is an entire example code that uses functions of QuickMessage features.

import { Button } from 'UnityEngine.UI';
import { ZepetoScriptBehaviour } from 'ZEPETO.Script';
import { ZepetoWorldContent, WorldMultiplayChatContent, QuickMessage } from 'ZEPETO.World';


export default class QuickChat extends ZepetoScriptBehaviour {
    
    public quickChatBtn: Button;

    Start() {
        ZepetoWorldContent.GetQuickMessageList(quickMessageList => {
            quickMessageList.forEach((quickMessage: QuickMessage, index: number, array: QuickMessage[]) => {
                console.log(`id = ${quickMessage.id}, message = ${quickMessage.message}`);
            });
        }, err => {
            console.log(`QuickMessage Error: ${err}`);
        });

        // Send "Hi" message
        this.quickChatBtn.onClick.AddListener(() => {
            this.OnClickQuickMessageButton("zw_quickchat_preset_001");
        });
    }

    private OnClickQuickMessageButton(quickId: string) {
        WorldMultiplayChatContent.instance.SendQuickMessage(quickId);
    }
}