Gotchas: hbf-webchat
Package-specific non-obvious patterns and pitfalls. Loaded on demand when working on this package.
- Needs
local/config.jsfor dev startup: The dev startup script imports../local/config.jswith no fallback. Must create the file manually with{ deploymentId, apiUrl }before starting. Thelocal/directory is gitignored.
DirectLine Architecture
- hbf-webchat connects to hbf-bot via Microsoft's botframework-directline (Azure DirectLine), NOT open-bot-framework. The directline client is bundled inside botframework-webchat. OBF is a planned future self-hosted replacement but is not yet integrated.
Pre-Auth Token Init
customData.authTokenis extracted duringinvokeCustomFunctions(): Site owners passauthToken(and optionalauthRefreshToken) inHBF_retrieveUserInfo()'scustomData. Extracted atCONNECT_FULFILLED(init) and on each message cycle.authIsPreAuthis set totrueso the shield icon is non-clickable. Also supports runtime updates viaHBFWebchat.setAuthToken(divId, token, refreshToken?).
Auth Status
- Webchat does NOT persist auth status in web storage: The shield icon only appears when the bot explicitly sends
auth/status { authenticated: true }. Security is enforced server-side. - Auth/logout handled via AuthEventStep lifecycle step: Intercepts
auth/logoutevents, clears auth store, sendsauth/status { authenticated: false }, stops lifecycle. AuthEventStep is logout-only. Do NOT add auth/status re-emission there (race on session restart). - Auth/status re-emission belongs in auth nodes, not pipeline:
authenticateUserandisAuthenticatedActionfire-and-forgetsendAuthStatusEvent(). Ensures icon only appears when flow's auth check confirms validity.
CSS Variables and Widget Modes
-
--headerBorderRadius,--headerMargin,--headerHeightare only set in the BUBBLE path ofapp.ts— not in EMBEDDED. Any feature that reads these variables (e.g., a listening overlay that needs to position itself below the header) must handle the undefined/unset case or provide CSS fallbacks (e.g.,var(--headerHeight, 0px)). -
.embed-widget-containerneedsposition: relativefor absolutely-positioned children to have a correct positioning context. Without it, absolutely-positioned elements (e.g., a listening overlay) will escape the container and position relative to the nearest positioned ancestor in the host page.