Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
import { Injectable } from '@nestjs/common';
import { EngineRegistry } from '../../engine/engine-registry.service';
import { CallLinkType, IWhatsAppEngine } from '../../engine/interfaces/whatsapp-engine.interface';
/**
* Owns engine access for call operations. Controllers depend on this service instead of
* reaching for the raw `IWhatsAppEngine` via `sessionService.getEngine`, so the "session not
* started" guard lives in one place (mirrors GroupService).
*/
@Injectable()
export class CallService {
constructor(private readonly engines: EngineRegistry) {}
private getEngine(sessionId: string): IWhatsAppEngine {
// EngineRegistry.require()'s default is this exact 400 "Session is not started".
return this.engines.require(sessionId);
}
/**
* Reject a currently-ringing incoming call. An unknown or no-longer-ringing callId surfaces
* as 404 via the Baileys adapter's CallNotFoundError; the whatsapp-web.js adapter throws
* EngineNotSupportedError, which maps to 501, so no special-casing here.
*/
rejectCall(sessionId: string, callId: string): Promise<void> {
return this.getEngine(sessionId).rejectCall(callId);
}
/**
* Generate a shareable call link. A WhatsApp-side refusal (no link generated) surfaces as 403 via
* the adapter's EngineRefusedError rather than as a success carrying an empty string.
*/
createCallLink(sessionId: string, type: CallLinkType, startTime: number): Promise<string> {
return this.getEngine(sessionId).createCallLink(type, startTime);
}
}