Repository navigation
feat(widget,server): setUser and setContext - #432
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
W6 in the P2 plan (F-05 task 26), second part:
ChatCops.setUser()andChatCops.setContext().update()comes next.setUser({ name?, email?, token? } | null)tokensets the client's identity token for signed-in visitors (F-04) and drops the saved session token, so the next message gets a session for the new identity. The server already refuses to carry a session over to another user (security/sessions.ts:130), and starts a new conversation then.null, callsclear(), so one person's conversation never shows for the next.nameandemailbecome visitor details, sent with a conversation's first message even without a pre-chat form, and the name greets the visitor.The widget used to send visitor details only until it knew the server spoke v1. With
newConversation()andclear()from #429, a new conversation on a v1 server would never get them. Now they go with the first message of each conversation, tracked by conversation id.setContext(data | null){ plan: 'Team' }. They go with each message as the newpageContext.data, andnullremoves them.PageContext.datais in core's types and the widget's request type.MAX_PAGE_DATA_*).Script tag loader
Both calls are kept until the chat loads, then applied right after it mounts. So a signed-in page can call
setUser()on load without loading the chat early or touching storage. A test spies onStorage.prototypeto check that.Tests
api.test.ts, 5 of them new here):setContextin the request body and removed withnullsetUserdetails sent with the first message, and the greetingnullclear itnewConversation()on a v1 serversetContexttakes only strings.Checks
Local:
pnpm -r buildpnpm test:coverage: 1757 passedpnpm lint: 39 warnings and 6 infos, same as devpnpm docs:checkpnpm size: the loader is 4.38 of 5 kB (+50 B) and the panel 16.45 of 17 kB (+240 B)Docs: both methods on the API page, and
pageContext.datain the request schema on the server setup and protocol pages.