Message suggestions / canned messages

MessageField.setText lets you build a "message suggestion" or "canned responses" type of mechanism by pre-filling the text in the message field. This way, users have two options: they can send the suggested message to save time or they can change it to fit their specific questions.

You can pre-populate the message field immediately when creating the UI:

const inbox = talkSession.createInbox({ ... });
inbox.messageField.setText("Hey, is this item still available?")
inbox.mount(document.getElementById("inbox-container"));

Or, at any time, modify it in an already-mounted Inbox:

inbox.messageField.setText("Hey, this works too? Great!");

It's done similarly with the Chatbox and the Popup.

Message field visibility

By default, the message field is always visible. The messageField.visible option, together with MessageField.setVisible let you programmatically show or hide the message field:

const inbox = talkSession.createInbox({ messageField: { visible: false } });
inbox.mount(document.getElementById("inbox-container"));

// .. later:
inbox.messageField.setVisible(true);

Additionally, you can configure the message field to be visible depending on the current conversation's properties, using a conversation predicate. For example, to hide the message field on every conversation in which the current user can not write, you could do:

const predicate = {
    access: ["==", "ReadWrite"]
}
const inbox = talkSession.createInbox({ messageField: { visible: predicate } });

This will automatically show or hide the message field as the user switches between conversations that they do and do not have write access to.

You can use custom fields too: for example, to temporarily mute all users, you could set a "muted" custom field on the conversation, and use a predicate like this:

const predicate = {
    custom: {
        muted: "!exists"
    }
}
const inbox = talkSession.createInbox({ messageField: { visible: predicate } });

If you then use the REST API to add or remove the muted custom field, the message field will disappear and reappear in real-time.

Autofocusing the message field

To focus the message field, just call inbox.messageField.focus() at any time. Note that on mobile devices, this will cause the on-screen keyboard to pop up, obscuring part of the screen.

Controlling Spellcheck, Placeholders, and the Enter key

See MessageFieldOptions for more settings related to the message field.