ifixkart-admin/services/api/integrationService.ts

257 lines
6.8 KiB
TypeScript

import { apiFetch } from './client';
export interface IntegrationOverview {
whatsapp_internal: {
name: string;
channel: string;
status: string;
phone?: string | null;
push_name?: string | null;
gateway_url: string;
source: string;
};
whatsapp_customer: {
name: string;
channel: string;
status: string;
source: string;
endpoint?: string;
};
email: {
name: string;
provider: string;
status: string;
sender?: string;
source: string;
};
meta_ads: {
name: string;
status: string;
app_id?: string;
ad_account_id?: string;
page_id?: string;
source: string;
};
google_analytics: {
name: string;
status: string;
property_id?: string;
source: string;
};
knowlarity: {
name: string;
status: string;
virtual_number?: string;
source: string;
};
shiprocket: {
name: string;
status: string;
source: string;
pickup_location?: string;
};
}
export const integrationService = {
// Overview
getOverview: async (): Promise<IntegrationOverview> => {
return apiFetch<IntegrationOverview>('/api/v1/integrations/overview');
},
// 1. WhatsApp Internal (OpenWA)
getWhatsappQr: async () => {
return apiFetch<{
status: string;
session_id?: string;
qr_code?: string | null;
phone?: string | null;
push_name?: string | null;
connected_at?: string | null;
message?: string;
}>('/api/v1/integrations/whatsapp/qr');
},
sendWhatsappTest: async (phone: string, message: string) => {
return apiFetch<any>('/api/v1/integrations/whatsapp/test-send', {
method: 'POST',
body: JSON.stringify({ phone, message }),
});
},
restartWhatsappSession: async () => {
return apiFetch<any>('/api/v1/integrations/whatsapp/restart', {
method: 'POST',
});
},
// 2. Customer WhatsApp (WATI)
getWatiCredentials: async () => {
return apiFetch<{
api_endpoint: string;
api_token: string;
source: string;
is_locked_by_config: boolean;
}>('/api/v1/integrations/wati/credentials');
},
saveWatiCredentials: async (payload: { api_endpoint: string; api_token: string }) => {
return apiFetch<any>('/api/v1/integrations/wati/credentials', {
method: 'PUT',
body: JSON.stringify(payload),
});
},
testWatiConnection: async (payload: { api_endpoint: string; api_token: string }) => {
return apiFetch<{
status: string;
templates_count?: number;
templates?: any[];
detail?: string;
status_code?: number;
}>('/api/v1/integrations/wati/test', {
method: 'POST',
body: JSON.stringify(payload),
});
},
getWatiTemplates: async () => {
return apiFetch<{ status: string; templates: any[] }>('/api/v1/integrations/wati/templates');
},
sendWatiTemplate: async (payload: {
phone: string;
template_name: string;
broadcast_name?: string;
parameters?: any[];
}) => {
return apiFetch<any>('/api/v1/integrations/wati/send-template', {
method: 'POST',
body: JSON.stringify(payload),
});
},
// 3. Email (ZeptoMail / SMTP)
getEmailCredentials: async () => {
return apiFetch<{
active_provider: string;
sender_email?: string;
sender_name?: string;
smtp_server?: string;
smtp_port?: number;
smtp_username?: string;
use_tls?: boolean;
source: string;
is_locked_by_config: boolean;
}>('/api/v1/integrations/email/credentials');
},
saveEmailCredentials: async (payload: any) => {
return apiFetch<any>('/api/v1/integrations/email/credentials', {
method: 'PUT',
body: JSON.stringify(payload),
});
},
sendTestEmail: async (payload: { recipient: string; subject?: string; body?: string }) => {
return apiFetch<any>('/api/v1/integrations/email/test', {
method: 'POST',
body: JSON.stringify(payload),
});
},
// 4. Meta Ads
getMetaCredentials: async () => {
return apiFetch<{
app_id?: string;
ad_account_id?: string;
page_id?: string;
instagram_id?: string;
access_token?: string;
source: string;
is_locked_by_config: boolean;
}>('/api/v1/integrations/meta/credentials');
},
saveMetaCredentials: async (payload: any) => {
return apiFetch<any>('/api/v1/integrations/meta/credentials', {
method: 'PUT',
body: JSON.stringify(payload),
});
},
testMetaConnection: async (payload: { access_token: string; ad_account_id?: string }) => {
return apiFetch<any>('/api/v1/integrations/meta/test', {
method: 'POST',
body: JSON.stringify(payload),
});
},
// 5. Knowlarity Telephony
getKnowlarityCredentials: async () => {
return apiFetch<{
api_key?: string;
authorization?: string;
virtual_number?: string;
call_url?: string;
log_url?: string;
source: string;
is_locked_by_config: boolean;
}>('/api/v1/integrations/call/credentials');
},
saveKnowlarityCredentials: async (payload: any) => {
return apiFetch<any>('/api/v1/integrations/call/credentials', {
method: 'PUT',
body: JSON.stringify(payload),
});
},
makeKnowlarityCall: async (payload: { agent_number: string; customer_number: string }) => {
return apiFetch<any>('/api/v1/integrations/call/make-call', {
method: 'POST',
body: JSON.stringify(payload),
});
},
getKnowlarityCallLogs: async (page = 1, limit = 20) => {
return apiFetch<any>(`/api/v1/integrations/call/logs?page=${page}&limit=${limit}`);
},
// 6. Shiprocket Logistics
getShiprocketCredentials: async () => {
return apiFetch<{
email?: string;
pickup_location?: string;
pickup_pin?: string;
api_url?: string;
source: string;
is_locked_by_config: boolean;
}>('/api/v1/integrations/shipping/credentials');
},
saveShiprocketCredentials: async (payload: any) => {
return apiFetch<any>('/api/v1/integrations/shipping/credentials', {
method: 'PUT',
body: JSON.stringify(payload),
});
},
authShiprocket: async (payload: { email: string; password: string }) => {
return apiFetch<any>('/api/v1/integrations/shipping/auth', {
method: 'POST',
body: JSON.stringify(payload),
});
},
checkShiprocketServiceability: async (payload: {
pickup_pin: string;
delivery_pin: string;
weight?: number;
cod?: boolean;
}) => {
return apiFetch<any>('/api/v1/integrations/shipping/serviceability', {
method: 'POST',
body: JSON.stringify(payload),
});
},
};