Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
37651 vikas 1
package com.spice.profitmandi.service.lms;
2
 
3
import com.spice.profitmandi.dao.entity.auth.AuthUser;
4
import com.spice.profitmandi.dao.entity.user.LeadCall;
5
import com.spice.profitmandi.dao.enumuration.dtr.LeadCallProvider;
6
 
7
import java.io.InputStream;
8
 
9
/**
10
 * The seam between the LMS and whichever telephony vendor actually places the call.
11
 *
12
 * <p>Exists because the two candidate providers work in opposite directions: Vonage's Client SDK
13
 * places the call <em>from the browser</em> once we hand it a token, while Knowlarity places it
14
 * <em>from the server</em> and rings the agent's handset first. {@link Handshake} is what lets the
15
 * LMS front-end treat both the same — it either receives a token to dial with, or is told the call is
16
 * already on its way.
17
 *
18
 * <p>Everything else in the LMS (the {@code user.lead_call} history, DND, disposition binding, the
19
 * recording gate) is provider-agnostic and sits above this interface, so swapping vendors — which the
20
 * India VoIP position may yet force — does not reach into the lead record.
21
 */
22
public interface LmsDialerProvider {
23
 
24
    /** How a call gets started, from the browser's point of view. */
25
    enum Mode {
26
        /** Browser dials over WebRTC using {@link Handshake#token}. */
27
        WEBRTC,
28
        /** Server already placed the call; the agent's own handset will ring. */
29
        SERVER_PLACED
30
    }
31
 
32
    /** What the browser needs in order to start, or the reason it cannot. */
33
    class Handshake {
34
        public final boolean ok;
35
        public final Mode mode;
36
        /** Client credential for WEBRTC mode; null otherwise. Treat as a secret. */
37
        public final String token;
38
        /** Vonage application id, or the vendor's equivalent, when the client SDK needs it. */
39
        public final String applicationId;
40
        public final String reason;
41
 
42
        private Handshake(boolean ok, Mode mode, String token, String applicationId, String reason) {
43
            this.ok = ok;
44
            this.mode = mode;
45
            this.token = token;
46
            this.applicationId = applicationId;
47
            this.reason = reason;
48
        }
49
 
50
        public static Handshake webrtc(String token, String applicationId) {
51
            return new Handshake(true, Mode.WEBRTC, token, applicationId, null);
52
        }
53
 
54
        public static Handshake serverPlaced() {
55
            return new Handshake(true, Mode.SERVER_PLACED, null, null, null);
56
        }
57
 
58
        /** Refuse with a reason the agent can act on — never a bare failure. */
59
        public static Handshake refuse(String reason) {
60
            return new Handshake(false, null, null, null, reason);
61
        }
62
    }
63
 
64
    /**
65
     * Place the call server-side. Only meaningful for {@link Mode#SERVER_PLACED} providers — a
66
     * WebRTC provider dials from the browser and refuses this.
67
     *
68
     * @return the vendor's call id, stored so state can be polled and the recording found later
69
     */
70
    String placeCall(AuthUser agent, String agentEndpoint, String toNumber) throws Exception;
71
 
72
    LeadCallProvider provider();
73
 
74
    /** False when credentials are absent, so the UI can hide the dialer rather than fail mid-call. */
75
    boolean isConfigured();
76
 
77
    /** Prepare this agent to place a call. Never throws for an unprovisioned agent — refuses instead. */
78
    Handshake prepare(AuthUser agent);
79
 
80
    /**
81
     * Open the vendor's copy of a call recording for archival. The caller owns the stream and must
82
     * close it. Returns null when the vendor has no recording for this call.
83
     */
84
    InputStream fetchRecording(LeadCall call) throws Exception;
85
 
86
    /** A recording the vendor holds, before we have copied it anywhere. */
87
    class RecordingRef {
88
        /** The vendor's recording id, stored on {@code lead_call.recording_uuid}. */
89
        public final String id;
90
        public final int durationSeconds;
91
 
92
        public RecordingRef(String id, int durationSeconds) {
93
            this.id = id;
94
            this.durationSeconds = durationSeconds;
95
        }
96
    }
97
 
98
    /**
99
     * Find the vendor's recording for a finished call, or null if there is not one (yet).
100
     *
101
     * <p>Needed by providers that place calls server-side: they get no recording webhook, so the only
102
     * way a recording is ever attached to a lead is by asking after the fact. The default returns null
103
     * for webhook-driven providers, which are told about their recordings and have nothing to look up.
104
     */
105
    default RecordingRef findRecording(LeadCall call) {
106
        return null;
107
    }
108
}