[{"data":1,"prerenderedAt":664},["ShallowReactive",2],{"docs-page:en:integrations:unversioned:connect-web-chat":3},{"page":4,"pageRef":626,"space":627,"edition":632,"spaceOptions":634,"versionOptions":653,"resolvedAuthors":654,"navigation":657},{"id":5,"title":6,"authors":7,"badges":9,"body":10,"contentType":610,"deprecatedSince":611,"description":612,"docId":613,"durationMinutes":114,"extension":614,"introducedIn":611,"meta":615,"navigation":141,"path":616,"releaseVersion":611,"removedIn":611,"seo":617,"spaceId":618,"status":619,"stem":620,"tags":621,"updatedAt":624,"version":611,"__hash__":625},"docs_en\u002Fdocs\u002Fintegrations\u002Fconnect-web-chat.md","Connect Web Chat with server relay",[8],"talkit-docs",[],{"type":11,"value":12,"toc":604},"minimark",[13,17,25,62,67,74,78,101,339,346,350,576,579,583,586,600],[14,15,16],"p",{},"Use a Website integration in server-relay mode when your application has a trusted backend that authenticates its users.",[18,19,22],"doc-callout",{"title":20,"type":21},"What server relay means","note",[14,23,24],{},"Your backend relays authentication and session creation. It does not proxy chat messages: after receiving a grant, the browser connects directly to the TalkIt WebSocket URL.",[26,27,33],"pre",{"className":28,"code":29,"filename":30,"language":31,"meta":32,"style":32},"language-mermaid shiki shiki-themes github-light github-dark","flowchart LR\n  accTitle: Server relay session flow\n  accDescr: The browser requests a grant from the trusted backend, which requests it from TalkIt.\n  Browser[Browser] --> Backend[Trusted backend] --> TalkIt[TalkIt]\n","Server relay session flow","mermaid","",[34,35,36,44,50,56],"code",{"__ignoreMap":32},[37,38,41],"span",{"class":39,"line":40},"line",1,[37,42,43],{},"flowchart LR\n",[37,45,47],{"class":39,"line":46},2,[37,48,49],{},"  accTitle: Server relay session flow\n",[37,51,53],{"class":39,"line":52},3,[37,54,55],{},"  accDescr: The browser requests a grant from the trusted backend, which requests it from TalkIt.\n",[37,57,59],{"class":39,"line":58},4,[37,60,61],{},"  Browser[Browser] --> Backend[Trusted backend] --> TalkIt[TalkIt]\n",[63,64,66],"h2",{"id":65},"prerequisites","Prerequisites",[14,68,69,70,73],{},"You need an active TalkIt agent with text mode enabled, a Website integration configured for server relay, its client ID and secret, and ",[34,71,72],{},"@talkit-llc\u002Ftalkit-js"," in the backend and frontend projects.",[63,75,77],{"id":76},"create-an-authenticated-grant-endpoint","Create an authenticated grant endpoint",[79,80,81],"doc-steps",{},[82,83,84,88,91,98],"ol",{},[85,86,87],"li",{},"Authenticate and authorize the caller on your backend.",[85,89,90],{},"Derive stable customer and session identifiers from trusted server-side state.",[85,92,93,94,97],{},"Call ",[34,95,96],{},"createTalkitServerRelayGrant"," with the Website credentials.",[85,99,100],{},"Return only the short-lived grant to the browser.",[26,102,116],{"className":103,"code":104,"filename":105,"highlights":106,"language":115,"meta":32,"style":32},"language-ts shiki shiki-themes github-light github-dark","import { createTalkitServerRelayGrant } from '@talkit-llc\u002Ftalkit-js\u002Fserver'\n\napp.post('\u002Fapi\u002Ftalkit\u002Ftext-token', requireAuthenticatedUser, async (req, res) => {\n  const grant = await createTalkitServerRelayGrant({\n    apiBaseUrl: process.env.TALKIT_BASE_URL!,\n    clientId: process.env.TALKIT_WEBSITE_CLIENT_ID!,\n    clientSecret: process.env.TALKIT_WEBSITE_CLIENT_SECRET!,\n    channel: 'text',\n    externalSubjectId: `customer:${req.user.id}`,\n    externalSessionId: `session:${req.session.id}`,\n  })\n\n  res.json(grant)\n})\n","server.ts",[40,107,108,109,110,111,112,113,114],5,6,7,8,9,10,11,12,"ts",[34,117,118,137,143,186,207,222,235,248,259,286,310,316,321,333],{"__ignoreMap":32},[37,119,122,126,130,133],{"class":120,"line":40},[39,121],"highlight",[37,123,125],{"class":124},"szBVR","import",[37,127,129],{"class":128},"sVt8B"," { createTalkitServerRelayGrant } ",[37,131,132],{"class":124},"from",[37,134,136],{"class":135},"sZZnC"," '@talkit-llc\u002Ftalkit-js\u002Fserver'\n",[37,138,139],{"class":39,"line":46},[37,140,142],{"emptyLinePlaceholder":141},true,"\n",[37,144,145,148,152,155,158,161,164,167,171,174,177,180,183],{"class":39,"line":52},[37,146,147],{"class":128},"app.",[37,149,151],{"class":150},"sScJk","post",[37,153,154],{"class":128},"(",[37,156,157],{"class":135},"'\u002Fapi\u002Ftalkit\u002Ftext-token'",[37,159,160],{"class":128},", requireAuthenticatedUser, ",[37,162,163],{"class":124},"async",[37,165,166],{"class":128}," (",[37,168,170],{"class":169},"s4XuR","req",[37,172,173],{"class":128},", ",[37,175,176],{"class":169},"res",[37,178,179],{"class":128},") ",[37,181,182],{"class":124},"=>",[37,184,185],{"class":128}," {\n",[37,187,188,191,195,198,201,204],{"class":39,"line":58},[37,189,190],{"class":124},"  const",[37,192,194],{"class":193},"sj4cs"," grant",[37,196,197],{"class":124}," =",[37,199,200],{"class":124}," await",[37,202,203],{"class":150}," createTalkitServerRelayGrant",[37,205,206],{"class":128},"({\n",[37,208,210,213,216,219],{"class":209,"line":107},[39,121],[37,211,212],{"class":128},"    apiBaseUrl: process.env.",[37,214,215],{"class":193},"TALKIT_BASE_URL",[37,217,218],{"class":124},"!",[37,220,221],{"class":128},",\n",[37,223,225,228,231,233],{"class":224,"line":108},[39,121],[37,226,227],{"class":128},"    clientId: process.env.",[37,229,230],{"class":193},"TALKIT_WEBSITE_CLIENT_ID",[37,232,218],{"class":124},[37,234,221],{"class":128},[37,236,238,241,244,246],{"class":237,"line":109},[39,121],[37,239,240],{"class":128},"    clientSecret: process.env.",[37,242,243],{"class":193},"TALKIT_WEBSITE_CLIENT_SECRET",[37,245,218],{"class":124},[37,247,221],{"class":128},[37,249,251,254,257],{"class":250,"line":110},[39,121],[37,252,253],{"class":128},"    channel: ",[37,255,256],{"class":135},"'text'",[37,258,221],{"class":128},[37,260,262,265,268,270,273,276,278,281,284],{"class":261,"line":111},[39,121],[37,263,264],{"class":128},"    externalSubjectId: ",[37,266,267],{"class":135},"`customer:${",[37,269,170],{"class":128},[37,271,272],{"class":135},".",[37,274,275],{"class":128},"user",[37,277,272],{"class":135},[37,279,280],{"class":128},"id",[37,282,283],{"class":135},"}`",[37,285,221],{"class":128},[37,287,289,292,295,297,299,302,304,306,308],{"class":288,"line":112},[39,121],[37,290,291],{"class":128},"    externalSessionId: ",[37,293,294],{"class":135},"`session:${",[37,296,170],{"class":128},[37,298,272],{"class":135},[37,300,301],{"class":128},"session",[37,303,272],{"class":135},[37,305,280],{"class":128},[37,307,283],{"class":135},[37,309,221],{"class":128},[37,311,313],{"class":312,"line":113},[39,121],[37,314,315],{"class":128},"  })\n",[37,317,319],{"class":318,"line":114},[39,121],[37,320,142],{"emptyLinePlaceholder":141},[37,322,324,327,330],{"class":39,"line":323},13,[37,325,326],{"class":128},"  res.",[37,328,329],{"class":150},"json",[37,331,332],{"class":128},"(grant)\n",[37,334,336],{"class":39,"line":335},14,[37,337,338],{"class":128},"})\n",[14,340,341,342,345],{},"Do not accept ",[34,343,344],{},"externalSubjectId"," directly from the browser. Use an immutable identifier from your authenticated account model.",[63,347,349],{"id":348},"connect-the-browser-client","Connect the browser client",[26,351,357],{"className":103,"code":352,"filename":353,"highlights":354,"language":115,"meta":32,"style":32},"import { createTalkitChat } from '@talkit-llc\u002Ftalkit-js'\n\nasync function getSessionToken() {\n  const response = await fetch('\u002Fapi\u002Ftalkit\u002Ftext-token', {\n    method: 'POST',\n    credentials: 'include',\n  })\n\n  if (!response.ok)\n    throw new Error(`TalkIt grant request failed with ${response.status}.`)\n  return response.json()\n}\n\nconst chat = createTalkitChat({\n  baseUrl: 'https:\u002F\u002Fyour-talkit-host.example',\n  getSessionToken,\n})\n\nawait chat.connect()\nchat.send('Hello from the website')\n","chat.ts",[40,323,335,355,356],15,16,[34,358,359,372,376,389,410,420,430,434,438,450,480,493,498,503,519,530,536,541,546,560],{"__ignoreMap":32},[37,360,362,364,367,369],{"class":361,"line":40},[39,121],[37,363,125],{"class":124},[37,365,366],{"class":128}," { createTalkitChat } ",[37,368,132],{"class":124},[37,370,371],{"class":135}," '@talkit-llc\u002Ftalkit-js'\n",[37,373,374],{"class":39,"line":46},[37,375,142],{"emptyLinePlaceholder":141},[37,377,378,380,383,386],{"class":39,"line":52},[37,379,163],{"class":124},[37,381,382],{"class":124}," function",[37,384,385],{"class":150}," getSessionToken",[37,387,388],{"class":128},"() {\n",[37,390,391,393,396,398,400,403,405,407],{"class":39,"line":58},[37,392,190],{"class":124},[37,394,395],{"class":193}," response",[37,397,197],{"class":124},[37,399,200],{"class":124},[37,401,402],{"class":150}," fetch",[37,404,154],{"class":128},[37,406,157],{"class":135},[37,408,409],{"class":128},", {\n",[37,411,412,415,418],{"class":39,"line":107},[37,413,414],{"class":128},"    method: ",[37,416,417],{"class":135},"'POST'",[37,419,221],{"class":128},[37,421,422,425,428],{"class":39,"line":108},[37,423,424],{"class":128},"    credentials: ",[37,426,427],{"class":135},"'include'",[37,429,221],{"class":128},[37,431,432],{"class":39,"line":109},[37,433,315],{"class":128},[37,435,436],{"class":39,"line":110},[37,437,142],{"emptyLinePlaceholder":141},[37,439,440,443,445,447],{"class":39,"line":111},[37,441,442],{"class":124},"  if",[37,444,166],{"class":128},[37,446,218],{"class":124},[37,448,449],{"class":128},"response.ok)\n",[37,451,452,455,458,461,463,466,469,471,474,477],{"class":39,"line":112},[37,453,454],{"class":124},"    throw",[37,456,457],{"class":124}," new",[37,459,460],{"class":150}," Error",[37,462,154],{"class":128},[37,464,465],{"class":135},"`TalkIt grant request failed with ${",[37,467,468],{"class":128},"response",[37,470,272],{"class":135},[37,472,473],{"class":128},"status",[37,475,476],{"class":135},"}.`",[37,478,479],{"class":128},")\n",[37,481,482,485,488,490],{"class":39,"line":113},[37,483,484],{"class":124},"  return",[37,486,487],{"class":128}," response.",[37,489,329],{"class":150},[37,491,492],{"class":128},"()\n",[37,494,495],{"class":39,"line":114},[37,496,497],{"class":128},"}\n",[37,499,501],{"class":500,"line":323},[39,121],[37,502,142],{"emptyLinePlaceholder":141},[37,504,506,509,512,514,517],{"class":505,"line":335},[39,121],[37,507,508],{"class":124},"const",[37,510,511],{"class":193}," chat",[37,513,197],{"class":124},[37,515,516],{"class":150}," createTalkitChat",[37,518,206],{"class":128},[37,520,522,525,528],{"class":521,"line":355},[39,121],[37,523,524],{"class":128},"  baseUrl: ",[37,526,527],{"class":135},"'https:\u002F\u002Fyour-talkit-host.example'",[37,529,221],{"class":128},[37,531,533],{"class":532,"line":356},[39,121],[37,534,535],{"class":128},"  getSessionToken,\n",[37,537,539],{"class":39,"line":538},17,[37,540,338],{"class":128},[37,542,544],{"class":39,"line":543},18,[37,545,142],{"emptyLinePlaceholder":141},[37,547,549,552,555,558],{"class":39,"line":548},19,[37,550,551],{"class":124},"await",[37,553,554],{"class":128}," chat.",[37,556,557],{"class":150},"connect",[37,559,492],{"class":128},[37,561,563,566,569,571,574],{"class":39,"line":562},20,[37,564,565],{"class":128},"chat.",[37,567,568],{"class":150},"send",[37,570,154],{"class":128},[37,572,573],{"class":135},"'Hello from the website'",[37,575,479],{"class":128},[14,577,578],{},"Request a fresh grant for every new connection or reconnect. Do not cache grants or log session tokens.",[63,580,582],{"id":581},"verify-the-integration","Verify the integration",[14,584,585],{},"Confirm that an authenticated user can connect, send a message, receive a response, and start a new session after reconnecting. Also confirm that an unauthenticated user cannot call your grant endpoint.",[14,587,588,589,594,595,599],{},"See the ",[590,591,593],"a",{"href":592},"..\u002Fapi\u002Fapi-overview","current API overview"," for the HTTP contract and the ",[590,596,598],{"href":597},"..\u002Fsdk\u002Fjavascript-sdk","JavaScript SDK guide"," for client lifecycle details.",[601,602,603],"style",{},"html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html pre.shiki code .szBVR, html code.shiki .szBVR{--shiki-default:#D73A49;--shiki-dark:#F97583}html pre.shiki code .sVt8B, html code.shiki .sVt8B{--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sZZnC, html code.shiki .sZZnC{--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sScJk, html code.shiki .sScJk{--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .s4XuR, html code.shiki .s4XuR{--shiki-default:#E36209;--shiki-dark:#FFAB70}html pre.shiki code .sj4cs, html code.shiki .sj4cs{--shiki-default:#005CC5;--shiki-dark:#79B8FF}",{"title":32,"searchDepth":52,"depth":52,"links":605},[606,607,608,609],{"id":65,"depth":46,"text":66},{"id":76,"depth":46,"text":77},{"id":348,"depth":46,"text":349},{"id":581,"depth":46,"text":582},"how-to",null,"Connect an authenticated website user to TalkIt without exposing Website integration credentials.","connect-web-chat","md",{},"\u002Fdocs\u002Fintegrations\u002Fconnect-web-chat",{"title":6,"description":612},"integrations","published","docs\u002Fintegrations\u002Fconnect-web-chat",[618,622,623],"web-chat","security","2026-08-12","4MDPGOnuCYqD8cozMPrwF29rowosJZ5ezgzjw-_rCok",{"spaceId":618,"versionId":611,"docId":613},{"id":618,"title":628,"description":629,"route":630,"searchScope":631},"Integrations","Implementation guides for connecting TalkIt to customer channels and applications.","\u002Fen\u002Fdocs\u002Fintegrations\u002Fconnect-web-chat","space",{"id":611,"label":611,"isCurrent":141,"indexing":633,"currentRoute":630},"index",[635,640,644,648,649],{"id":636,"label":637,"route":638,"isActive":639},"platform","Platform","\u002Fen\u002Fdocs\u002Foverview",false,{"id":641,"label":642,"route":643,"isActive":639},"api","API","\u002Fen\u002Fdocs\u002Fapi\u002Fapi-overview",{"id":645,"label":646,"route":647,"isActive":639},"sdk","SDK","\u002Fen\u002Fdocs\u002Fsdk\u002Fjavascript-sdk",{"id":618,"label":628,"route":630,"isActive":141},{"id":650,"label":651,"route":652,"isActive":639},"changelog","Changelog","\u002Fen\u002Fdocs\u002Fchangelog\u002F2026-08-12",[],[655],{"id":8,"name":656},"TalkIt Docs team",[658],{"id":659,"title":660,"pages":661},"website","Website",[662],{"docId":613,"title":6,"route":630,"pageRef":663,"contentType":610},{"spaceId":618,"versionId":611,"docId":613},1792741581400]