@wizai/agent-sip-sdk 0.1.5-alpha → 0.1.6-alpha

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,48 @@
1
+ import type { IApiProps, IRespones, IAgentStatusListResponse, IAgentStatusResponse, IGetAgentSettingParams, IGetAgentSettingResponse, IUpdateAgentTicketParams, IRegisterSSEParams, ICloseSSEParams, ISwitchAgentStatusParams, IOutboundCallParams, IOutboundCallResponse, IAgentResponseTimeParams, IGetCallTaskInfoParams, IGetCallTaskInfoResponse, ISendBeaconParams } from './types';
2
+ import { EApiCode } from '../enums/common';
3
+ declare class Api {
4
+ private baseUrl;
5
+ private readonly id;
6
+ private static instance;
7
+ private eventSource;
8
+ private retryCount;
9
+ private retryMap;
10
+ private token;
11
+ private getSystemToken;
12
+ private resetSSE;
13
+ constructor(props: IApiProps);
14
+ validateToken(id: string, token: string): Promise<IRespones<boolean>>;
15
+ initToken(): Promise<{
16
+ code: EApiCode;
17
+ data: null;
18
+ message: string;
19
+ }>;
20
+ refreshToken(): Promise<void>;
21
+ getAgentStatusList(): Promise<IRespones<IAgentStatusListResponse>>;
22
+ getAgentInfo(): Promise<IRespones<IAgentStatusResponse>>;
23
+ getAgentSetting(params: IGetAgentSettingParams): Promise<IGetAgentSettingResponse>;
24
+ updateAgentHangup(agentId: number): Promise<IGetAgentSettingResponse>;
25
+ updateAgentTicket(data: IUpdateAgentTicketParams): Promise<IRespones<any>>;
26
+ registerSSE(data: IRegisterSSEParams): Promise<unknown>;
27
+ closeSSE(data: ICloseSSEParams): Promise<void>;
28
+ switchAgentStatus(data: ISwitchAgentStatusParams): Promise<IRespones<IAgentStatusResponse>>;
29
+ outboundCall(data: IOutboundCallParams): Promise<IRespones<IOutboundCallResponse>>;
30
+ saveAgentResponseTime(data: IAgentResponseTimeParams): Promise<IRespones<any>>;
31
+ getCallTaskInfo(data: IGetCallTaskInfoParams): Promise<IGetCallTaskInfoResponse>;
32
+ getAfterCallProcessTime(data: IGetCallTaskInfoParams): Promise<IRespones<number>>;
33
+ formatFormData<T = Record<string, any>>(params: T): FormData;
34
+ sendBeacon<T extends ISendBeaconParams>(params: T): void;
35
+ clearnSendBeaconQueue(): Promise<void>;
36
+ /**
37
+ * 获取token,支持降级策略
38
+ * 1. 优先使用内存中的token
39
+ * 2. 如果内存为空,从sessionStorage读取
40
+ * @returns token字符串
41
+ */
42
+ private getTokenWithFallback;
43
+ waitToken(timeout?: number, duration?: number): Promise<unknown>;
44
+ private request;
45
+ private executePeriodically;
46
+ static getInstance(options?: IApiProps): Api;
47
+ }
48
+ export default Api;
@@ -0,0 +1,144 @@
1
+ import { EApiCode } from '../enums/common';
2
+ import { EAgentStatus, EAgentAction } from '../enums/agent';
3
+ export interface IRequestOptionsType<T = any> {
4
+ method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD';
5
+ url: string;
6
+ data?: T;
7
+ headers?: Record<string, string>;
8
+ }
9
+ export interface IApiProps {
10
+ id: string;
11
+ getSystemToken: () => Promise<string>;
12
+ resetSSE: () => Promise<void>;
13
+ baseUrl?: string;
14
+ retryCount?: number;
15
+ }
16
+ export interface IRespones<T> {
17
+ code: EApiCode;
18
+ data: T;
19
+ message: string;
20
+ msg?: string;
21
+ }
22
+ export interface IRefreshTokenResponse {
23
+ token: string;
24
+ expire: string;
25
+ refreshToken: null;
26
+ refreshExpire: null;
27
+ userId: string;
28
+ userName: string;
29
+ renderLocale: null;
30
+ logout: null;
31
+ entExpireTips: null;
32
+ entExpire: null;
33
+ firstLogin: null;
34
+ initPassword: null;
35
+ userCacheVO: null;
36
+ entId: string;
37
+ }
38
+ interface IAgentStatusItem {
39
+ id: number;
40
+ entId: number;
41
+ name: string;
42
+ status: number;
43
+ isSystemDefault: boolean;
44
+ description: string;
45
+ createTime: string;
46
+ updateTime: string;
47
+ }
48
+ export type IAgentStatusListResponse = Array<IAgentStatusItem>;
49
+ export interface IAgentStatus {
50
+ id: number;
51
+ number: string;
52
+ name: null;
53
+ enterpriseId: string;
54
+ userId: string;
55
+ outboundLineId: string;
56
+ outboundLineName: null;
57
+ groupId: number;
58
+ status: number;
59
+ username: string;
60
+ password: string;
61
+ realm: string;
62
+ outboundLineNames: null;
63
+ type: number;
64
+ sipServer: null;
65
+ statusName: string;
66
+ ticket: string;
67
+ }
68
+ export type IAgentStatusResponse = Array<IAgentStatus>;
69
+ export interface IGetAgentSettingParams {
70
+ key: string;
71
+ }
72
+ export interface IGetAgentSettingResponse {
73
+ callType: string;
74
+ transferWaitingTime: number;
75
+ transferWaitingRingtone: string;
76
+ agentWaitingTime: number;
77
+ agentRingtone: string;
78
+ }
79
+ export interface IUpdateAgentTicketParams {
80
+ agentId: number;
81
+ ticket: string;
82
+ type: EAgentStatus;
83
+ }
84
+ export interface IRegisterSSEParams {
85
+ agentId: number;
86
+ onMessage: (_e: any) => void;
87
+ }
88
+ export interface ICloseSSEParams {
89
+ agentId: number;
90
+ clearTicket: 0 | 1;
91
+ }
92
+ export interface ISwitchAgentStatusParams {
93
+ id: number;
94
+ groupId: number;
95
+ status: EAgentStatus;
96
+ subStatus?: string;
97
+ }
98
+ export interface IOutboundCallParams {
99
+ phone: string;
100
+ line: string;
101
+ }
102
+ export interface IOutboundCallResponse {
103
+ callId: string;
104
+ callType: number;
105
+ }
106
+ export interface IAgentResponseTimeParams {
107
+ callId: string;
108
+ agentResponseTime: number;
109
+ agentId: number;
110
+ agentGroupId: number;
111
+ resultType: EAgentAction;
112
+ }
113
+ export interface IGetCustomerInfoParams {
114
+ customerId: string;
115
+ }
116
+ export interface IGetCustomerInfoResponse {
117
+ phone: string;
118
+ name: string;
119
+ email: string;
120
+ gender: number;
121
+ address: string;
122
+ companyName: string;
123
+ source: string;
124
+ customerStatus: number;
125
+ userName: string;
126
+ extraJson: string;
127
+ }
128
+ export interface IGetCallTaskInfoParams {
129
+ callTaskId: string;
130
+ }
131
+ export interface IGetCallTaskInfoResponse {
132
+ callTaskId: string;
133
+ name: string;
134
+ templateName: string;
135
+ }
136
+ export interface ISendBeaconParams {
137
+ url: string;
138
+ lastSendResult?: boolean;
139
+ createTime?: string;
140
+ sendTime?: string;
141
+ Authentication?: string;
142
+ trace?: string;
143
+ }
144
+ export {};
@@ -0,0 +1,9 @@
1
+ export declare enum EAgentStatus {
2
+ OFFLINE = 0,
3
+ ONLINE = 1,
4
+ HANGUP = 4
5
+ }
6
+ export declare enum EAgentAction {
7
+ ANSWER = 1,
8
+ HANGUP = 2
9
+ }
@@ -0,0 +1,19 @@
1
+ export declare enum EApiCode {
2
+ SUCCESS = 0,
3
+ FAILED = -1,
4
+ TIMEOUT = -2,
5
+ UNAUTHORIZED = 401,
6
+ UNAVAILABLE = 403,
7
+ SYSTEMBUSY = 450,
8
+ NOENOUGNCHARACTER = 10001
9
+ }
10
+ export declare enum ECode {
11
+ SUCCESS = 200,
12
+ UNAUTHORIZED = 401,
13
+ UNAVAILABLE = 403,
14
+ TIMEOUT = 408,
15
+ LOCKED = 423,
16
+ SYSTEMBUSY = 450,
17
+ FAILED = 500,
18
+ NOENOUGNCHARACTER = 10001
19
+ }
@@ -0,0 +1,57 @@
1
+ import { ECode } from './enums/common';
2
+ import type { IAnswerFnType, INewMessageFnType, ISessionType, ISessionEventListener } from './sip/types';
3
+ import type { IAgentSipSDKOptions, IAgentStatusParams, IInitType, IInitFnType, IAgentType, IAgentFnType, IGetAgentStatus, IGetAgentStatusList, ISwitchAgentStatus, IOutboundCall } from './types';
4
+ declare class AgentSipSDK {
5
+ private sip;
6
+ private api;
7
+ private agentInfo;
8
+ private initEvent;
9
+ private agentEvent;
10
+ private agentWaitingTime;
11
+ private agentResponseTime;
12
+ private timer;
13
+ private callDetails;
14
+ constructor(props: IAgentSipSDKOptions);
15
+ private init;
16
+ getAgentStatusList(): Promise<IGetAgentStatusList>;
17
+ private getTicket;
18
+ private getHostName;
19
+ private processSSEMessage;
20
+ private resetSSE;
21
+ private createSSEAndOpensips;
22
+ getAgentStatus(): Promise<IGetAgentStatus>;
23
+ private onlineAgent;
24
+ private offlineAgent;
25
+ switchAgentStatus(data: IAgentStatusParams): Promise<ISwitchAgentStatus>;
26
+ outboundCall(phoneNumber: string): Promise<IOutboundCall>;
27
+ finshACW(): Promise<{
28
+ code: ECode;
29
+ data: null;
30
+ message: string;
31
+ }>;
32
+ private sessionEnded;
33
+ private sessionFailed;
34
+ private openOnunload;
35
+ private cancelOnunload;
36
+ private saveAgentResponseTime;
37
+ hangup(): void;
38
+ private timingResTime;
39
+ private incomingCall;
40
+ answer(): void;
41
+ ignore(): void;
42
+ mute(): void;
43
+ unmute(): void;
44
+ attachInitEvent(type: IInitType, listener: IInitFnType): void;
45
+ removeInitEvent(type: IInitType, listener: IInitFnType): void;
46
+ private emitInitEvent;
47
+ attachAgentEvent(type: IAgentType, listener: IAgentFnType): void;
48
+ removeAgentEvent(type: IAgentType, listener: IAgentFnType): void;
49
+ private emitAgentEvent;
50
+ attachAnswerEvent(listener: IAnswerFnType): void;
51
+ removeAnswerEvent(listener: IAnswerFnType): void;
52
+ attachNewMessageEvent(listener: INewMessageFnType): void;
53
+ removeNewMessageEvent(listener: INewMessageFnType): void;
54
+ attchSessionEvent<T extends ISessionType>(type: T, listener: ISessionEventListener<T>): void;
55
+ removeSessionEvent<T extends ISessionType>(type: T, listener: ISessionEventListener<T>): void;
56
+ }
57
+ export default AgentSipSDK;
@@ -0,0 +1,68 @@
1
+ import type { UAEventMap, IncomingRTCSessionEvent } from 'jssip/lib/UA.d.ts';
2
+ import type { RTCSession, RTCSessionEventMap } from 'jssip/lib/RTCSession.d.ts';
3
+ import type { IAnswerFnType, IAnswerEventPayload, INewMessageFnType, INewMessageEventPayload, ISessionType, ISessionEventListener, ISessionEventPayload } from './types';
4
+ declare class SIP {
5
+ private callType;
6
+ private ua;
7
+ private socket;
8
+ private isManualStop;
9
+ private pingTimerId;
10
+ private newRTCSession;
11
+ incomingSession: RTCSession;
12
+ private outgoingSession;
13
+ private stream;
14
+ private audio;
15
+ private ringAudio;
16
+ private answerEvent;
17
+ private newMessageEvent;
18
+ private sessionEvent;
19
+ private callDetails;
20
+ private readonly incomingCallCallback;
21
+ private readonly getMediaStream;
22
+ constructor(props: {
23
+ incomingCallCallback: (_e: IncomingRTCSessionEvent) => Promise<IAnswerEventPayload>;
24
+ getMediaStream?: () => Promise<MediaStream>;
25
+ });
26
+ /**
27
+ *
28
+ *
29
+ * @memberof AgentSipClient
30
+ */
31
+ initMicrophone(): void;
32
+ destroyMicrophone(): void;
33
+ reset(): void;
34
+ setCallType(type: 'inboundCall' | 'outboundCall' | ''): void;
35
+ getCallType(): 'inboundCall' | 'outboundCall' | '';
36
+ init(options: {
37
+ wssuri: string;
38
+ password: string;
39
+ uri: string;
40
+ }): Promise<void>;
41
+ start(): void;
42
+ stop(isManualStop?: boolean): void;
43
+ destroy(): void;
44
+ getSocketWS(): any;
45
+ sendPing(): void;
46
+ playRing(): void;
47
+ stopRing(): void;
48
+ call(sipPhoneNumber: string, eventHandlers: any, _stream: any, _muteAudio: boolean): void;
49
+ hangup(): void;
50
+ ignore(): void;
51
+ answer(): void;
52
+ attachAnswerEvent(listener: IAnswerFnType): void;
53
+ removeAnswerEvent(listener: IAnswerFnType): void;
54
+ emitAnswerEvent(data: IAnswerEventPayload): void;
55
+ attachNewMessageEvent(listener: INewMessageFnType): void;
56
+ removeNewMessageEvent(listener: INewMessageFnType): void;
57
+ emitNewMessageEvent(data: INewMessageEventPayload): void;
58
+ attchSessionEvent<T extends ISessionType>(type: T, listener: ISessionEventListener<T>): void;
59
+ removeSessionEvent<T extends ISessionType>(type: T, listener: ISessionEventListener<T>): void;
60
+ emitSessionEvent<T extends ISessionType>(type: T, data: ISessionEventPayload<T>): void;
61
+ on<T extends keyof UAEventMap>(type: T, listener: UAEventMap[T]): this;
62
+ RTCSessionOn<T extends keyof RTCSessionEventMap>(type: T, listener: RTCSessionEventMap[T]): void;
63
+ mute(): void;
64
+ unmute(): void;
65
+ isMuted(): MediaConstraints;
66
+ getIsRegistered(): boolean;
67
+ }
68
+ export default SIP;
@@ -0,0 +1,28 @@
1
+ import type { IResponse, ICallDetails } from '../types';
2
+ export interface ISipOptions {
3
+ getSystemToken: () => Promise<string>;
4
+ retryCount?: number;
5
+ }
6
+ export interface IRequestOptionsType {
7
+ method: string;
8
+ url: string;
9
+ headers: {
10
+ Authorization: string;
11
+ };
12
+ }
13
+ export type IAnswerEventPayload = IResponse<ICallDetails | null>;
14
+ export type IAnswerFnType = (_data: IAnswerEventPayload) => void;
15
+ export type INewMessageEventPayload = IResponse<{
16
+ agentId: string;
17
+ callId: string;
18
+ data: Array<any>;
19
+ state: string;
20
+ type: string;
21
+ } | null>;
22
+ export type INewMessageFnType = (_data: INewMessageEventPayload) => void;
23
+ export type ISessionType = 'success' | 'failed' | 'ended';
24
+ export type ISessionEventPayload<T extends ISessionType> = IResponse<ICallDetails | null>;
25
+ export type ISessionEventListener<T extends ISessionType> = (_data: ISessionEventPayload<T>) => void;
26
+ export type ISessionEventType<T extends ISessionType> = {
27
+ [K in T]: Array<ISessionEventListener<K>>;
28
+ };
@@ -0,0 +1,85 @@
1
+ import { ECode } from './enums/common';
2
+ import { EAgentStatus } from './enums/agent';
3
+ import type { IAgentStatusListResponse, IOutboundCallResponse } from './api/types';
4
+ export interface IResponse<T = any> {
5
+ code: ECode;
6
+ data: T;
7
+ message: string;
8
+ }
9
+ export interface IAgentSipSDKOptions {
10
+ id: string;
11
+ getSystemToken: () => Promise<string>;
12
+ baseUrl?: string;
13
+ retryCount?: number;
14
+ getMediaStream?: () => Promise<MediaStream>;
15
+ }
16
+ export interface IAgentStatusParams {
17
+ status: EAgentStatus;
18
+ subStatus: string;
19
+ }
20
+ export type IInitType = 'success' | 'failed';
21
+ export type IInitEventPayload = IResponse;
22
+ export type IInitFnType = (_data: IInitEventPayload) => void;
23
+ export type IAgentType = 'online' | 'offline';
24
+ export type IAgentEventPayload = IResponse<IAgentStatusParams>;
25
+ export type IAgentFnType = (_data: IAgentEventPayload) => void;
26
+ export interface ICallDetails {
27
+ callId: string;
28
+ callType: string;
29
+ taskName: string;
30
+ afterCallProcessTime: string;
31
+ extraJson: any;
32
+ }
33
+ export interface IGetAgentStatusSuccess {
34
+ code: ECode.SUCCESS | ECode.LOCKED;
35
+ data: {
36
+ id: number;
37
+ groupId: number;
38
+ status: number;
39
+ subStatus: string;
40
+ };
41
+ message: string;
42
+ }
43
+ interface IGetAgentStatusFailed {
44
+ code: ECode.FAILED;
45
+ data: null;
46
+ message: string;
47
+ }
48
+ export type IGetAgentStatus = IGetAgentStatusSuccess | IGetAgentStatusFailed;
49
+ interface IGetAgentStatusListSuccess {
50
+ code: ECode.SUCCESS;
51
+ data: IAgentStatusListResponse;
52
+ message: string;
53
+ }
54
+ interface IGetAgentStatusListFailed {
55
+ code: ECode.FAILED;
56
+ data: null;
57
+ message: string;
58
+ }
59
+ export type IGetAgentStatusList = IGetAgentStatusListSuccess | IGetAgentStatusListFailed;
60
+ export interface ISwitchAgentStatusSuccess {
61
+ code: ECode.SUCCESS;
62
+ data: {
63
+ status: EAgentStatus;
64
+ subStatus: string;
65
+ };
66
+ message: string;
67
+ }
68
+ interface ISwitchAgentStatusFailed {
69
+ code: ECode.FAILED;
70
+ data: null;
71
+ message: string;
72
+ }
73
+ export type ISwitchAgentStatus = ISwitchAgentStatusSuccess | ISwitchAgentStatusFailed;
74
+ interface IOutboundCallSuccess {
75
+ code: ECode.SUCCESS;
76
+ data: IOutboundCallResponse;
77
+ message: string | undefined;
78
+ }
79
+ interface IOutboundCallFailed {
80
+ code: ECode.FAILED;
81
+ data: null;
82
+ message: string | undefined;
83
+ }
84
+ export type IOutboundCall = IOutboundCallSuccess | IOutboundCallFailed;
85
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wizai/agent-sip-sdk",
3
- "version": "0.1.5-alpha",
3
+ "version": "0.1.6-alpha",
4
4
  "description": "Manages SIP clients and agent status, simplifying calls and events.",
5
5
  "main": "lib/agent-sip-sdk-cjs.js",
6
6
  "module": "lib/agent-sip-sdk-es.js",