MessageField

Encapsulates the message entry field tied to the currently selected conversation.

Methods

getText

1MessageField.getText(): Promise<string>

Gets the current content of the message field.

Parameters

None

Returns

Promise<string>

setText

1MessageField.setText(text: string): void

Sets the message entry field to text. Useful if you want to guide your user with message suggestions.

Parameters

NameTypeDescription
text RequiredstringThe text to be displayed in the message entry field

Returns

void

typeText

1MessageField.typeText(text: string): void

Types the given text into the message field.

Inserts text wherever the cursor currently is.

This method may be useful for various bot/simulation scenarios. Additionally, it lets you make it so that any regular keypress lets the user start typing into the message field, even if it is not focused.

To do that, capture the keypress using a regular window event listener, ensure that the user isn't typing into a different input, and then call this method to type the key, followed by focus. Note that TalkJS already does this out-of-the box when the chat UI iframe has focus and ChatboxOptions​.captureKeyboardEvents is off.

Parameters

NameTypeDescription
text RequiredstringThe text to be inserted in the message entry field

Returns

void

setVisible

1MessageField.setVisible(visible: boolean | ConversationPredicate): void

Sets the visibility of the Message Field to a given value or to a certain predicate.

Parameters

NameTypeDescription
visible Requiredboolean | ConversationPredicateA boolean or predicate that outlines the circumstances the message field should be hidden

Returns

void

focus

1MessageField.focus(): void

Focuses the message entry field.

Parameters

None

Returns

void