Send Message To Room

Description

The sendMessageToRoom() function is the one responsible for sending messages in Widget. You can send the following types of messages:

  • TextMessage

  • ImageMessage

  • AudioMessage

  • VideoMessage

  • DocumentMessage

  • LocationMessage

  • PostbackMessage

  • EventMessage

Params

The sendMessageToRoom() function will receive 2 mandatory params as its argument:

  • roomId: It is a param of type “string”, that corresponds to the ID of the room to which messages will be sent. The ID of the current room is a key inside the room object of widgetService, and can be accessed as follows: widgetService.room.id

  • message: It Is an object that will have different keys, depending on the type of message being sent, according to the corresponding interfaces.

Interfaces

Text Message Interface

interface TextBaseMessage {
    text: string;
    readonly type: 'TEXT';
}

Image Message Interface

interface ImageBaseMessage {
    mediaUrl: string;
    caption?: string;
    readonly type: 'IMAGE';
}

Audio Message Interface

export interface AudioBaseMessage {
    mediaUrl: string;
    readonly type: 'AUDIO';
}

Video Message Interface

interface VideoBaseMessage {
    mediaUrl: string;
    caption?: string;
    readonly type: 'VIDEO';
}

Document Message Interface

interface DocumentBaseMessage {
    mediaUrl: string;
    caption?: string;
    readonly type: 'DOCUMENT';
}

Location Message Interface

interface LocationBaseMessage {
    lat: string;
    lng: string;
    readonly type: 'LOCATION';
}

Postback Message Interface

interface PostbackMessage {
    text: string;
    payload: Record<string, any>;
    readonly type: 'POSTBACK';
}

Event Message Interface

interface EventMessage {
    slug: string;
    description: string;
    eventPayload: Record<string, string>;
    readonly type: 'EVENT';
}

Example of use: Text message

/**
* @param {SendMessageToRoom} [params]
* @returns {Promise<Message>}
**/

widgetInstance.sendMessage ("<someStringValue>",
    {
        "type": "TEXT",
        "text": "<textMessageToBeSent>"
    }
);

/**
* "<someStringValue>" param corresponds to the roomId to which the message is being sent.
/**

Last updated