@vogent/vogent-web-client 0.0.1

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 @@
1
+ export * from "./gql";
package/codegen.ts ADDED
@@ -0,0 +1,29 @@
1
+ // eslint-disable-next-line import/no-extraneous-dependencies
2
+ import { CodegenConfig } from '@graphql-codegen/cli';
3
+
4
+ const config: CodegenConfig = {
5
+ generates: {
6
+ './__generated__/': {
7
+ preset: 'client',
8
+ schema: 'https://api.getelto.com/query',
9
+ documents: ['*.ts'],
10
+ plugins: [
11
+ {
12
+ add: {
13
+ content: '/* eslint-disable */',
14
+ },
15
+ },
16
+ ],
17
+ presetConfig: {
18
+ gqlTagName: 'gql',
19
+ fragmentMasking: false,
20
+ },
21
+ config: {
22
+ dedupeFragments: true,
23
+ },
24
+ },
25
+ },
26
+ ignoreNoDocuments: true,
27
+ };
28
+
29
+ export default config;
@@ -0,0 +1,12 @@
1
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
2
+
3
+ export interface VogentCall {
4
+ on: (ev: 'mute' | 'disconnect', fn: (...args: any[]) => void) => void;
5
+ mute: (status: boolean) => void;
6
+ disconnect: () => void;
7
+ sendDigits: (k: string) => void;
8
+ }
9
+
10
+ export interface VogentDevice {
11
+ connect: (p: any) => Promise<VogentCall>;
12
+ }
@@ -0,0 +1,103 @@
1
+ import { VogentCall } from './VogentDevice';
2
+ import { VonageClient, LoggingLevel } from '@vonage/client-sdk';
3
+
4
+ export class VonageCall {
5
+ _callId: string;
6
+ _client: VonageClient;
7
+ _liveListen: boolean;
8
+ _params: any;
9
+ _handlers: {
10
+ ev: 'mute' | 'disconnect';
11
+ fn: (...args: any[]) => void;
12
+ }[];
13
+
14
+ constructor(callId: string, client: VonageClient, params: any) {
15
+ this._callId = callId;
16
+ this._client = client;
17
+ this._params = params;
18
+ this._handlers = [];
19
+
20
+ this._client.on('callHangup', (callId, _, reason) => {
21
+ if (callId !== this._callId) {
22
+ return;
23
+ }
24
+
25
+ console.log('Call status changed', reason, callId);
26
+
27
+ if (
28
+ !this._liveListen &&
29
+ (reason === 'REMOTE_HANGUP' || reason === 'REMOTE_NO_ANSWER_TIMEOUT')
30
+ ) {
31
+ console.log('Reconnecting');
32
+ this._client
33
+ .serverCall(this._params)
34
+ .then((cid: string) => {
35
+ this._callId = cid;
36
+ })
37
+ .catch((err) => {
38
+ console.error('Error reconnecting', err);
39
+ this.sendEvent('disconnect');
40
+ });
41
+ } else {
42
+ this.sendEvent('disconnect');
43
+ }
44
+ });
45
+ }
46
+
47
+ mute(status: boolean) {
48
+ if (status) {
49
+ this._client.mute(this._callId).then(() => {
50
+ this.sendEvent('mute', true);
51
+ });
52
+ } else {
53
+ this._client.unmute(this._callId).then(() => {
54
+ this.sendEvent('mute', false);
55
+ });
56
+ }
57
+ }
58
+
59
+ sendDigits(k: string) {
60
+ this._client.sendDTMF(this._callId, k);
61
+ }
62
+
63
+ disconnect() {
64
+ this._client.hangup(this._callId);
65
+ }
66
+
67
+ sendEvent(evName: string, ...args: any[]) {
68
+ for (const { ev, fn } of this._handlers) {
69
+ if (ev === evName) {
70
+ fn(...args);
71
+ }
72
+ }
73
+ }
74
+
75
+ on(ev: 'mute' | 'disconnect', fn: (...args: any[]) => void) {
76
+ this._handlers.push({
77
+ ev,
78
+ fn,
79
+ });
80
+ }
81
+ }
82
+
83
+ export class VonageDevice {
84
+ _sessionId: string;
85
+ _client: VonageClient;
86
+
87
+ private constructor(sessionId: string, client: VonageClient, liveListen = false) {
88
+ this._sessionId = sessionId;
89
+ this._client = client;
90
+ }
91
+
92
+ static async getDevice(sessionToken: string, disableEffects = false): Promise<VonageDevice> {
93
+ const client = new VonageClient({ loggingLevel: LoggingLevel.Warn });
94
+ const sessId = await client.createSession(sessionToken);
95
+ return new VonageDevice(sessId, client, disableEffects);
96
+ }
97
+
98
+ async connect(p: any): Promise<VogentCall> {
99
+ const call = await this._client.serverCall(p.params);
100
+ const v = new VonageCall(call, this._client, p.params);
101
+ return v;
102
+ }
103
+ }
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "@vogent/vogent-web-client",
3
+ "version": "0.0.1",
4
+ "license": "MIT",
5
+ "dependencies": {
6
+ "@apollo/client": "^3.12.4",
7
+ "@vonage/client-sdk": "^1.7.2",
8
+ "graphql": "^16.10.0"
9
+ },
10
+ "devDependencies": {
11
+ "@graphql-codegen/cli": "^5.0.3",
12
+ "@graphql-codegen/client-preset": "^4.5.1",
13
+ "@graphql-typed-document-node/core": "^3.2.0"
14
+ }
15
+ }
package/queries.ts ADDED
@@ -0,0 +1,64 @@
1
+ import { gql } from './__generated__';
2
+
3
+ export const AI_CREATE_AD_HOC_DIAL_SESSION = gql(`
4
+ mutation CreateAdHocDialSession($input: CreateAdHocDialSessionInput!) {
5
+ createAdHocDialSession(input: $input) {
6
+ id
7
+ telephonyProvider
8
+ }
9
+ }`);
10
+
11
+ export const AI_START_DIAL_SESSION = gql(`
12
+ mutation StartDialSession($sessionId: ID!) {
13
+ startDialSession(dialSessionId: $sessionId)
14
+ }
15
+ `);
16
+
17
+ export const AI_HANGUP_CALL = gql(`
18
+ mutation HangupCall($dialId: ID!, $dropVoicemail: Boolean, $transferNumber: String) {
19
+ hangupCall(dialId: $dialId, dropVoicemail: $dropVoicemail, transferNumber: $transferNumber)
20
+ }
21
+ `);
22
+
23
+ export const AI_GET_TOKEN = gql(`
24
+ mutation BrowserDialToken($input: BrowserDialTokenInput!) {
25
+ browserDialToken(input: $input) {
26
+ token
27
+ iceConfig
28
+ }
29
+ }
30
+ `);
31
+
32
+ export const AI_CONNECT_SESSION = gql(`
33
+ subscription ConnectSession($sessionId: ID!) {
34
+ connectSession(sessionId: $sessionId) {
35
+ messageType
36
+ content {
37
+ __typename
38
+ ... on DialsUpdatedMessage {
39
+ contactId
40
+ dials {
41
+ id
42
+ status
43
+ answerType
44
+ phoneField
45
+ callDispositionId
46
+ systemResultType
47
+ toNumber
48
+ }
49
+ contactComplete
50
+ }
51
+ ... on DialConnectMessage {
52
+ dialId
53
+ }
54
+ ... on SessionUpdatedMessage {
55
+ dialSession {
56
+ id
57
+ status
58
+ }
59
+ reason
60
+ }
61
+ }
62
+ }
63
+ }
64
+ `);
package/utils.ts ADDED
@@ -0,0 +1,16 @@
1
+ export function dialStatusIsComplete(status: string) {
2
+ switch (status) {
3
+ case 'completed':
4
+ return true;
5
+ case 'canceled':
6
+ return true;
7
+ case 'no-answer':
8
+ return true;
9
+ case 'failed':
10
+ return true;
11
+ case 'busy':
12
+ return true;
13
+ default:
14
+ return false;
15
+ }
16
+ }