typings/lib2/messagev2/messageFactory.js

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MessageFactory = void 0;
const internal_1 = require("./internal");
const messagePayload_1 = require("./messagePayload");
/**
 * Factory class to create the various message types of Oracle Digital Assistant Conversation Message Model (CMM)
 */
class MessageFactory {
    /**
     * Converts a message from JSON representation into an instance of corresponding message type class.
     * @param {any} json - The JSON representation of the message
     * @returns {NonRawMessage} An instance of a subclass of a NonRawMessage.
     */
    static messageFromJson(json) {
        return internal_1.MessageUtil.deserializeMessage(json);
    }
    /**
     * Create a new voice settings object
     * @param {string} text - The text of the voice settings
     * @returns {Voice} A new instance of the Voice class.
     */
    static createVoice(text) {
        return new internal_1.Voice(text);
    }
    /**
     * Create a new text message
     * @param {string} text - The text content of the message.
     * @returns {TextMessage} A new instance of the TextMessage class.
     */
    static createTextMessage(text) {
        return new internal_1.TextMessage(text);
    }
    /**
     * Create a new text stream message
     * @param {string} text - The latest text chunk of the stream
     * @param {string} aggregateText - Aggregate text that has been streamed so far
     * @param {string} streamId - Unique identifier of the text stream
     * @param {StreamState} streamState - the state of the stream: start, running or end
     * @returns {TextStreamMessage} A new instance of the TextStreamMessage class.
     */
    static createTextStreamMessage(text, aggregateText, streamId, streamState) {
        return new internal_1.TextStreamMessage(text, aggregateText, streamId, streamState);
    }
    /**
     * Creates a new card
     * @param {string} title The title of the card
     * @returns {Card} A new instance of the Card.
     */
    static createCard(title) {
        return new internal_1.Card(title);
    }
    /**
     * Creates a new card message
     * @param {Card[]} cards The cards of the message.
     * @returns {CardMessage} A new instance of the CardMessage.
     */
    static createCardMessage(cards) {
        return new internal_1.CardMessage(cards);
    }
    /**
     * Creates a new attachment
     * @param {AttachmentType} type The type of the attachment (required).
     * @param {string} url The URL of the attachment (required).
     * @returns {Attachment} A new instance of the Attachment class.
     */
    static createAttachment(type, url) {
        return new internal_1.Attachment(type, url);
    }
    /**
     * Creates a new attachment message
     * @param {Attachment} attachment The attachment of the message.
     * @returns {AttachmentMessage} A new instance of AttachmentMessage.
     */
    static createAttachmentMessage(attachment) {
        return new internal_1.AttachmentMessage(attachment);
    }
    /**
     * Creates an instance of the CommandMessage class.
     * @param {CommandType} command The command type.
     * @returns {CommandMessage} The created instance of the CommandMessage.
     */
    static createCommandMessage(command) {
        return new internal_1.CommandMessage(command);
    }
    /**
     * Creates an instance of the EditFormMessage class.
     * @param {Field[]} fields The list of fields in the edit form message.
     * @returns {EditFormMessage} The created instance of the EditFormMessage.
     */
    static createEditFormMessage(fields) {
        return new internal_1.EditFormMessage(fields);
    }
    // Other message creation methods...
    /**
     * Creates an instance of the ReadOnlyForm class.
     * @param {ReadOnlyField[]} fields The list of fields in the read-only form.
     * @returns {ReadOnlyForm} The created instance of the ReadOnlyForm.
     */
    static createReadOnlyForm(fields) {
        return new internal_1.ReadOnlyForm(fields);
    }
    /**
     * Creates an instance of the FormMessage class.
     * @param {ReadOnlyForm[]} forms The list of forms in the message.
     * @returns {FormMessage} The created instance of the FormMessage.
     */
    static createFormMessage(forms) {
        return new internal_1.FormMessage(forms);
    }
    /**
     * Creates an instance of the Row class.
     * @param {ReadOnlyField[]} fields The list of fields in the row
     * @returns {Row} The created instance of the Row.
     */
    static createRow(fields) {
        return new internal_1.Row(fields);
    }
    /**
     * Creates an instance of the TableHeading class.
     * @param {string} label The label of the header column
     * @returns {TableHeading} The created instance of the TableHeading.
     */
    static createTableHeading(label) {
        return new internal_1.TableHeading(label);
    }
    /**
     * Creates a new instance of TableMessage.
     * @param {TableHeading[]} headings The table headings.
     * @param {Row[]} rows The table rows.
     * @returns {TableMessage} A new instance of TableMessage.
     */
    static createTableMessage(headings, rows) {
        return new internal_1.TableMessage(headings, rows);
    }
    /**
     * Creates an instance of TableFormMessage.
     * @param {TableHeading[]} headings The table headings.
     * @param {Row[]} rows The table rows.
     * @param {ReadOnlyForm[]} forms The read-only forms.
     * @returns {TableFormMessage} A new instance of TableFormMessage.
     */
    static createTableFormMessage(headings, rows, forms) {
        return new internal_1.TableFormMessage(headings, rows, forms);
    }
    /**
     * Creates an instance of the RawMessage class.
     * @param {object} payload The message payload.
     * @returns {RawMessage} The created instance of the RawMessage.
     */
    static createRawMessage(payload) {
        return new internal_1.RawMessage(payload);
    }
    /**
     * Creates an instance of the ExecuteApplicationActionCommandMessage class.
     * @param {string} applicationName The name of the application
     * @param {string} action The action to execute
     * @returns {ExecuteApplicationActionCommandMessage} The created instance of the ExecuteApplicationActionCommandMessage.
     */
    static createExecuteApplicationActionCommandMessage(applicationName, action) {
        return new messagePayload_1.ExecuteApplicationActionCommandMessage(applicationName, action);
    }
    /**
     * Creates an instance of the UpdateApplicationContextCommandMessage class.
     * @param {string} applicationName The name of the application
     * @returns {UpdateApplicationContextCommandMessage} The created instance of the UpdateApplicationContextCommandMessage.
     */
    static createUpdateApplicationContextCommandMessage(applicationName) {
        return new messagePayload_1.UpdateApplicationContextCommandMessage(applicationName);
    }
    /**
     * Creates an instance of the PaginationInfo class.
     * @param {number} totalCount The total count.
     * @param {number} rangeSize The range size.
     * @param {number} rangeStart The range start.
     * @returns {PaginationInfo} The created instance of the PaginationInfo.
     */
    static createPaginationInfo(totalCount, rangeSize, rangeStart) {
        return new internal_1.PaginationInfo(totalCount, rangeSize, rangeStart);
    }
    /**
     * Create a new postback action
     * @param {string} label The label of the postback action.
     * @param {object} postback The postback associated with the action.
     * @returns {PostbackAction} A new instance of the PostbackAction class.
     */
    static createPostbackAction(label, postback) {
        return new internal_1.PostbackAction(label, postback);
    }
    /**
     * Create a new custom event handler invocation action
     * @param {string} label The label of the button that invokes the custom event handle when clicked.
     * @param {string} event The name of the custom event handler
     * @returns {CustomEventAction} A new instance of the CustomEventAction class.
     */
    static createCustomEventAction(label, event) {
        return new internal_1.CustomEventAction(label, event);
    }
    /**
     * Create a new submit form action
     * @param {string} label The label of the action.
     * @param {object} postback The postback associated with the action.
     * @returns {SubmitFormAction} A new instance of the SubmitFormAction class.
     */
    static createSubmitFormAction(label, postback) {
        return new internal_1.SubmitFormAction(label, postback);
    }
    /**
     * Create a new action to send the geo location
     * @param {string} label The label of the action.
     * @returns {LocationAction} A new instance of the LocationAction class.
     */
    static createLocationAction(label) {
        return new internal_1.LocationAction(label);
    }
    /**
     * Create a new share action (facebook only)
     * @param {string} label The label of the action.
     * @returns {ShareAction} A new instance of the ShareAction class.
     */
    static createShareAction(label) {
        return new internal_1.ShareAction(label);
    }
    /**
     * Create a new URL action
     * @param {string} label The label of the URL action.
     * @param {string} url The URL associated with the action.
     * @returns {UrlAction} A new instance of the UrlAction class.
     */
    static createUrlAction(label, url) {
        return new internal_1.UrlAction(label, url);
    }
    /**
     * Create a new Popup action
     * @param {string} label The label of the Popup action.
     * @param {NonRawMessage} popupContent The content shown in the popup.
     * @returns {PopupAction} A new instance of the PopupAction class.
     */
    static createPopupAction(label, popupContent) {
        return new internal_1.PopupAction(label, popupContent);
    }
    /**
     * Create a new Call action
     * @param {string} label The label of the Call action.
     * @param {string} phoneNumber The phone number associated with the call action.
     * @returns {CallAction} A new instance of the CallAction class.
     */
    static createCallAction(label, phoneNumber) {
        return new internal_1.CallAction(label, phoneNumber);
    }
    /**
     * Creates an instance of Keyword.
     * @param {any} postback The postback to set.
     * @param {string[]} keywords The keywords to set.
     * @returns {Keyword} A new instance of the Keyword class.
     */
    static createKeyword(postback, keywords) {
        return new internal_1.Keyword(postback, keywords);
    }
    /**
     * Creates an instance of the DatePickerField class.
     * @param {string} id The ID of the date picker field.
     * @param {string} label The label of the field.
     * @returns {DatePickerField} The created instance of the DatePickerField.
     */
    static createDatePickerField(id, label) {
        return new internal_1.DatePickerField(id, label);
    }
    /**
     * Creates an instance of the SingleSelectField class.
     * @param {string} id The unique identifier of the field.
     * @param {string} label The label of the field.
     * @param {SelectFieldOption[]} options The options of the field.
     * @returns {SingleSelectField} The created instance of the SingleSelectField.
     */
    static createSingleSelectField(id, label, options) {
        return new internal_1.SingleSelectField(id, label, options);
    }
    /**
     * Creates an instance of the MultiSelectField class.
     * @param {string} id The ID of the field.
     * @param {string} label The label of the field.
     * @param {SelectFieldOption[]} options The options of the field.
     * @returns {MultiSelectField} The created instance of the MultiSelectField.
     */
    static createMultiSelectField(id, label, options) {
        return new internal_1.MultiSelectField(id, label, options);
    }
    /**
     * Creates an instance of the SelectFieldOption class.
     * @param {string} label The label of the option.
     * @param {any} value The value of the option. If not specified, the label is used as the value.
     * @returns {SelectFieldOption} The created instance of the SelectFieldOption.
     */
    static createSelectFieldOption(label, value) {
        return new internal_1.SelectFieldOption(label, value);
    }
    /**
     * Creates an instance of the NumberInputField class.
     * @param {string} id The unique identifier of the field.
     * @param {string} label The label of the field.
     * @returns {NumberInputField} The created instance of the NumberInputField.
     */
    static createNumberInputField(id, label) {
        return new internal_1.NumberInputField(id, label);
    }
    /**
     * Creates an instance of the TextField class.
     * @param {string} label The label of the field.
     * @param {any} value The value of the field.
     * @returns {TextField} The created instance of the TextField.
     */
    static createTextField(label, value) {
        return new internal_1.TextField(label, value);
    }
    /**
     * Creates an instance of the TextInputField class.
     * @param {string} id The unique identifier of the field.
     * @param {string} label The label of the field.
     * @returns {TextInputField} The created instance of the TextInputField.
     */
    static createTextInputField(id, label) {
        return new internal_1.TextInputField(id, label);
    }
    /**
     * Creates an instance of the TimePickerField class.
     * @param {string} id The unique identifier of the field.
     * @param {string} label The label of the field.
     * @returns {TimePickerField} The created instance of the TimePickerField.
     */
    static createTimePickerField(id, label) {
        return new internal_1.TimePickerField(id, label);
    }
    /**
     * Creates an instance of the ToggleField class.
     * @param {string} id The unique identifier of the field.
     * @param {string} label The label of the field.
     * @param {any} valueOff The value when the toggle is off.
     * @param {any} valueOn The value when the toggle is on.
     * @returns {ToggleField} The created instance of the ToggleField.
     */
    static createToggleField(id, label, valueOff, valueOn) {
        return new internal_1.ToggleField(id, label, valueOff, valueOn);
    }
    /**
     * Creates an instance of the LinkField class.
     * @param {string} label The label of the link field.
     * @param {string} value The value of the link field.
     * @param {string} linkLabel The link label of the link field.
     * @returns {LinkField} The created instance of the LinkField.
     */
    static createLinkField(label, value, linkLabel) {
        return new internal_1.LinkField(label, value, linkLabel);
    }
    /**
     * Creates an instance of the ActionField class.
     * @param action The action of the action field.
     * @returns The created instance of the ActionField.
     */
    static createActionField(action) {
        return new internal_1.ActionField(action);
    }
    /**
     * Creates an instance of the MediaField class.
     * @param label The label of the field.
     * @param value The URL value of the field
     * @param mediaType The media type for the field.
     * @returns The created instance of the MediaField.
     */
    static createMediaField(label, value, mediaType) {
        return new internal_1.MediaField(label, value, mediaType);
    }
}
exports.MessageFactory = MessageFactory;