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, ... })

Name

Type

Required

Description

channelId

string

yes

The id of the channel that the message will be added to. ThechannelId must be included in the list of channelIds that were passed when generating the authToken.

content

string

yes

The content of the message.

metadata

plain object

no

The metadata of the message is a custom object allowing you to attach any information you need directly onto the message.

parentId

string

no

If the message is a reply to another message, set the parentId to the id of the parent message.

files

array [File]

no

An array of File objects that will be automatically uploaded to ALO's media servers and metadata persisted on the message

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] })

Name

Type

Required

Description

channelIds

array [string]

yes

An array of channelIds that specify which channels you want the client to receive events for through the function passed to addEventListener.

Last updated

Logo

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