Send Messages

Send and receive messages with custom metadata and file attachments using ALO's JavaScript SDK.

Send a message

You can send a message as a reply, with custom metadata, and even pass a list of File objects all in one command.

chat.sendMessage({
    channelId: "alpha",
    content: "<p>Hello, World!</p>",
    metadata: {
        coordinates: "27.9881,86.9250",
        temperature: "69.3"
    },
    parentId: "8e8a4e05-12e3-43b5-882e-d9711426f8e3",
    files: []
}).then((res) => {
    if (res.status.error) {
        console.log(`Send Message Failed:
            Reason: ${res.status.errorData.message}
            (Status Code: ${res.status.errorData.statusCode})
        `);
        return;
    }
    const message = res.response.message;
});    

sendMessage({ channelId: string, content: string, ... })

Receive new messages

chat.addEventListener(function(event) {
    if (event.type === "message.new") {
        const { message } = event.data;
        console.log("New message: ", message);
    }
})

chat.subscribe({
    channelIds: ["alpha", "bravo"]
})

subscribe({ channelIds: [string] })

Last updated

Logo

© Copyright 2024 ALO.ai, Inc. • All Rights Reserved