setChatMessages: Switching Greetings
setChatMessages switches greeting versions from a code block inside the greeting. Typical use: put a set of "choose your opening" buttons in the greeting; the user taps one and jumps straight to that version of the greeting.
Signature
declare function setChatMessages(
updates: [{ message_id: 0; swipe_id: number }],
option?: Record<string, never>,
): Promise<void>Example
```html
<!doctype html>
<html>
<body>
<button id="opening-0">Opening One</button>
<button id="opening-1">Opening Two</button>
<script>
document.querySelector('#opening-0').onclick = () =>
setChatMessages([{ message_id: 0, swipe_id: 0 }]);
document.querySelector('#opening-1').onclick = async () => {
try {
await setChatMessages([{ message_id: 0, swipe_id: 1 }]);
} catch (error) {
console.error(error.message);
}
};
</script>
</body>
</html>
```Availability
setChatMessages can only be called from code blocks written inside the greeting, and the greeting must have at least two switchable versions. Code blocks in other messages (such as AI replies) don't have this function — a capability check finds window.setChatMessages is undefined.
swipe_id is the greeting version's index, starting from 0. On success, the greeting switches to the specified version and the chat scrolls back to the top so the user reads the new greeting from the beginning.
Intentionally Unsupported
These calls are all rejected:
- Passing multiple elements in
updates(trying to update several messages at once) - Updating a message whose
message_idis not0 - Updating message text or any other field
- Passing extra options
- Using a nonexistent or out-of-range
swipe_id
setChatMessages is not a general chat-history write API, and it can't read chat history either.
Tips
- When the availability conditions aren't met (e.g. only one greeting version), the function doesn't exist in the code block — run a capability check first:
typeof window.setChatMessages === 'function' - There's no confirmation dialog when switching — make the button labels clear about what will happen
- For writing multi-version greetings, see What is a Greeting?