oscerd opened a new pull request, #29060: URL: https://github.com/apache/camel/pull/29060
Fixes [CAMEL-26213](https://issues.apache.org/jira/browse/CAMEL-26213), found while adding the catalog body types (CAMEL-24961). ## 1. The first message of an endpoint, and of each resetChat, is never sent **Was:** For the first message of the endpoint, and for every message with `resetChat=true`, `ChatScriptBot.sendChat` called `init`. `init` sent a message with a null text, which went out as the text `null`, and its reply (the greeting of the bot) became the reply of the exchange. The message itself was never sent. **Now:** The conversation starts with an empty message, which the ChatScript client-server protocol defines as the start of a conversation and requires first for a new user. The message is then sent, so the reply is the answer of the bot to it. A first message with an empty text only starts the conversation, and its reply is the greeting. `ChatScriptMessage.toCSFormat` writes a missing field as empty text instead of `null`. ## 2. The producer drops every header **Was:** The producer set the reply with `exchange.getOut().setBody(...)`, so the headers of the message were lost after the call. **Now:** It uses `exchange.getMessage().setBody(...)`, and the headers are kept. ## 3. resetChat resets the endpoint's user, not the message's user **Was:** With `resetChat=true` the producer sent `:reset` as the `chatUserName` option of the endpoint (often empty) before it read the body, so the conversation of the user of the message was not reset. **Now:** The producer reads the body first and sends `:reset` for the user of the message, or for `chatUserName` when the message has no user. `ChatScriptBot` has a new `reset(String user)` for this; `reset()` is kept and still resets the `chatUserName` user. ## 4. sendChat(String) calls init(null) **Was:** `ChatScriptBot.sendChat(String)` called `init(null)` for the first message, which failed with a `NullPointerException`. **Now:** It builds the message from the text and the user and bot names of the bot first, and sends it like `sendChat(ChatScriptMessage)`: the first text starts the conversation and is then sent. ## Tests `ChatScriptConversationTest` runs the producer and the bot against a fake ChatScript server on a local socket. The server records the user, bot and text of every message it receives and answers the empty start message with a greeting. - The first message, as JSON text or as a `ChatScriptMessage`, is sent after an empty start message, the next messages are sent once, and an empty first message returns the greeting. - With `resetChat=true` every message resets the conversation of the user of the message, or of `chatUserName` when the message has none, starts a new one and is then sent. - The headers of the message are kept. - `sendChat(String)` starts the conversation and sends the text. - A missing field is written as empty text. Revert check: with the src/main change reverted, 8 of 8 new tests fail: the start message went out as `null` (5 tests), the headers were gone (1), `:reset` was sent for the user `""` (1), and `sendChat(String)` failed with the old `NullPointerException` (1). Module: 10 tests, 0 failures (8 new, 2 existing). `ChatScriptComponentIT` needs the ChatScript container and was not run. ## Docs and generated files - The component page says that the first message starts the conversation with an empty message and is then sent, that an empty first message returns the greeting, which user `resetChat` resets, and that the headers are kept. - Catalog copy of the page. `chatscript.json` and the body types are unchanged, as the bodies are the same. - Upgrade guide entry for 4.24, as the reply to the first message and the user that `resetChat` resets change. ## Not changed - The conversation is still started once per endpoint, not once per user: an endpoint that serves several users sends the start message only before the first message (and, with `resetChat`, before every message). Starting it per user would need a map of the users seen, which this issue does not ask for. - When the first message has text, the greeting that answers the start message is not part of the reply: the reply is the answer to the message. - `sendChat(String)` is fixed rather than removed, as `ChatScriptBot` is a public class. Main only, as the other fixes of the CAMEL-24961 follow-ups. _Claude Code on behalf of Andrea Cosentino (oscerd)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
