1import { defineStore } from "pinia";
2import { call } from "frappe-ui";
3
4interface MakeCallParams {
5 number?: string;
6 doctype?: string;
7 docname?: string;
8}
9
10interface SetLinkDocParams {
11 docname: string;
12 doctype: string;
13}
14
15export const useTelephonyStore = defineStore("telephony", {
16 state: () => ({
17 isLoading: false,
18 isCallingEnabled: false,
19 isTwilioEnabled: false,
20 isExotelEnabled: false,
21 defaultCallingMedium: "",
22 callMethod: (params: MakeCallParams) => {},
23 linkDoc: {
24 doctype: "",
25 docname: "",
26 },
27 }),
28 actions: {
29 setMakeCall(value: (params: MakeCallParams) => void) {
30 this.callMethod = value;
31 },
32 setDefaultCallingMedium(value: string) {
33 this.defaultCallingMedium = value;
34 },
35 makeCall(params: MakeCallParams) {
36 this.callMethod(params);
37 },
38 setIsCallingEnabled(value: boolean) {
39 this.isCallingEnabled = value;
40 },
41 async fetchCallIntegrationStatus() {
42 try {
43 this.isLoading = true;
44 const data = await call("telephony.api.is_call_integration_enabled");
45 this.isTwilioEnabled = Boolean(data.twilio_enabled);
46 this.isExotelEnabled = Boolean(data.exotel_enabled);
47 this.defaultCallingMedium = data.default_calling_medium;
48 this.isCallingEnabled = this.isTwilioEnabled || this.isExotelEnabled;
49 } catch (error) {
50 console.error("Failed to fetch call integration status:", error);
51 } finally {
52 this.isLoading = false;
53 }
54 },
55 setLinkDoc(params: SetLinkDocParams) {
56 this.linkDoc.docname = params.docname;
57 this.linkDoc.doctype = params.doctype;
58 },
59 },
60});
61