Repository navigation
Connect the Text Us page to the chat API and texter WebSocket (W6-01) - #166
Merged
Merged
Conversation
Add useChat, which starts a session (token in sessionStorage), opens the texter socket with an auth frame, confirms pending sends from the server echo, catches up with ?after= on reconnect, resumes on refresh, and ends the chat on conversation.closed, a 4401 close, or End conversation. Render the text-us.intro block, line status, chat window (when web chat is enabled) and the SMS number on /text-us, and send Cache-Control: no-store and Referrer-Policy: no-referrer for /text-us and /portal/*. Closes #135
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.
The Text Us page is still a heading. The chat window (#56) runs on local state, and the backend for it is done: sessions and REST (#90) and the texter socket (#112). This ticket connects them, so a student can open
/text-us, read the notice, and talk to a responder (TDD 4.3.1, 4.6.2).Changes:
useChat, a hook that ownschatReducerand talks to the backend. "Start" callsPOST /api/chat/sessionsand keeps the token insessionStorage, so closing the tab ends the texter's identity. The token is only sent in the socket's auth frame or anAuthorizationheader, never in a URL.createSocketon/ws/chatand sends{"type": "auth", "token": ...}inonOpen.{"type": "message", "body": ...}and show as pending. The server'smessage.createdecho confirms the oldest pending message with the same body. An error frame marks it failed, and the failed message can be retried.onReconnectfetchesGET /api/chat/conversation?after=<last id>and adds anything missed. Messages already shown are skipped, so a texter message the socket already delivered is never matched twice.conversation.closedends the chat. A 4401 close clears the token and ends it too.POST /api/chat/conversation/end, then clears the token.sessionStorageon load, the hook resumes withGET /api/chat/conversationinstead of showing the notice again. A rejected token (401) is cleared and the notice shows./text-usshows thetext-us.introcontent block and the line status (useLineStatus). It shows the chat window withchat.noticeas the notice when"web"is in thechannelssetting, and the number with ansms:link whensms_numberis set. I added aloading.tsxlike the other public pages, whichnext buildneeds for this route.next.config.tsheaders()sendsCache-Control: no-storeandReferrer-Policy: no-referrerfor/text-usand/portal/*(TDD 4.8).sessionStorageand sending the auth frame, an echoed message confirming the pending one, a reconnect fetching withafter,conversation.closedand a 4401 both ending the chat and clearing the token, and a refresh with a token resuming the conversation. There are also tests for the page, the headers config, and that nothing logs message bodies or the token./dev/chatis unchanged and still works without the backend. No analytics script loads on/text-us.How to test: run
make dev-backendandmake dev-frontend, open/text-us, start a conversation and send a message. Refresh the tab mid-chat to see it resume, then end the conversation and confirm a refresh shows the notice again.Closes #135