File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -126,6 +126,8 @@ export function createClient(config: {
126126 axios : axiosClient ,
127127 socket,
128128 appId,
129+ serverUrl,
130+ token,
129131 } ) ,
130132 cleanup : ( ) => {
131133 socket . disconnect ( ) ;
@@ -141,6 +143,8 @@ export function createClient(config: {
141143 axios : serviceRoleAxiosClient ,
142144 socket,
143145 appId,
146+ serverUrl,
147+ token
144148 } ) ,
145149 cleanup : ( ) => {
146150 socket . disconnect ( ) ;
Original file line number Diff line number Diff line change @@ -2,17 +2,22 @@ import { RoomsSocket } from "../utils/socket-utils.js";
22import { AgentConversation , AgentMessage } from "./agents.types.js" ;
33import { AxiosInstance } from "axios" ;
44import { ModelFilterParams } from "../types.js" ;
5+ import { getAccessToken } from "../utils/auth-utils.js" ;
56
67export type AgentsModuleConfig = {
78 axios : AxiosInstance ;
89 socket : ReturnType < typeof RoomsSocket > ;
910 appId : string ;
11+ serverUrl ?: string ;
12+ token ?: string ;
1013} ;
1114
1215export function createAgentsModule ( {
1316 axios,
1417 socket,
1518 appId,
19+ serverUrl,
20+ token,
1621} : AgentsModuleConfig ) {
1722 const baseURL = `/apps/${ appId } /agents` ;
1823
@@ -74,8 +79,16 @@ export function createAgentsModule({
7479 } ) ;
7580 } ;
7681
77- const generateUserWhatsAppLink = ( agentName : string ) => {
78- return axios . post ( `/whatsapp/generate-user-link` , { agent_name : agentName } ) ;
82+ const getWhatsAppConnectURL = ( agentName : string ) => {
83+ const baseUrl = `${ serverUrl } /whatsapp/${ appId } /${ encodeURIComponent ( agentName ) } ` ;
84+ const accessToken = token ?? getAccessToken ( ) ;
85+
86+ if ( accessToken ) {
87+ return `${ baseUrl } ?token=${ accessToken } ` ;
88+ } else {
89+ // No token - URL will redirect to login automatically
90+ return baseUrl ;
91+ }
7992 } ;
8093
8194 return {
@@ -85,6 +98,6 @@ export function createAgentsModule({
8598 createConversation,
8699 addMessage,
87100 subscribeToConversation,
88- generateUserWhatsAppLink ,
101+ getWhatsAppConnectURL ,
89102 } ;
90103}
You can’t perform that action at this time.
0 commit comments