Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ export function createClient(config: {
axios: axiosClient,
socket,
appId,
serverUrl,
token,
}),
cleanup: () => {
socket.disconnect();
Expand All @@ -141,6 +143,8 @@ export function createClient(config: {
axios: serviceRoleAxiosClient,
socket,
appId,
serverUrl,
token
}),
cleanup: () => {
socket.disconnect();
Expand Down
19 changes: 16 additions & 3 deletions src/modules/agents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ import { RoomsSocket } from "../utils/socket-utils.js";
import { AgentConversation, AgentMessage } from "./agents.types.js";
import { AxiosInstance } from "axios";
import { ModelFilterParams } from "../types.js";
import { getAccessToken } from "../utils/auth-utils.js";

export type AgentsModuleConfig = {
axios: AxiosInstance;
socket: ReturnType<typeof RoomsSocket>;
appId: string;
serverUrl?: string;
token?: string;
};

export function createAgentsModule({
axios,
socket,
appId,
serverUrl,
token,
}: AgentsModuleConfig) {
const baseURL = `/apps/${appId}/agents`;

Expand Down Expand Up @@ -74,8 +79,16 @@ export function createAgentsModule({
});
};

const generateUserWhatsAppLink = (agentName: string) => {
return axios.post(`/whatsapp/generate-user-link`, { agent_name: agentName });
const getWhatsAppConnectURL = (agentName: string) => {
const baseUrl = `${serverUrl}/whatsapp/${appId}/${encodeURIComponent(agentName)}`;
const accessToken = token ?? getAccessToken();

if (accessToken) {
return `${baseUrl}?token=${accessToken}`;
} else {
// No token - URL will redirect to login automatically
return baseUrl;
}
};

return {
Expand All @@ -85,6 +98,6 @@ export function createAgentsModule({
createConversation,
addMessage,
subscribeToConversation,
generateUserWhatsAppLink,
getWhatsAppConnectURL,
};
}
Loading