Skip to content

feat(chat): add initialUserMessage option#6956

Open
aymeric-giraudet wants to merge 2 commits intomasterfrom
feat/chat-initial-user-message
Open

feat(chat): add initialUserMessage option#6956
aymeric-giraudet wants to merge 2 commits intomasterfrom
feat/chat-initial-user-message

Conversation

@aymeric-giraudet
Copy link
Copy Markdown
Member

@aymeric-giraudet aymeric-giraudet commented Apr 8, 2026

Summary

FX-3767
Sends a user message automatically when the chat is initialized, unless messages already exist (e.g. restored from localStorage).

Sends a user message automatically when the chat is initialized,
unless messages already exist (e.g. restored from localStorage).
@aymeric-giraudet aymeric-giraudet requested review from a team, Haroenv, Copilot and shaejaz and removed request for a team April 8, 2026 13:59
@codacy-production
Copy link
Copy Markdown

codacy-production bot commented Apr 8, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 4 complexity · 2 duplication

Metric Results
Complexity 4
Duplication 2

View in Codacy

TIP This summary will be updated as you push new changes. Give us feedback

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 8, 2026

More templates

algoliasearch-helper

npm i https://pkg.pr.new/algolia/instantsearch/algoliasearch-helper@6956

instantsearch-ui-components

npm i https://pkg.pr.new/algolia/instantsearch/instantsearch-ui-components@6956

instantsearch.css

npm i https://pkg.pr.new/algolia/instantsearch/instantsearch.css@6956

instantsearch.js

npm i https://pkg.pr.new/algolia/instantsearch/instantsearch.js@6956

react-instantsearch

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch@6956

react-instantsearch-core

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch-core@6956

react-instantsearch-nextjs

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch-nextjs@6956

react-instantsearch-router-nextjs

npm i https://pkg.pr.new/algolia/instantsearch/react-instantsearch-router-nextjs@6956

vue-instantsearch

npm i https://pkg.pr.new/algolia/instantsearch/vue-instantsearch@6956

commit: 058fb82

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds an initialUserMessage option to the Chat connector so a predefined user message is sent automatically on initialization when there is no existing chat history (e.g., restored state), with accompanying tests.

Changes:

  • Extend connectChat params with initialUserMessage?: string.
  • Trigger an automatic chat.sendMessage({ text }) during connector init when there are no existing messages.
  • Add widget and connector option tests covering the new behavior (and one guard case on the widget side).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
tests/common/widgets/chat/options.tsx Adds widget-level tests for sending initialUserMessage on init and skipping when messages already exist.
tests/common/connectors/chat/options.ts Adds connector-level test asserting initialUserMessage is sent on init.
packages/instantsearch.js/src/connectors/chat/connectChat.ts Introduces initialUserMessage param and sends it during init when the message list is empty.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

… exist

- Add !resume guard so initialUserMessage doesn't conflict with resumeStream
- Expand JSDoc to document skip conditions
- Add connector-level test for existing messages guard
*
* When `resume` is enabled, this message is not sent.
*/
initialUserMessage?: string;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you also considered passing messages or initialMessages? that would be a bit more flexible, but I'm not sure if it's useful for anything

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants