Hi,
I’m looking for an assistance
I have a react application and I want to have two different tawk widgets:
one widget for public pages available for guest
another widget for dashboard pages for our logged-in clients
I added TawkMessengerReact component with switchWidget and setAttributes functions
import { useEffect, useRef } from "react"
import TawkMessengerReact from "@tawk.to/tawk-messenger-react"
...
const TawkComponent = () => {
...
const handleSwitchWidget = () => {
if (window.Tawk_API && typeof window.Tawk_API.switchWidget === "function") {
window.Tawk_API.switchWidget(
{ propertyId, widgetId },
(error: string) => {
if (error) {
console.log("--- error ---")
console.log(error)
return
}
},
)
}
}
const handleSetAttributes = () => {
if (
window.Tawk_API &&
typeof window.Tawk_API.setAttributes === "function"
) {
window.Tawk_API.setAttributes(
{
name,
email,
hash: signature,
},
(error: string) => {
if (error) {
console.log("--- error ---")
console.log(error)
return
}
},
)
}
}
useEffect(() => {
if (TAWK_DISABLED) {
return
}
handleFetchTawk()
}, [clientId])
useEffect(() => {
if (TAWK_DISABLED) {
return
}
handleSwitchWidget()
if (isLoggedIn && isFetched) {
handleSetAttributes()
}
}, [widgetId])
return (
<TawkMessengerReact
useRef={tawkMessengerRef}
propertyId={propertyId}
widgetId={widgetId}
/>
)
}
– propertyId
is the same for widgets
– widgetId
is defined in tawk dashboard
– name
, email
and signature
are provided by the backend
– Secure Mode was enabled in the tawk dashboard
There is some session start issue
POST https://va.tawk.to/v1/session/start
{
ok: false,
error: { code: "InternalServerError", message: "" },
}
after a while session and a few page refreshes session can be started successfully
POST https://va.tawk.to/v1/session/start
{
ok: true,
data: ...
}
After login and widget switch I got the same session start error
POST https://va.tawk.to/v1/session/start
{
ok: false,
error: { code: "InternalServerError", message: "" },
}
I guess the problem is somewhere in tawk chat authentication because cleanup cookies like twk_uuid_...
and twk_idm_key
help to start a session
What is the proper way to switch widgets and update client attributes like name and email?
Appreciate any feedback and suggestions