Skip to content

Commit ab5ab2c

Browse files
committed
feat(admin): restore chat broadcast tools in app settings
Port the preserved admin broadcast flow onto dev so app owners can send announcements to all chats or selected pinned rooms and track async delivery progress without relying on old dev-tf history.
1 parent 393e057 commit ab5ab2c

File tree

3 files changed

+425
-54
lines changed

3 files changed

+425
-54
lines changed

src/http.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,22 @@ export const httpV2 = axios.create({
3434
baseURL: import.meta.env.VITE_API_V2,
3535
});
3636

37+
export const httpV2App = axios.create({
38+
baseURL: import.meta.env.VITE_API_V2,
39+
});
40+
41+
function getAppJwt(): string {
42+
let appJwt = httpTokens.appJwt;
43+
if (!appJwt && typeof window !== 'undefined' && window.useAppStore) {
44+
const appToken = window.useAppStore.getState()?.currentApp?.appToken;
45+
if (appToken) {
46+
appJwt = appToken;
47+
httpTokens.appJwt = appToken;
48+
}
49+
}
50+
return appJwt || '';
51+
}
52+
3753
const AUTH_WHITELIST: Array<string | RegExp> = [
3854
'/users/login-with-email',
3955
'/users/login',
@@ -101,6 +117,14 @@ function attachAuthInterceptors(client: AxiosInstance) {
101117
attachAuthInterceptors(http);
102118
attachAuthInterceptors(httpV2);
103119

120+
httpV2App.interceptors.request.use((config) => {
121+
config.headers = config.headers || {};
122+
if (!(config.headers as any).Authorization) {
123+
(config.headers as any).Authorization = getAppJwt();
124+
}
125+
return config;
126+
}, null);
127+
104128
export const refreshToken = async () => {
105129
try {
106130
const response = await http.post('/users/login/refresh', null, {
@@ -528,6 +552,33 @@ export function deleteDefaultRooms(appId: string, chatJid: string) {
528552
});
529553
}
530554

555+
export function httpBroadcastChatsV2(
556+
payload: {
557+
text: string;
558+
allRooms?: boolean;
559+
chatNames?: string[];
560+
chatIds?: string[];
561+
metadata?: any;
562+
dryRun?: boolean;
563+
},
564+
opts?: { appToken?: string }
565+
) {
566+
const cfg = opts?.appToken
567+
? { headers: { Authorization: opts.appToken } }
568+
: undefined;
569+
return httpV2App.post('/chats/broadcast', payload, cfg);
570+
}
571+
572+
export function httpGetBroadcastChatsJobV2(
573+
jobId: string,
574+
opts?: { appToken?: string }
575+
) {
576+
const cfg = opts?.appToken
577+
? { headers: { Authorization: opts.appToken } }
578+
: undefined;
579+
return httpV2App.get(`/chats/broadcast/${jobId}`, cfg);
580+
}
581+
531582
export const sendHSFormData = async (
532583
appId: string,
533584
formId: string,

src/pages/AppSettings/AppSettings.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,7 @@ export default function AppSettings() {
782782
defaultChatRooms={defaultChatRooms}
783783
setDefaultChatRooms={setDefaultChatRooms}
784784
appId={appId as string}
785+
appToken={app?.appToken || ''}
785786
/>
786787
</TabPanel>
787788

0 commit comments

Comments
 (0)