@memberjunction/server 5.44.0 → 5.45.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.
- package/dist/agentSessions/ReturningVisitorRecap.d.ts +39 -0
- package/dist/agentSessions/ReturningVisitorRecap.d.ts.map +1 -0
- package/dist/agentSessions/ReturningVisitorRecap.js +198 -0
- package/dist/agentSessions/ReturningVisitorRecap.js.map +1 -0
- package/dist/agentSessions/SessionJanitor.d.ts +13 -0
- package/dist/agentSessions/SessionJanitor.d.ts.map +1 -1
- package/dist/agentSessions/SessionJanitor.js +65 -7
- package/dist/agentSessions/SessionJanitor.js.map +1 -1
- package/dist/agentSessions/SessionManager.d.ts.map +1 -1
- package/dist/agentSessions/SessionManager.js +37 -0
- package/dist/agentSessions/SessionManager.js.map +1 -1
- package/dist/auth/magicLink/MagicLinkRouter.d.ts +10 -0
- package/dist/auth/magicLink/MagicLinkRouter.d.ts.map +1 -1
- package/dist/auth/magicLink/MagicLinkRouter.js +16 -0
- package/dist/auth/magicLink/MagicLinkRouter.js.map +1 -1
- package/dist/auth/magicLink/index.d.ts +1 -1
- package/dist/auth/magicLink/index.d.ts.map +1 -1
- package/dist/auth/magicLink/index.js +1 -1
- package/dist/auth/magicLink/index.js.map +1 -1
- package/dist/auth/magicLink/types.d.ts +26 -0
- package/dist/auth/magicLink/types.d.ts.map +1 -1
- package/dist/config.d.ts +1883 -144
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +160 -36
- package/dist/config.js.map +1 -1
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +45 -2
- package/dist/context.js.map +1 -1
- package/dist/generated/generated.d.ts +522 -0
- package/dist/generated/generated.d.ts.map +1 -1
- package/dist/generated/generated.js +2860 -0
- package/dist/generated/generated.js.map +1 -1
- package/dist/generic/ResolverBase.d.ts +13 -0
- package/dist/generic/ResolverBase.d.ts.map +1 -1
- package/dist/generic/ResolverBase.js +22 -0
- package/dist/generic/ResolverBase.js.map +1 -1
- package/dist/generic/RunViewResolver.d.ts.map +1 -1
- package/dist/generic/RunViewResolver.js +4 -0
- package/dist/generic/RunViewResolver.js.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +101 -3
- package/dist/index.js.map +1 -1
- package/dist/integration/CustomColumnPromoter.d.ts.map +1 -1
- package/dist/integration/CustomColumnPromoter.js +6 -0
- package/dist/integration/CustomColumnPromoter.js.map +1 -1
- package/dist/realtimeWidget/WidgetRouter.d.ts +26 -0
- package/dist/realtimeWidget/WidgetRouter.d.ts.map +1 -0
- package/dist/realtimeWidget/WidgetRouter.js +182 -0
- package/dist/realtimeWidget/WidgetRouter.js.map +1 -0
- package/dist/realtimeWidget/WidgetSessionService.d.ts +265 -0
- package/dist/realtimeWidget/WidgetSessionService.d.ts.map +1 -0
- package/dist/realtimeWidget/WidgetSessionService.js +477 -0
- package/dist/realtimeWidget/WidgetSessionService.js.map +1 -0
- package/dist/realtimeWidget/host-identity.d.ts +40 -0
- package/dist/realtimeWidget/host-identity.d.ts.map +1 -0
- package/dist/realtimeWidget/host-identity.js +58 -0
- package/dist/realtimeWidget/host-identity.js.map +1 -0
- package/dist/realtimeWidget/index.d.ts +10 -0
- package/dist/realtimeWidget/index.d.ts.map +1 -0
- package/dist/realtimeWidget/index.js +9 -0
- package/dist/realtimeWidget/index.js.map +1 -0
- package/dist/realtimeWidget/visitorIdentity.d.ts +76 -0
- package/dist/realtimeWidget/visitorIdentity.d.ts.map +1 -0
- package/dist/realtimeWidget/visitorIdentity.js +202 -0
- package/dist/realtimeWidget/visitorIdentity.js.map +1 -0
- package/dist/realtimeWidget/widgetCore.d.ts +106 -0
- package/dist/realtimeWidget/widgetCore.d.ts.map +1 -0
- package/dist/realtimeWidget/widgetCore.js +173 -0
- package/dist/realtimeWidget/widgetCore.js.map +1 -0
- package/dist/realtimeWidget/widgetGuestElevation.d.ts +51 -0
- package/dist/realtimeWidget/widgetGuestElevation.d.ts.map +1 -0
- package/dist/realtimeWidget/widgetGuestElevation.js +79 -0
- package/dist/realtimeWidget/widgetGuestElevation.js.map +1 -0
- package/dist/resolvers/ComponentRegistryResolver.d.ts +7 -0
- package/dist/resolvers/ComponentRegistryResolver.d.ts.map +1 -1
- package/dist/resolvers/ComponentRegistryResolver.js +31 -8
- package/dist/resolvers/ComponentRegistryResolver.js.map +1 -1
- package/dist/resolvers/EntityPermissionResolver.d.ts.map +1 -1
- package/dist/resolvers/EntityPermissionResolver.js +1 -2
- package/dist/resolvers/EntityPermissionResolver.js.map +1 -1
- package/dist/resolvers/QuerySystemUserResolver.d.ts +9 -6
- package/dist/resolvers/QuerySystemUserResolver.d.ts.map +1 -1
- package/dist/resolvers/QuerySystemUserResolver.js +15 -13
- package/dist/resolvers/QuerySystemUserResolver.js.map +1 -1
- package/dist/resolvers/RealtimeClientSessionResolver.d.ts +10 -0
- package/dist/resolvers/RealtimeClientSessionResolver.d.ts.map +1 -1
- package/dist/resolvers/RealtimeClientSessionResolver.js +47 -3
- package/dist/resolvers/RealtimeClientSessionResolver.js.map +1 -1
- package/dist/resolvers/RingCentralTelephonyResolver.d.ts +27 -0
- package/dist/resolvers/RingCentralTelephonyResolver.d.ts.map +1 -0
- package/dist/resolvers/RingCentralTelephonyResolver.js +87 -0
- package/dist/resolvers/RingCentralTelephonyResolver.js.map +1 -0
- package/dist/resolvers/RunAIAgentResolver.d.ts.map +1 -1
- package/dist/resolvers/RunAIAgentResolver.js +14 -3
- package/dist/resolvers/RunAIAgentResolver.js.map +1 -1
- package/dist/resolvers/SearchKnowledgeResolver.d.ts.map +1 -1
- package/dist/resolvers/SearchKnowledgeResolver.js +2 -0
- package/dist/resolvers/SearchKnowledgeResolver.js.map +1 -1
- package/dist/resolvers/TeamsMeetingsResolver.d.ts +28 -0
- package/dist/resolvers/TeamsMeetingsResolver.d.ts.map +1 -0
- package/dist/resolvers/TeamsMeetingsResolver.js +91 -0
- package/dist/resolvers/TeamsMeetingsResolver.js.map +1 -0
- package/dist/resolvers/TelephonyResolver.d.ts +26 -0
- package/dist/resolvers/TelephonyResolver.d.ts.map +1 -0
- package/dist/resolvers/TelephonyResolver.js +86 -0
- package/dist/resolvers/TelephonyResolver.js.map +1 -0
- package/dist/resolvers/TestQuerySQLResolver.d.ts +1 -1
- package/dist/resolvers/TestQuerySQLResolver.d.ts.map +1 -1
- package/dist/resolvers/TestQuerySQLResolver.js +2 -3
- package/dist/resolvers/TestQuerySQLResolver.js.map +1 -1
- package/dist/resolvers/VonageTelephonyResolver.d.ts +26 -0
- package/dist/resolvers/VonageTelephonyResolver.d.ts.map +1 -0
- package/dist/resolvers/VonageTelephonyResolver.js +86 -0
- package/dist/resolvers/VonageTelephonyResolver.js.map +1 -0
- package/dist/rest/MediaStreamHandler.js +4 -1
- package/dist/rest/MediaStreamHandler.js.map +1 -1
- package/dist/telephony/RingCentralTelephonyService.d.ts +115 -0
- package/dist/telephony/RingCentralTelephonyService.d.ts.map +1 -0
- package/dist/telephony/RingCentralTelephonyService.js +262 -0
- package/dist/telephony/RingCentralTelephonyService.js.map +1 -0
- package/dist/telephony/TeamsMeetingsRouter.d.ts +40 -0
- package/dist/telephony/TeamsMeetingsRouter.d.ts.map +1 -0
- package/dist/telephony/TeamsMeetingsRouter.js +96 -0
- package/dist/telephony/TeamsMeetingsRouter.js.map +1 -0
- package/dist/telephony/TeamsMeetingsService.d.ts +113 -0
- package/dist/telephony/TeamsMeetingsService.d.ts.map +1 -0
- package/dist/telephony/TeamsMeetingsService.js +196 -0
- package/dist/telephony/TeamsMeetingsService.js.map +1 -0
- package/dist/telephony/TwilioTelephonyRouter.d.ts +36 -0
- package/dist/telephony/TwilioTelephonyRouter.d.ts.map +1 -0
- package/dist/telephony/TwilioTelephonyRouter.js +143 -0
- package/dist/telephony/TwilioTelephonyRouter.js.map +1 -0
- package/dist/telephony/TwilioTelephonyService.d.ts +95 -0
- package/dist/telephony/TwilioTelephonyService.d.ts.map +1 -0
- package/dist/telephony/TwilioTelephonyService.js +193 -0
- package/dist/telephony/TwilioTelephonyService.js.map +1 -0
- package/dist/telephony/VonageTelephonyRouter.d.ts +41 -0
- package/dist/telephony/VonageTelephonyRouter.d.ts.map +1 -0
- package/dist/telephony/VonageTelephonyRouter.js +201 -0
- package/dist/telephony/VonageTelephonyRouter.js.map +1 -0
- package/dist/telephony/VonageTelephonyService.d.ts +90 -0
- package/dist/telephony/VonageTelephonyService.d.ts.map +1 -0
- package/dist/telephony/VonageTelephonyService.js +191 -0
- package/dist/telephony/VonageTelephonyService.js.map +1 -0
- package/dist/telephony/calendar-scheduler.d.ts +67 -0
- package/dist/telephony/calendar-scheduler.d.ts.map +1 -0
- package/dist/telephony/calendar-scheduler.js +133 -0
- package/dist/telephony/calendar-scheduler.js.map +1 -0
- package/dist/telephony/index.d.ts +29 -0
- package/dist/telephony/index.d.ts.map +1 -0
- package/dist/telephony/index.js +38 -0
- package/dist/telephony/index.js.map +1 -0
- package/dist/telephony/media-upgrade-router.d.ts +33 -0
- package/dist/telephony/media-upgrade-router.d.ts.map +1 -0
- package/dist/telephony/media-upgrade-router.js +56 -0
- package/dist/telephony/media-upgrade-router.js.map +1 -0
- package/dist/telephony/ringcentral-runtime.d.ts +14 -0
- package/dist/telephony/ringcentral-runtime.d.ts.map +1 -0
- package/dist/telephony/ringcentral-runtime.js +18 -0
- package/dist/telephony/ringcentral-runtime.js.map +1 -0
- package/dist/telephony/teams-meetings-runtime.d.ts +16 -0
- package/dist/telephony/teams-meetings-runtime.d.ts.map +1 -0
- package/dist/telephony/teams-meetings-runtime.js +20 -0
- package/dist/telephony/teams-meetings-runtime.js.map +1 -0
- package/dist/telephony/teamsAcsMediaRegistry.d.ts +69 -0
- package/dist/telephony/teamsAcsMediaRegistry.d.ts.map +1 -0
- package/dist/telephony/teamsAcsMediaRegistry.js +118 -0
- package/dist/telephony/teamsAcsMediaRegistry.js.map +1 -0
- package/dist/telephony/telephony-runtime.d.ts +14 -0
- package/dist/telephony/telephony-runtime.d.ts.map +1 -0
- package/dist/telephony/telephony-runtime.js +18 -0
- package/dist/telephony/telephony-runtime.js.map +1 -0
- package/dist/telephony/twilioMediaRegistry.d.ts +60 -0
- package/dist/telephony/twilioMediaRegistry.d.ts.map +1 -0
- package/dist/telephony/twilioMediaRegistry.js +106 -0
- package/dist/telephony/twilioMediaRegistry.js.map +1 -0
- package/dist/telephony/vonage-runtime.d.ts +14 -0
- package/dist/telephony/vonage-runtime.d.ts.map +1 -0
- package/dist/telephony/vonage-runtime.js +18 -0
- package/dist/telephony/vonage-runtime.js.map +1 -0
- package/dist/telephony/vonageMediaRegistry.d.ts +78 -0
- package/dist/telephony/vonageMediaRegistry.d.ts.map +1 -0
- package/dist/telephony/vonageMediaRegistry.js +158 -0
- package/dist/telephony/vonageMediaRegistry.js.map +1 -0
- package/package.json +88 -83
- package/src/__tests__/search-knowledge-tags.test.ts +9 -9
- package/src/__tests__/teams-meetings-service.test.ts +65 -0
- package/src/__tests__/teamsAcsMediaRegistry.test.ts +82 -0
- package/src/__tests__/twilio-telephony-service.test.ts +23 -0
- package/src/__tests__/twilioMediaRegistry.test.ts +103 -0
- package/src/__tests__/vonageMediaRegistry.test.ts +180 -0
- package/src/__tests__/widget.test.ts +204 -0
- package/src/__tests__/widgetGuestElevation.test.ts +57 -0
- package/src/__tests__/widgetHostIdentity.test.ts +117 -0
- package/src/agentSessions/ReturningVisitorRecap.ts +242 -0
- package/src/agentSessions/SessionJanitor.ts +66 -6
- package/src/agentSessions/SessionManager.ts +38 -0
- package/src/auth/magicLink/MagicLinkRouter.ts +17 -0
- package/src/auth/magicLink/index.ts +1 -0
- package/src/auth/magicLink/types.ts +26 -0
- package/src/config.ts +172 -38
- package/src/context.ts +50 -3
- package/src/generated/generated.ts +1991 -1
- package/src/generic/ResolverBase.ts +28 -0
- package/src/generic/RunViewResolver.ts +4 -0
- package/src/index.ts +109 -3
- package/src/integration/CustomColumnPromoter.ts +6 -0
- package/src/realtimeWidget/WidgetRouter.ts +204 -0
- package/src/realtimeWidget/WidgetSessionService.ts +714 -0
- package/src/realtimeWidget/host-identity.ts +84 -0
- package/src/realtimeWidget/index.ts +15 -0
- package/src/realtimeWidget/visitorIdentity.ts +258 -0
- package/src/realtimeWidget/widgetCore.ts +231 -0
- package/src/realtimeWidget/widgetGuestElevation.ts +115 -0
- package/src/resolvers/ComponentRegistryResolver.ts +36 -10
- package/src/resolvers/EntityPermissionResolver.ts +1 -2
- package/src/resolvers/QuerySystemUserResolver.ts +14 -10
- package/src/resolvers/RealtimeClientSessionResolver.ts +59 -2
- package/src/resolvers/RingCentralTelephonyResolver.ts +64 -0
- package/src/resolvers/RunAIAgentResolver.ts +16 -4
- package/src/resolvers/SearchKnowledgeResolver.ts +2 -0
- package/src/resolvers/TeamsMeetingsResolver.ts +68 -0
- package/src/resolvers/TelephonyResolver.ts +63 -0
- package/src/resolvers/TestQuerySQLResolver.ts +2 -3
- package/src/resolvers/VonageTelephonyResolver.ts +63 -0
- package/src/rest/MediaStreamHandler.ts +4 -1
- package/src/telephony/RingCentralTelephonyService.ts +342 -0
- package/src/telephony/TeamsMeetingsRouter.ts +124 -0
- package/src/telephony/TeamsMeetingsService.ts +268 -0
- package/src/telephony/TwilioTelephonyRouter.ts +184 -0
- package/src/telephony/TwilioTelephonyService.ts +261 -0
- package/src/telephony/VonageTelephonyRouter.ts +239 -0
- package/src/telephony/VonageTelephonyService.ts +259 -0
- package/src/telephony/calendar-scheduler.ts +176 -0
- package/src/telephony/index.ts +43 -0
- package/src/telephony/media-upgrade-router.ts +62 -0
- package/src/telephony/ringcentral-runtime.ts +22 -0
- package/src/telephony/teams-meetings-runtime.ts +24 -0
- package/src/telephony/teamsAcsMediaRegistry.ts +152 -0
- package/src/telephony/telephony-runtime.ts +22 -0
- package/src/telephony/twilioMediaRegistry.ts +137 -0
- package/src/telephony/vonage-runtime.ts +22 -0
- package/src/telephony/vonageMediaRegistry.ts +200 -0
- package/dist/agents/skip-agent.d.ts +0 -111
- package/dist/agents/skip-agent.d.ts.map +0 -1
- package/dist/agents/skip-agent.js +0 -1487
- package/dist/agents/skip-agent.js.map +0 -1
- package/dist/agents/skip-sdk.d.ts +0 -261
- package/dist/agents/skip-sdk.d.ts.map +0 -1
- package/dist/agents/skip-sdk.js +0 -909
- package/dist/agents/skip-sdk.js.map +0 -1
- package/src/agents/skip-agent.ts +0 -1594
- package/src/agents/skip-sdk.ts +0 -1210
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview GraphQL surface for Teams meeting joins: `StartTeamsMeetingSession` has an agent identity
|
|
3
|
+
* join a Teams meeting by URL and connects the pinned agent over the realtime bridge. Thin — it authorizes
|
|
4
|
+
* the caller, then delegates to the startup-constructed {@link TeamsMeetingsService} (which owns the bridge
|
|
5
|
+
* orchestration + the shared ACS media registry). Roster/call-ended updates arrive via the public
|
|
6
|
+
* `POST /meetings/teams/notifications` Graph webhook, not GraphQL.
|
|
7
|
+
*
|
|
8
|
+
* Mirrors `TelephonyResolver.ts` (the Twilio `PlaceTwilioCall` equivalent).
|
|
9
|
+
*
|
|
10
|
+
* @module @memberjunction/server
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { Resolver, Mutation, Arg, Ctx, ObjectType, Field } from 'type-graphql';
|
|
14
|
+
import { LogError, IMetadataProvider } from '@memberjunction/core';
|
|
15
|
+
import { AppContext } from '../types.js';
|
|
16
|
+
import { ResolverBase } from '../generic/ResolverBase.js';
|
|
17
|
+
import { GetReadWriteProvider } from '../util.js';
|
|
18
|
+
import { GetTeamsMeetingsService } from '../telephony/teams-meetings-runtime.js';
|
|
19
|
+
|
|
20
|
+
/** Result of a Teams meeting join attempt. */
|
|
21
|
+
@ObjectType()
|
|
22
|
+
export class StartTeamsMeetingResult {
|
|
23
|
+
@Field(() => Boolean)
|
|
24
|
+
Success: boolean;
|
|
25
|
+
|
|
26
|
+
@Field(() => String, { nullable: true })
|
|
27
|
+
ErrorMessage?: string;
|
|
28
|
+
|
|
29
|
+
/** The Graph call id the bot joined (the bridge's external connection id), when successful. */
|
|
30
|
+
@Field(() => String)
|
|
31
|
+
CallId: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@Resolver()
|
|
35
|
+
export class TeamsMeetingsResolver extends ResolverBase {
|
|
36
|
+
/**
|
|
37
|
+
* Has the given agent identity join a Teams meeting by URL, connecting the pinned agent over the realtime
|
|
38
|
+
* bridge. Returns the Graph call id.
|
|
39
|
+
*/
|
|
40
|
+
@Mutation(() => StartTeamsMeetingResult)
|
|
41
|
+
async StartTeamsMeetingSession(
|
|
42
|
+
@Arg('agentIdentityId', () => String) agentIdentityId: string,
|
|
43
|
+
@Arg('joinUrl', () => String) joinUrl: string,
|
|
44
|
+
@Ctx() context: AppContext = {} as AppContext,
|
|
45
|
+
): Promise<StartTeamsMeetingResult> {
|
|
46
|
+
const failure = (msg: string): StartTeamsMeetingResult => ({ Success: false, ErrorMessage: msg, CallId: '' });
|
|
47
|
+
try {
|
|
48
|
+
const user = this.GetUserFromPayload(context.userPayload);
|
|
49
|
+
if (!user) {
|
|
50
|
+
return failure('Unable to determine current user.');
|
|
51
|
+
}
|
|
52
|
+
const service = GetTeamsMeetingsService();
|
|
53
|
+
if (!service) {
|
|
54
|
+
return failure('Teams meetings are not configured on this server.');
|
|
55
|
+
}
|
|
56
|
+
const provider = GetReadWriteProvider(context.providers) as unknown as IMetadataProvider;
|
|
57
|
+
const result = await service.JoinMeetingByUrl(agentIdentityId, joinUrl, user, provider);
|
|
58
|
+
if (!result.accepted) {
|
|
59
|
+
return failure(result.reason ?? 'The meeting join was not accepted.');
|
|
60
|
+
}
|
|
61
|
+
return { Success: true, CallId: result.callId ?? '' };
|
|
62
|
+
} catch (error) {
|
|
63
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
64
|
+
LogError(`StartTeamsMeetingSession failed: ${msg}`);
|
|
65
|
+
return failure(msg);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview GraphQL surface for OUTBOUND telephony: `PlaceTwilioCall` rings a real phone from
|
|
3
|
+
* an agent identity and connects the pinned agent. Thin — it authorizes the caller, then delegates to
|
|
4
|
+
* the startup-constructed {@link TwilioTelephonyService} (which owns the bridge orchestration + the
|
|
5
|
+
* shared media registry). Inbound calls arrive via the public `POST /telephony/twilio/voice` webhook,
|
|
6
|
+
* not GraphQL.
|
|
7
|
+
*
|
|
8
|
+
* @module @memberjunction/server
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { Resolver, Mutation, Arg, Ctx, ObjectType, Field } from 'type-graphql';
|
|
12
|
+
import { LogError, IMetadataProvider } from '@memberjunction/core';
|
|
13
|
+
import { AppContext } from '../types.js';
|
|
14
|
+
import { ResolverBase } from '../generic/ResolverBase.js';
|
|
15
|
+
import { GetReadWriteProvider } from '../util.js';
|
|
16
|
+
import { GetTwilioTelephonyService } from '../telephony/telephony-runtime.js';
|
|
17
|
+
|
|
18
|
+
/** Result of an outbound place-call attempt. */
|
|
19
|
+
@ObjectType()
|
|
20
|
+
export class PlaceCallResult {
|
|
21
|
+
@Field(() => Boolean)
|
|
22
|
+
Success: boolean;
|
|
23
|
+
|
|
24
|
+
@Field(() => String, { nullable: true })
|
|
25
|
+
ErrorMessage?: string;
|
|
26
|
+
|
|
27
|
+
/** The placed Twilio Call SID (the bridge's external connection id). */
|
|
28
|
+
@Field(() => String)
|
|
29
|
+
CallSid: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@Resolver()
|
|
33
|
+
export class TelephonyResolver extends ResolverBase {
|
|
34
|
+
/**
|
|
35
|
+
* Places an outbound call from the given agent identity (its phone number is the caller-id) to a
|
|
36
|
+
* destination number, connecting the pinned agent over the realtime bridge. Returns the Call SID.
|
|
37
|
+
*/
|
|
38
|
+
@Mutation(() => PlaceCallResult)
|
|
39
|
+
async PlaceTwilioCall(
|
|
40
|
+
@Arg('agentIdentityId', () => String) agentIdentityId: string,
|
|
41
|
+
@Arg('toNumber', () => String) toNumber: string,
|
|
42
|
+
@Ctx() context: AppContext = {} as AppContext,
|
|
43
|
+
): Promise<PlaceCallResult> {
|
|
44
|
+
const failure = (msg: string): PlaceCallResult => ({ Success: false, ErrorMessage: msg, CallSid: '' });
|
|
45
|
+
try {
|
|
46
|
+
const user = this.GetUserFromPayload(context.userPayload);
|
|
47
|
+
if (!user) {
|
|
48
|
+
return failure('Unable to determine current user.');
|
|
49
|
+
}
|
|
50
|
+
const service = GetTwilioTelephonyService();
|
|
51
|
+
if (!service) {
|
|
52
|
+
return failure('Twilio telephony is not configured on this server.');
|
|
53
|
+
}
|
|
54
|
+
const provider = GetReadWriteProvider(context.providers) as unknown as IMetadataProvider;
|
|
55
|
+
const callSid = await service.PlaceOutboundCall(agentIdentityId, toNumber, user, provider);
|
|
56
|
+
return { Success: true, CallSid: callSid };
|
|
57
|
+
} catch (error) {
|
|
58
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
59
|
+
LogError(`PlaceTwilioCall failed: ${msg}`);
|
|
60
|
+
return failure(msg);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -2,7 +2,6 @@ import { Arg, Ctx, Field, InputType, Int, ObjectType, Query, Resolver } from 'ty
|
|
|
2
2
|
import { GraphQLJSONObject } from 'graphql-type-json';
|
|
3
3
|
import { RunQuery, IRunQueryProvider, LogError, LogStatus, QueryExecutionSpec } from '@memberjunction/core';
|
|
4
4
|
import { AppContext } from '../types.js';
|
|
5
|
-
import { RequireSystemUser } from '../directives/RequireSystemUser.js';
|
|
6
5
|
import { GetReadOnlyProvider } from '../util.js';
|
|
7
6
|
import { ResolverBase } from '../generic/ResolverBase.js';
|
|
8
7
|
|
|
@@ -85,7 +84,7 @@ export class TestQuerySQLResult {
|
|
|
85
84
|
* enabling external systems (e.g., Skip-Brain) to test query SQL before saving to the database.
|
|
86
85
|
*
|
|
87
86
|
* Security:
|
|
88
|
-
* - Requires
|
|
87
|
+
* - Requires `query:test` scope for API key users (no-op for JWT auth)
|
|
89
88
|
* - Uses read-only database connection (no mutation possible)
|
|
90
89
|
* - Enforces MaxRows limit (default 100) to prevent unbounded queries
|
|
91
90
|
*
|
|
@@ -93,7 +92,6 @@ export class TestQuerySQLResult {
|
|
|
93
92
|
*/
|
|
94
93
|
@Resolver()
|
|
95
94
|
export class TestQuerySQLResolver extends ResolverBase {
|
|
96
|
-
@RequireSystemUser()
|
|
97
95
|
@Query(() => TestQuerySQLResult, {
|
|
98
96
|
description: 'Test transient SQL with full composition + Nunjucks template processing without requiring a saved query'
|
|
99
97
|
})
|
|
@@ -102,6 +100,7 @@ export class TestQuerySQLResolver extends ResolverBase {
|
|
|
102
100
|
@Ctx() context: AppContext
|
|
103
101
|
): Promise<TestQuerySQLResult> {
|
|
104
102
|
try {
|
|
103
|
+
await this.CheckAPIKeyScopeAuthorization('query:test', '*', context.userPayload);
|
|
105
104
|
// Use read-only provider for security — no mutation possible
|
|
106
105
|
const provider = GetReadOnlyProvider(context.providers, { allowFallbackToReadWrite: false });
|
|
107
106
|
if (!provider) {
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview GraphQL surface for OUTBOUND Vonage telephony: `PlaceVonageCall` rings a real phone from
|
|
3
|
+
* an agent identity and connects the pinned agent. Thin — it authorizes the caller, then delegates to
|
|
4
|
+
* the startup-constructed {@link VonageTelephonyService} (which owns the bridge orchestration + the
|
|
5
|
+
* shared media registry). Inbound calls arrive via the public `POST /telephony/vonage/answer` webhook,
|
|
6
|
+
* not GraphQL.
|
|
7
|
+
*
|
|
8
|
+
* @module @memberjunction/server
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { Resolver, Mutation, Arg, Ctx, ObjectType, Field } from 'type-graphql';
|
|
12
|
+
import { LogError, IMetadataProvider } from '@memberjunction/core';
|
|
13
|
+
import { AppContext } from '../types.js';
|
|
14
|
+
import { ResolverBase } from '../generic/ResolverBase.js';
|
|
15
|
+
import { GetReadWriteProvider } from '../util.js';
|
|
16
|
+
import { GetVonageTelephonyService } from '../telephony/vonage-runtime.js';
|
|
17
|
+
|
|
18
|
+
/** Result of an outbound place-call attempt. */
|
|
19
|
+
@ObjectType()
|
|
20
|
+
export class PlaceVonageCallResult {
|
|
21
|
+
@Field(() => Boolean)
|
|
22
|
+
Success: boolean;
|
|
23
|
+
|
|
24
|
+
@Field(() => String, { nullable: true })
|
|
25
|
+
ErrorMessage?: string;
|
|
26
|
+
|
|
27
|
+
/** The placed Vonage call UUID (the bridge's external connection id). */
|
|
28
|
+
@Field(() => String)
|
|
29
|
+
CallId: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
@Resolver()
|
|
33
|
+
export class VonageTelephonyResolver extends ResolverBase {
|
|
34
|
+
/**
|
|
35
|
+
* Places an outbound call from the given agent identity (its phone number is the caller-id) to a
|
|
36
|
+
* destination number, connecting the pinned agent over the realtime bridge. Returns the call UUID.
|
|
37
|
+
*/
|
|
38
|
+
@Mutation(() => PlaceVonageCallResult)
|
|
39
|
+
async PlaceVonageCall(
|
|
40
|
+
@Arg('agentIdentityId', () => String) agentIdentityId: string,
|
|
41
|
+
@Arg('toNumber', () => String) toNumber: string,
|
|
42
|
+
@Ctx() context: AppContext = {} as AppContext,
|
|
43
|
+
): Promise<PlaceVonageCallResult> {
|
|
44
|
+
const failure = (msg: string): PlaceVonageCallResult => ({ Success: false, ErrorMessage: msg, CallId: '' });
|
|
45
|
+
try {
|
|
46
|
+
const user = this.GetUserFromPayload(context.userPayload);
|
|
47
|
+
if (!user) {
|
|
48
|
+
return failure('Unable to determine current user.');
|
|
49
|
+
}
|
|
50
|
+
const service = GetVonageTelephonyService();
|
|
51
|
+
if (!service) {
|
|
52
|
+
return failure('Vonage telephony is not configured on this server.');
|
|
53
|
+
}
|
|
54
|
+
const provider = GetReadWriteProvider(context.providers) as unknown as IMetadataProvider;
|
|
55
|
+
const callId = await service.PlaceOutboundCall(agentIdentityId, toNumber, user, provider);
|
|
56
|
+
return { Success: true, CallId: callId };
|
|
57
|
+
} catch (error) {
|
|
58
|
+
const msg = error instanceof Error ? error.message : String(error);
|
|
59
|
+
LogError(`PlaceVonageCall failed: ${msg}`);
|
|
60
|
+
return failure(msg);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -49,7 +49,10 @@ export function createMediaStreamRouter(): Router {
|
|
|
49
49
|
|
|
50
50
|
/** Top-level request handler: verify token → resolve bytes → stream/buffer with Range support. */
|
|
51
51
|
async function handleMediaRequest(req: Request, res: Response): Promise<void> {
|
|
52
|
-
|
|
52
|
+
// Express type defs allow req.params values to be string | string[]; normalize to string
|
|
53
|
+
// so downstream consumers with moduleResolution:"node" type-check cleanly (see SignatureWebhookHandler).
|
|
54
|
+
const rawFileId = req.params.fileId;
|
|
55
|
+
const fileId: string = Array.isArray(rawFileId) ? rawFileId[0] : rawFileId;
|
|
53
56
|
const token = typeof req.query.token === 'string' ? req.query.token : '';
|
|
54
57
|
|
|
55
58
|
const claims = verifyMediaToken(token, fileId);
|
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Orchestrates RingCentral telephony bridge sessions (inbound + outbound) for MJAPI over the
|
|
3
|
+
* **SIP softphone** transport.
|
|
4
|
+
*
|
|
5
|
+
* RingCentral's only product that carries bidirectional call audio is a registered SIP softphone (the
|
|
6
|
+
* `ringcentral-softphone` SDK over SIP/TLS + RTP/SRTP) — its WebSocket "Call Streaming" product is
|
|
7
|
+
* receive-only and cannot inject the agent's voice. So unlike the Twilio/Vonage ingresses (public webhook
|
|
8
|
+
* + media WSS), this service owns a **long-lived SIP registration**: one
|
|
9
|
+
* {@link RingCentralSoftphoneHandle} created + registered at boot, shared across all calls. Inbound calls
|
|
10
|
+
* arrive as SIP INVITEs on that registration (no HTTP webhook); outbound calls place SIP calls through it.
|
|
11
|
+
*
|
|
12
|
+
* It does NOT re-implement bridge logic: it resolves the RingCentral provider + the agent identity, opens a
|
|
13
|
+
* server-side realtime session via the agent layer's `CreateBridgeRealtimeSession` factory, binds a
|
|
14
|
+
* {@link RingCentralSoftphoneCallSdk} (drawing its session from the shared handle) onto the driver, and
|
|
15
|
+
* hands everything to `AIBridgeEngine.StartBridgeSession` — the same seam the Twilio/Vonage services use.
|
|
16
|
+
*
|
|
17
|
+
* @module @memberjunction/server/telephony
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { RunView, UserInfo, IMetadataProvider, Metadata, LogError, LogStatus } from '@memberjunction/core';
|
|
21
|
+
import type { MJAIBridgeAgentIdentityEntity, MJAIBridgeProviderEntity } from '@memberjunction/core-entities';
|
|
22
|
+
import { UserCache } from '@memberjunction/sqlserver-dataprovider';
|
|
23
|
+
import { AIBridgeEngine } from '@memberjunction/ai-bridge-server';
|
|
24
|
+
import { CreateBridgeRealtimeSession } from '@memberjunction/ai-agents';
|
|
25
|
+
import {
|
|
26
|
+
BaseTelephonyBridge,
|
|
27
|
+
type BridgeNativeSdkBinding,
|
|
28
|
+
CARRIER_SAMPLE_RATE_CONFIG_KEY,
|
|
29
|
+
DIRECTION_CONFIG_KEY,
|
|
30
|
+
FROM_NUMBER_CONFIG_KEY,
|
|
31
|
+
INBOUND_CALL_ID_CONFIG_KEY,
|
|
32
|
+
} from '@memberjunction/ai-bridge-base';
|
|
33
|
+
import {
|
|
34
|
+
createRingCentralSoftphone,
|
|
35
|
+
RingCentralSoftphoneCallSdk,
|
|
36
|
+
type RingCentralSoftphoneConfig,
|
|
37
|
+
type RingCentralSoftphoneHandle,
|
|
38
|
+
type InboundInviteInfo,
|
|
39
|
+
} from '@memberjunction/ai-bridge-ringcentral';
|
|
40
|
+
import type { RingCentralTelephonyConfig } from '../config.js';
|
|
41
|
+
import { SessionManager } from '../agentSessions/SessionManager.js';
|
|
42
|
+
|
|
43
|
+
const RINGCENTRAL_PROVIDER_DRIVER = 'RingCentralBridge';
|
|
44
|
+
const AGENT_IDENTITY_ENTITY = 'MJ: AI Bridge Agent Identities';
|
|
45
|
+
const PHONE_IDENTITY_TYPE = 'PhoneNumber';
|
|
46
|
+
|
|
47
|
+
/** PCM16 carrier rate (Hz) per softphone codec — the rate the bridge resamples to/from the model rate. */
|
|
48
|
+
const CODEC_CARRIER_RATE: Record<NonNullable<RingCentralSoftphoneConfig['codec']>, number> = {
|
|
49
|
+
'OPUS/16000': 16000,
|
|
50
|
+
'OPUS/48000/2': 48000,
|
|
51
|
+
'PCMU/8000': 8000,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** A resolved inbound call's identifying fields (mapped from a RingCentral SIP INVITE). */
|
|
55
|
+
export interface InboundCallInput {
|
|
56
|
+
/** The SIP `Call-ID` (the per-call id the handle parked the INVITE under + the bridge's inbound id). */
|
|
57
|
+
sessionId: string;
|
|
58
|
+
/** The caller's number (the INVITE's `From`). */
|
|
59
|
+
from: string;
|
|
60
|
+
/** The dialed DID (the INVITE's `To`) — resolved to an agent identity. */
|
|
61
|
+
to: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Result of starting an inbound bridge session. */
|
|
65
|
+
export interface InboundCallResult {
|
|
66
|
+
/** Whether a pinned agent was resolved + a bridge session started. */
|
|
67
|
+
accepted: boolean;
|
|
68
|
+
/** Why it was rejected (no agent identity for the DID, provider missing, etc.). */
|
|
69
|
+
reason?: string;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** Injectable collaborators (production defaults wired in the constructor; fakes in tests). */
|
|
73
|
+
export interface RingCentralTelephonyServiceDeps {
|
|
74
|
+
engine?: Pick<AIBridgeEngine, 'ProviderByName' | 'ProviderByDriverClass' | 'StartBridgeSession' | 'Config'>;
|
|
75
|
+
sessionFactory?: typeof CreateBridgeRealtimeSession;
|
|
76
|
+
sessionManager?: Pick<SessionManager, 'CreateSession'>;
|
|
77
|
+
/** Test seam: a factory that builds the softphone handle (inject a fake to avoid the real SIP SDK). */
|
|
78
|
+
createHandle?: typeof createRingCentralSoftphone;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Starts RingCentral bridge sessions over a shared SIP-softphone registration. One instance per server,
|
|
83
|
+
* constructed at boot and held by the runtime holder so the outbound `PlaceRingCentralCall` resolver and the
|
|
84
|
+
* inbound INVITE coordinator share the same registration.
|
|
85
|
+
*/
|
|
86
|
+
export class RingCentralTelephonyService {
|
|
87
|
+
private readonly engine: Pick<AIBridgeEngine, 'ProviderByName' | 'ProviderByDriverClass' | 'StartBridgeSession' | 'Config'>;
|
|
88
|
+
private readonly sessionFactory: typeof CreateBridgeRealtimeSession;
|
|
89
|
+
private readonly sessionManager: Pick<SessionManager, 'CreateSession'>;
|
|
90
|
+
private readonly createHandle: typeof createRingCentralSoftphone;
|
|
91
|
+
|
|
92
|
+
/** The shared SIP registration — created + registered by {@link start}; null until then. */
|
|
93
|
+
private handle: RingCentralSoftphoneHandle | null = null;
|
|
94
|
+
|
|
95
|
+
/** The carrier PCM16 rate for the negotiated codec (set in {@link start}). */
|
|
96
|
+
private carrierSampleRate: number = CODEC_CARRIER_RATE['OPUS/16000'];
|
|
97
|
+
|
|
98
|
+
constructor(
|
|
99
|
+
private readonly config: RingCentralTelephonyConfig,
|
|
100
|
+
deps: RingCentralTelephonyServiceDeps = {},
|
|
101
|
+
) {
|
|
102
|
+
this.engine = deps.engine ?? AIBridgeEngine.Instance;
|
|
103
|
+
this.sessionFactory = deps.sessionFactory ?? CreateBridgeRealtimeSession;
|
|
104
|
+
this.sessionManager = deps.sessionManager ?? new SessionManager();
|
|
105
|
+
this.createHandle = deps.createHandle ?? createRingCentralSoftphone;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Creates + registers the shared SIP softphone and wires inbound INVITE handling. Called once at boot
|
|
110
|
+
* (fire-and-forget so SIP registration never blocks server startup); logs success/failure. Inbound calls
|
|
111
|
+
* only flow once this resolves.
|
|
112
|
+
*/
|
|
113
|
+
public async start(): Promise<void> {
|
|
114
|
+
try {
|
|
115
|
+
this.carrierSampleRate = CODEC_CARRIER_RATE[this.config.codec ?? 'OPUS/16000'];
|
|
116
|
+
this.handle = await this.createHandle(this.toSoftphoneConfig());
|
|
117
|
+
this.handle.onInvite((info) => void this.onInboundInvite(info));
|
|
118
|
+
await this.handle.register();
|
|
119
|
+
LogStatus('[Telephony][RingCentral] softphone telephony started (inbound + outbound ready).');
|
|
120
|
+
} catch (e) {
|
|
121
|
+
this.handle = null;
|
|
122
|
+
LogError(`[Telephony][RingCentral] softphone start failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** Best-effort teardown of the SIP registration (server shutdown). */
|
|
127
|
+
public dispose(): void {
|
|
128
|
+
this.handle?.dispose();
|
|
129
|
+
this.handle = null;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Resolves the dialed DID to a pinned agent and starts an INBOUND bridge session. The bound
|
|
134
|
+
* {@link RingCentralSoftphoneCallSdk} answers the parked INVITE for `sessionId`. Returns
|
|
135
|
+
* `{ accepted:false }` (never throws) when no agent identity matches the DID, so the coordinator can
|
|
136
|
+
* decline the INVITE cleanly.
|
|
137
|
+
*/
|
|
138
|
+
public async HandleInboundCall(input: InboundCallInput, contextUser: UserInfo, provider: IMetadataProvider): Promise<InboundCallResult> {
|
|
139
|
+
try {
|
|
140
|
+
const identity = await this.resolveAgentIdentityByPhone(input.to, contextUser);
|
|
141
|
+
if (!identity) {
|
|
142
|
+
return { accepted: false, reason: `No active agent identity for dialed number '${input.to}'.` };
|
|
143
|
+
}
|
|
144
|
+
await this.startBridge({
|
|
145
|
+
agentID: identity.AgentID,
|
|
146
|
+
direction: 'Inbound',
|
|
147
|
+
address: input.from,
|
|
148
|
+
inboundCallId: input.sessionId,
|
|
149
|
+
contextUser,
|
|
150
|
+
provider,
|
|
151
|
+
});
|
|
152
|
+
return { accepted: true };
|
|
153
|
+
} catch (e) {
|
|
154
|
+
LogError(`[Telephony][RingCentral] inbound call ${input.sessionId} failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
155
|
+
return { accepted: false, reason: 'Internal error starting the agent.' };
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Places an OUTBOUND call from a given agent identity to a destination number. The bound
|
|
161
|
+
* {@link RingCentralSoftphoneCallSdk} places the SIP call through the shared registration; the returned
|
|
162
|
+
* SIP `Call-ID` is the bridge's external connection id.
|
|
163
|
+
*
|
|
164
|
+
* @returns The placed call's SIP `Call-ID`.
|
|
165
|
+
*/
|
|
166
|
+
public async PlaceOutboundCall(agentIdentityId: string, toNumber: string, contextUser: UserInfo, provider: IMetadataProvider): Promise<string> {
|
|
167
|
+
const identity = await this.loadAgentIdentity(agentIdentityId, contextUser, provider);
|
|
168
|
+
if (!identity) {
|
|
169
|
+
throw new Error(`Agent identity '${agentIdentityId}' not found or inactive.`);
|
|
170
|
+
}
|
|
171
|
+
const session = await this.startBridge({
|
|
172
|
+
agentID: identity.AgentID,
|
|
173
|
+
direction: 'Outbound',
|
|
174
|
+
address: toNumber,
|
|
175
|
+
fromNumber: identity.IdentityValue,
|
|
176
|
+
contextUser,
|
|
177
|
+
provider,
|
|
178
|
+
});
|
|
179
|
+
return session.RoomKey ?? '';
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
// ── internals ────────────────────────────────────────────────────────────────
|
|
183
|
+
|
|
184
|
+
/** Inbound INVITE coordinator: resolve the server principal, start a bridge, decline if no agent matched. */
|
|
185
|
+
private async onInboundInvite(info: InboundInviteInfo): Promise<void> {
|
|
186
|
+
const context = this.resolveServerContext();
|
|
187
|
+
if (!context) {
|
|
188
|
+
LogError('[Telephony][RingCentral] no server context user available; declining inbound call.');
|
|
189
|
+
await this.handle?.declineCall(info.callId);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const result = await this.HandleInboundCall({ sessionId: info.callId, from: info.from, to: info.to }, context.user, context.provider);
|
|
193
|
+
if (!result.accepted) {
|
|
194
|
+
LogStatus(`[Telephony][RingCentral] inbound ${info.callId} not accepted: ${result.reason ?? 'unknown'}; declining.`);
|
|
195
|
+
await this.handle?.declineCall(info.callId);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** Shared inbound/outbound bridge-start: resolve provider, open the realtime session, bind the SDK, start. */
|
|
200
|
+
private async startBridge(args: {
|
|
201
|
+
agentID: string;
|
|
202
|
+
direction: 'Inbound' | 'Outbound';
|
|
203
|
+
address: string;
|
|
204
|
+
inboundCallId?: string;
|
|
205
|
+
fromNumber?: string;
|
|
206
|
+
contextUser: UserInfo;
|
|
207
|
+
provider: IMetadataProvider;
|
|
208
|
+
}): Promise<{ RoomKey?: string }> {
|
|
209
|
+
await this.engine.Config(false, args.contextUser, args.provider);
|
|
210
|
+
const ringCentralProvider = this.resolveProvider();
|
|
211
|
+
|
|
212
|
+
const agentSession = await this.sessionManager.CreateSession({ agentID: args.agentID, userID: args.contextUser.ID }, args.contextUser, args.provider);
|
|
213
|
+
const realtimeSession = await this.sessionFactory({
|
|
214
|
+
AgentID: args.agentID,
|
|
215
|
+
TargetAgentID: args.agentID,
|
|
216
|
+
ContextUser: args.contextUser,
|
|
217
|
+
MetadataProvider: args.provider,
|
|
218
|
+
AgentSessionID: agentSession.ID,
|
|
219
|
+
RoomName: args.address,
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
const active = await this.engine.StartBridgeSession({
|
|
223
|
+
AgentSessionID: agentSession.ID,
|
|
224
|
+
AgentID: args.agentID,
|
|
225
|
+
TargetAgentID: args.agentID,
|
|
226
|
+
Provider: ringCentralProvider,
|
|
227
|
+
RealtimeSession: realtimeSession,
|
|
228
|
+
Address: args.address,
|
|
229
|
+
Direction: args.direction,
|
|
230
|
+
Configuration: this.buildSessionConfiguration(args.direction, args.fromNumber, args.inboundCallId),
|
|
231
|
+
BindSdk: this.buildBindSdk(),
|
|
232
|
+
ContextUser: args.contextUser,
|
|
233
|
+
MetadataProvider: args.provider,
|
|
234
|
+
});
|
|
235
|
+
return { RoomKey: active.RoomKey };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** Resolves the seeded RingCentral provider row (by driver class, falling back to display name). */
|
|
239
|
+
private resolveProvider(): MJAIBridgeProviderEntity {
|
|
240
|
+
const provider = this.engine.ProviderByDriverClass(RINGCENTRAL_PROVIDER_DRIVER) ?? this.engine.ProviderByName('RingCentral');
|
|
241
|
+
if (!provider) {
|
|
242
|
+
throw new Error(`No active 'MJ: AI Bridge Providers' row for the RingCentral bridge (DriverClass '${RINGCENTRAL_PROVIDER_DRIVER}').`);
|
|
243
|
+
}
|
|
244
|
+
return provider;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Builds the per-session SDK binding that wires a {@link RingCentralSoftphoneCallSdk} (drawing its
|
|
249
|
+
* session from the shared SIP registration handle) onto the telephony driver — overriding the package's
|
|
250
|
+
* default unbound SDK. Reads the handle lazily at call time so a call placed during the brief boot window
|
|
251
|
+
* before registration fails loudly rather than binding a null handle.
|
|
252
|
+
*/
|
|
253
|
+
public buildBindSdk(): BridgeNativeSdkBinding {
|
|
254
|
+
return (driver) => {
|
|
255
|
+
const telephony = driver as BaseTelephonyBridge;
|
|
256
|
+
telephony.SetSdkFactory(() => new RingCentralSoftphoneCallSdk(this.requireHandle()));
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** Returns the live registration handle, or throws if the softphone hasn't registered yet. */
|
|
261
|
+
private requireHandle(): RingCentralSoftphoneHandle {
|
|
262
|
+
if (!this.handle) {
|
|
263
|
+
throw new Error('[Telephony][RingCentral] softphone not registered yet (start() pending or failed).');
|
|
264
|
+
}
|
|
265
|
+
return this.handle;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** Assembles the per-session bridge configuration (direction / from-number / inbound-call-id / carrier rate). */
|
|
269
|
+
private buildSessionConfiguration(direction: 'Inbound' | 'Outbound', fromNumber?: string, inboundCallId?: string): Record<string, unknown> {
|
|
270
|
+
// The engine does NOT forward the top-level Direction into the driver's Configuration; set it here so
|
|
271
|
+
// an inbound call answers instead of wrongly taking the outbound-dial path. The carrier rate tells the
|
|
272
|
+
// base bridge the SIP leg is wideband (16 kHz for OPUS/16000), not the 8 kHz G.711 default.
|
|
273
|
+
const config: Record<string, unknown> = {
|
|
274
|
+
[DIRECTION_CONFIG_KEY]: direction,
|
|
275
|
+
[CARRIER_SAMPLE_RATE_CONFIG_KEY]: this.carrierSampleRate,
|
|
276
|
+
};
|
|
277
|
+
if (fromNumber) {
|
|
278
|
+
config[FROM_NUMBER_CONFIG_KEY] = fromNumber;
|
|
279
|
+
}
|
|
280
|
+
if (inboundCallId) {
|
|
281
|
+
config[INBOUND_CALL_ID_CONFIG_KEY] = inboundCallId;
|
|
282
|
+
}
|
|
283
|
+
return config;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
/** Maps the server config block to the softphone SDK's SIP-device config (credentials resolved upstream). */
|
|
287
|
+
private toSoftphoneConfig(): RingCentralSoftphoneConfig {
|
|
288
|
+
return {
|
|
289
|
+
domain: this.config.sipDomain,
|
|
290
|
+
outboundProxy: this.config.sipOutboundProxy,
|
|
291
|
+
username: this.config.sipUsername,
|
|
292
|
+
password: this.config.sipPassword,
|
|
293
|
+
authorizationId: this.config.sipAuthorizationId,
|
|
294
|
+
codec: this.config.codec,
|
|
295
|
+
ignoreTlsCertErrors: this.config.ignoreTlsCertErrors,
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/** Resolves the server-side principal + provider for an inbound call (no MJ JWT on a SIP INVITE). */
|
|
300
|
+
private resolveServerContext(): { user: UserInfo; provider: IMetadataProvider } | null {
|
|
301
|
+
const user = UserCache.Instance.GetSystemUser() ?? UserCache.Users.find((u) => u.IsActive && u.Type?.trim().toLowerCase() === 'owner') ?? null;
|
|
302
|
+
const provider = Metadata.Provider as unknown as IMetadataProvider | undefined; // global-provider-ok: inbound SIP INVITE has no MJ JWT / per-request provider; the server's single default provider is correct
|
|
303
|
+
if (!user || !provider) {
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
306
|
+
return { user, provider };
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/** Finds the active agent identity whose phone number matches the dialed DID. */
|
|
310
|
+
private async resolveAgentIdentityByPhone(dialedNumber: string, contextUser: UserInfo): Promise<MJAIBridgeAgentIdentityEntity | null> {
|
|
311
|
+
const normalized = (dialedNumber ?? '').trim();
|
|
312
|
+
if (!normalized) {
|
|
313
|
+
return null;
|
|
314
|
+
}
|
|
315
|
+
const rv = new RunView();
|
|
316
|
+
const result = await rv.RunView<MJAIBridgeAgentIdentityEntity>(
|
|
317
|
+
{
|
|
318
|
+
EntityName: AGENT_IDENTITY_ENTITY,
|
|
319
|
+
ExtraFilter: `IdentityType='${PHONE_IDENTITY_TYPE}' AND IdentityValue='${normalized.replace(/'/g, "''")}' AND IsActive=1`,
|
|
320
|
+
MaxRows: 1,
|
|
321
|
+
ResultType: 'entity_object',
|
|
322
|
+
},
|
|
323
|
+
contextUser,
|
|
324
|
+
);
|
|
325
|
+
if (!result.Success) {
|
|
326
|
+
LogError(`[Telephony][RingCentral] agent-identity lookup failed: ${result.ErrorMessage}`);
|
|
327
|
+
return null;
|
|
328
|
+
}
|
|
329
|
+
return result.Results?.[0] ?? null;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/** Loads a specific agent identity by id (used by outbound PlaceCall), requiring it be active. */
|
|
333
|
+
private async loadAgentIdentity(agentIdentityId: string, contextUser: UserInfo, provider: IMetadataProvider): Promise<MJAIBridgeAgentIdentityEntity | null> {
|
|
334
|
+
// Use the request-scoped provider (multi-provider safe), not the global Metadata.
|
|
335
|
+
const entity = await provider.GetEntityObject<MJAIBridgeAgentIdentityEntity>(AGENT_IDENTITY_ENTITY, contextUser);
|
|
336
|
+
const loaded = await entity.Load(agentIdentityId);
|
|
337
|
+
if (!loaded || !entity.IsActive) {
|
|
338
|
+
return null;
|
|
339
|
+
}
|
|
340
|
+
return entity;
|
|
341
|
+
}
|
|
342
|
+
}
|