Skip to content

Live Chat Messages

The function subscribeMessage allows you to recieve chat messages updates passing a function that will be called every time a message is added or deleted. Otherwise, the function unsubscribeMessage, remove chat messages updates, in other words, cancel subscribeMessage function.

import { Metalives } from "metalives-sdk"
import dotenv from 'dotenv'

dotenv.config();

const client = new Metalives(process.env.SDK_TOKEN);

const addMessage = (message) => {
    // Add message to chat
}

const deletedMessage = (message) => {
    // Delete message from chat
}

client.chat.subscribeMessages(liveId, addMessage, deletedMessage);
client.chat.unsubscribeMessages(); // disable recieve chat messages updates

The added messages will be in the following format:

    {
        "id": "Id of the message",
        "createdAt": "Timestamp { seconds: int, nanoseconds: int }",
        "name": "name of message sender, configured by application",
        "text": "Text content of the message"
    },

The deleted messages will be in the format:

    {
        "createdAt": "Timestamp { seconds: int, nanoseconds: int }",
        "name": "name of message sender, configured by application",
        "text": "Text content of the message"
    },