@tarunzyraclavis/zyra-twilio-wrapper 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,162 @@
1
+ export interface Config {
2
+ serverUrl: string,
3
+ identity: string,
4
+ waitUrl ?: string
5
+ }
6
+
7
+ export interface TwilioConferenceParticipant {
8
+ accountSid: string;
9
+ callSid: string;
10
+ callSidToCoach: string | null;
11
+ coaching: boolean;
12
+ conferenceSid: string;
13
+ dateCreated: string; // ISO 8601 date string
14
+ dateUpdated: string; // ISO 8601 date string
15
+ endConferenceOnExit: boolean;
16
+ hold: boolean;
17
+ label: string | null;
18
+ muted: boolean;
19
+ queueTime: string | null; // Twilio may return seconds as a string or null
20
+ startConferenceOnEnter: boolean;
21
+ status: 'queued' | 'ringing' | 'in-progress' | 'connected' | 'completed' | string;
22
+ uri: string;
23
+ }
24
+
25
+ export interface TwilioConference {
26
+ conferenceSid: string; // Your own wrapper ID
27
+ conferences: TwilioConferenceDetails;
28
+ }
29
+
30
+ export interface TwilioConferenceDetails {
31
+ accountSid: string;
32
+ apiVersion: string;
33
+ callSidEndingConference: string | null;
34
+ dateCreated: string; // ISO 8601 date
35
+ dateUpdated: string; // ISO 8601 date
36
+ friendlyName: string;
37
+ reasonConferenceEnded: string | null;
38
+ region: string;
39
+ sid: string; // Conference SID (same as conferenceSid)
40
+ status: 'init' | 'in-progress' | 'completed' | 'terminated' | string;
41
+ subresourceUris: {
42
+ participants: string;
43
+ recordings: string;
44
+ [key: string]: string;
45
+ };
46
+ uri: string;
47
+ }
48
+
49
+ export interface TokenRequestPayload {
50
+ identity: string;
51
+ ttl: number;
52
+ incomingAllow: boolean;
53
+ }
54
+
55
+ export interface TokenResponse {
56
+ result: {
57
+ data: {
58
+ token: string;
59
+ };
60
+ };
61
+ }
62
+
63
+ export interface CallResult {
64
+ message: string;
65
+ status: boolean;
66
+ }
67
+
68
+ export interface HoldCallPayload {
69
+ callSid: string;
70
+ conferenceName: string;
71
+ waitUrl: string;
72
+ }
73
+
74
+ export interface ResumeCallPayload {
75
+ callSid: string;
76
+ conferenceName: string;
77
+ }
78
+
79
+ export interface HoldPayload {
80
+ callSid: string;
81
+ conferenceName: string;
82
+ waitUrl: string;
83
+ }
84
+
85
+ export interface AddParticipantPayload {
86
+ conferenceName: string;
87
+ newParticipantNo: string;
88
+ }
89
+
90
+ export interface HoldAndAddResult extends CallResult {
91
+ holdResponse?: any;
92
+ addParticipantResponse?: any;
93
+ }
94
+
95
+ export interface GetConferencePayload {
96
+ conferenceName: string;
97
+ }
98
+
99
+ export interface GetConferenceResult extends CallResult {
100
+ conferenceDetail?: TwilioConference;
101
+ }
102
+
103
+ export interface GetParticipantsPayload {
104
+ conferenceSid: string;
105
+ }
106
+
107
+ export interface GetParticipantsResult extends CallResult {
108
+ participants?: TwilioConferenceParticipant[];
109
+ }
110
+
111
+ export interface RemoveParticipantPayload {
112
+ conferenceSid: string;
113
+ callSid: string;
114
+ }
115
+
116
+ export interface RemoveParticipantResult extends CallResult {
117
+ // Optionally, you can include server response data
118
+ data?: any;
119
+ }
120
+
121
+ export type CallResponse<T = void> =
122
+ | { success: true; message: string; data: T }
123
+ | { success: false; error: Error };
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+
132
+ // const data = {
133
+ // Called: '+14159643849',
134
+ // ToState: 'CA',
135
+ // DialCallStatus: 'completed',
136
+ // CallerCountry: 'US',
137
+ // Direction: 'inbound',
138
+ // CallerState: '',
139
+ // ToZip: '94965',
140
+ // DialCallSid: 'CA825f011a791f34a69f1296ba692feccd',
141
+ // CallSid: 'CA97818ba8ca7429801a6079c41244f461',
142
+ // To: '+14159643849',
143
+ // CallerZip: '',
144
+ // ToCountry: 'US',
145
+ // CalledZip: '94965',
146
+ // ApiVersion: '2010-04-01',
147
+ // CalledCity: 'SAUSALITO',
148
+ // CallStatus: 'completed',
149
+ // From: '+18884359109',
150
+ // DialBridged: 'true',
151
+ // AccountSid: 'ACb1589cdb0710cb771f48b3414b62f9d3',
152
+ // DialCallDuration: '14',
153
+ // CalledCountry: 'US',
154
+ // CallerCity: '',
155
+ // ToCity: 'SAUSALITO',
156
+ // FromCountry: 'US',
157
+ // Caller: '+18884359109',
158
+ // FromCity: '',
159
+ // CalledState: 'CA',
160
+ // FromZip: '',
161
+ // FromState: ''
162
+ // }
@@ -0,0 +1,37 @@
1
+ import axios, { AxiosError } from "axios";
2
+
3
+ /**
4
+ * Handles errors from Axios requests in a consistent way.
5
+ *
6
+ * @param error - The error thrown by Axios or any other source.
7
+ * @param onErrorCallback - Optional callback to handle the error externally.
8
+ * @param contextMessage - Optional custom message to provide context for the error.
9
+ */
10
+ export function handleAxiosError(
11
+ error: unknown,
12
+ onErrorCallback?: (error: Error) => void,
13
+ contextMessage = "Request failed"
14
+ ): void {
15
+ let finalError: Error;
16
+
17
+ if (axios.isAxiosError(error)) {
18
+ const axiosError = error as AxiosError;
19
+ const status = axiosError.response?.status ?? "Unknown";
20
+ const statusText = axiosError.response?.statusText ?? "No status text";
21
+ const responseData = axiosError.response?.data
22
+ ? JSON.stringify(axiosError.response.data)
23
+ : "No response data";
24
+
25
+ finalError = new Error(
26
+ `[AxiosError] ${contextMessage}: ${status} ${statusText} | Response: ${responseData}`
27
+ );
28
+ } else if (error instanceof Error) {
29
+ finalError = new Error(`[Error] ${contextMessage}: ${error.message}`);
30
+ } else {
31
+ finalError = new Error(`[Unknown Error] ${contextMessage}: ${String(error)}`);
32
+ }
33
+
34
+ console.error(finalError); // Optional: log for debugging
35
+ onErrorCallback?.(finalError);
36
+ }
37
+
@@ -0,0 +1,20 @@
1
+ // src/utils/helper.ts
2
+
3
+ import type { CallResponse } from "../types/interface"; // adjust path if needed
4
+
5
+ /**
6
+ * Helper to create success result
7
+ */
8
+ export function createSuccessResult<T>(message: string, data: T): CallResponse<T> {
9
+ return { success : true, message : message, data };
10
+ }
11
+
12
+ /**
13
+ * Helper to create error result
14
+ */
15
+ export function createErrorResult<T = void>(error: Error | string): CallResponse<T> {
16
+ return {
17
+ success: false,
18
+ error: error instanceof Error ? error : new Error(error),
19
+ };
20
+ }