{"version":3,"sources":["../src/ConnectorClient.ts"],"sourcesContent":["// SPDX-FileCopyrightText: 2025 LiveKit, Inc.\n//\n// SPDX-License-Identifier: Apache-2.0\nimport type {\n  ConnectTwilioCallRequest_TwilioCallDirection,\n  RoomAgentDispatch,\n  SessionDescription,\n} from '@livekit/protocol';\nimport {\n  AcceptWhatsAppCallRequest,\n  AcceptWhatsAppCallResponse,\n  ConnectTwilioCallRequest,\n  ConnectTwilioCallResponse,\n  ConnectWhatsAppCallRequest,\n  ConnectWhatsAppCallResponse,\n  DialWhatsAppCallRequest,\n  DialWhatsAppCallResponse,\n  DisconnectWhatsAppCallRequest,\n  DisconnectWhatsAppCallResponse,\n} from '@livekit/protocol';\nimport type { ClientOptions } from './ClientOptions.js';\nimport { ServiceBase } from './ServiceBase.js';\nimport { type Rpc, TwirpRpc, livekitPackage } from './TwirpRPC.js';\n\nconst svc = 'Connector';\n\n// WhatsApp types\nexport interface DialWhatsAppCallOptions {\n  /** Required - The identifier of the WhatsApp phone number that is initiating the call */\n  whatsappPhoneNumberId: string;\n  /** Required - The number of the user that is supposed to receive the call */\n  whatsappToPhoneNumber: string;\n  /** Required - The API key of the business that is initiating the call */\n  whatsappApiKey: string;\n  /** Required - WhatsApp Cloud API version, eg: 23.0, 24.0, etc. */\n  whatsappCloudApiVersion: string;\n  /** Optional - An arbitrary string you can pass in that is useful for tracking and logging purposes */\n  whatsappBizOpaqueCallbackData?: string;\n  /** Optional - What LiveKit room should this participant be connected to */\n  roomName?: string;\n  /** Optional - Agents to dispatch the call to */\n  agents?: RoomAgentDispatch[];\n  /** Optional - Identity of the participant in LiveKit room */\n  participantIdentity?: string;\n  /** Optional - Name of the participant in LiveKit room */\n  participantName?: string;\n  /** Optional - User-defined metadata. Will be attached to a created Participant in the room. */\n  participantMetadata?: string;\n  /** Optional - User-defined attributes. Will be attached to a created Participant in the room. */\n  participantAttributes?: { [key: string]: string };\n  /** Optional - Country where the call terminates as ISO 3166-1 alpha-2 */\n  destinationCountry?: string;\n}\n\nexport interface AcceptWhatsAppCallOptions {\n  /** Required - The identifier of the WhatsApp phone number that is connecting the call */\n  whatsappPhoneNumberId: string;\n  /** Required - The API key of the business that is connecting the call */\n  whatsappApiKey: string;\n  /** Required - WhatsApp Cloud API version, eg: 23.0, 24.0, etc. */\n  whatsappCloudApiVersion: string;\n  /** Required - Call ID sent by Meta */\n  whatsappCallId: string;\n  /** Optional - An arbitrary string you can pass in that is useful for tracking and logging purposes */\n  whatsappBizOpaqueCallbackData?: string;\n  /** Required - The call accept webhook comes with SDP from Meta */\n  sdp: SessionDescription;\n  /** Optional - What LiveKit room should this participant be connected to */\n  roomName?: string;\n  /** Optional - Agents to dispatch the call to */\n  agents?: RoomAgentDispatch[];\n  /** Optional - Identity of the participant in LiveKit room */\n  participantIdentity?: string;\n  /** Optional - Name of the participant in LiveKit room */\n  participantName?: string;\n  /** Optional - User-defined metadata. Will be attached to a created Participant in the room. */\n  participantMetadata?: string;\n  /** Optional - User-defined attributes. Will be attached to a created Participant in the room. */\n  participantAttributes?: { [key: string]: string };\n  /** Optional - Country where the call terminates as ISO 3166-1 alpha-2 */\n  destinationCountry?: string;\n}\n\n// Twilio types\nexport interface ConnectTwilioCallOptions {\n  /** The direction of the call */\n  twilioCallDirection: ConnectTwilioCallRequest_TwilioCallDirection;\n  /** What LiveKit room should this call be connected to */\n  roomName: string;\n  /** Optional agents to dispatch the call to */\n  agents?: RoomAgentDispatch[];\n  /** Optional identity of the participant in LiveKit room */\n  participantIdentity?: string;\n  /** Optional name of the participant in LiveKit room */\n  participantName?: string;\n  /** Optional user-defined metadata. Will be attached to a created Participant in the room. */\n  participantMetadata?: string;\n  /** Optional user-defined attributes. Will be attached to a created Participant in the room. */\n  participantAttributes?: { [key: string]: string };\n  /** Country where the call terminates as ISO 3166-1 alpha-2 */\n  destinationCountry?: string;\n}\n\n/**\n * Client to access Connector APIs for WhatsApp and Twilio integrations\n */\nexport class ConnectorClient extends ServiceBase {\n  private readonly rpc: Rpc;\n\n  /**\n   * @param host - hostname including protocol. i.e. 'https://<project>.livekit.cloud'\n   * @param apiKey - API Key, can be set in env var LIVEKIT_API_KEY\n   * @param secret - API Secret, can be set in env var LIVEKIT_API_SECRET\n   * @param options - client options\n   */\n  constructor(host: string, apiKey?: string, secret?: string, options?: ClientOptions) {\n    super(apiKey, secret);\n    const rpcOptions = options?.requestTimeout\n      ? { requestTimeout: options.requestTimeout }\n      : undefined;\n    this.rpc = new TwirpRpc(host, livekitPackage, rpcOptions);\n  }\n\n  /**\n   * Initiate an outbound WhatsApp call\n   *\n   * @param options - WhatsApp call options\n   * @returns Promise containing the WhatsApp call ID and room name\n   */\n  async dialWhatsAppCall(options: DialWhatsAppCallOptions): Promise<DialWhatsAppCallResponse> {\n    const whatsappBizOpaqueCallbackData = options.whatsappBizOpaqueCallbackData || '';\n    const roomName = options.roomName || '';\n    const participantIdentity = options.participantIdentity || '';\n    const participantName = options.participantName || '';\n    const participantMetadata = options.participantMetadata || '';\n    const destinationCountry = options.destinationCountry || '';\n\n    const req = new DialWhatsAppCallRequest({\n      whatsappPhoneNumberId: options.whatsappPhoneNumberId,\n      whatsappToPhoneNumber: options.whatsappToPhoneNumber,\n      whatsappApiKey: options.whatsappApiKey,\n      whatsappCloudApiVersion: options.whatsappCloudApiVersion,\n      whatsappBizOpaqueCallbackData,\n      roomName,\n      agents: options.agents,\n      participantIdentity,\n      participantName,\n      participantMetadata,\n      participantAttributes: options.participantAttributes,\n      destinationCountry,\n    }).toJson();\n\n    const data = await this.rpc.request(\n      svc,\n      'DialWhatsAppCall',\n      req,\n      await this.authHeader({ roomCreate: true }),\n    );\n    return DialWhatsAppCallResponse.fromJson(data, { ignoreUnknownFields: true });\n  }\n\n  /**\n   * Accept an inbound WhatsApp call\n   *\n   * @param options - WhatsApp call accept options\n   * @returns Promise containing the room name\n   */\n  async acceptWhatsAppCall(\n    options: AcceptWhatsAppCallOptions,\n  ): Promise<AcceptWhatsAppCallResponse> {\n    const whatsappBizOpaqueCallbackData = options.whatsappBizOpaqueCallbackData || '';\n    const roomName = options.roomName || '';\n    const participantIdentity = options.participantIdentity || '';\n    const participantName = options.participantName || '';\n    const participantMetadata = options.participantMetadata || '';\n    const destinationCountry = options.destinationCountry || '';\n\n    const req = new AcceptWhatsAppCallRequest({\n      whatsappPhoneNumberId: options.whatsappPhoneNumberId,\n      whatsappApiKey: options.whatsappApiKey,\n      whatsappCloudApiVersion: options.whatsappCloudApiVersion,\n      whatsappCallId: options.whatsappCallId,\n      whatsappBizOpaqueCallbackData,\n      sdp: options.sdp,\n      roomName,\n      agents: options.agents,\n      participantIdentity,\n      participantName,\n      participantMetadata,\n      participantAttributes: options.participantAttributes,\n      destinationCountry,\n    }).toJson();\n\n    const data = await this.rpc.request(\n      svc,\n      'AcceptWhatsAppCall',\n      req,\n      await this.authHeader({ roomCreate: true }),\n    );\n    return AcceptWhatsAppCallResponse.fromJson(data, { ignoreUnknownFields: true });\n  }\n\n  /**\n   * Connect an established WhatsApp call (used for business-initiated calls)\n   *\n   * @param whatsappCallId - Call ID sent by Meta\n   * @param sdp - Session description from Meta\n   */\n  async connectWhatsAppCall(\n    whatsappCallId: string,\n    sdp: SessionDescription,\n  ): Promise<ConnectWhatsAppCallResponse> {\n    const req = new ConnectWhatsAppCallRequest({\n      whatsappCallId,\n      sdp,\n    }).toJson();\n\n    const data = await this.rpc.request(\n      svc,\n      'ConnectWhatsAppCall',\n      req,\n      await this.authHeader({ roomCreate: true }),\n    );\n    return ConnectWhatsAppCallResponse.fromJson(data, { ignoreUnknownFields: true });\n  }\n\n  /**\n   * Disconnect an active WhatsApp call\n   *\n   * @param whatsappCallId - Call ID sent by Meta\n   * @param whatsappApiKey - The API key of the business that is disconnecting the call\n   */\n  async disconnectWhatsAppCall(\n    whatsappCallId: string,\n    whatsappApiKey: string,\n  ): Promise<DisconnectWhatsAppCallResponse> {\n    const req = new DisconnectWhatsAppCallRequest({\n      whatsappCallId,\n      whatsappApiKey,\n    }).toJson();\n\n    const data = await this.rpc.request(\n      svc,\n      'DisconnectWhatsAppCall',\n      req,\n      await this.authHeader({ roomCreate: true }),\n    );\n    return DisconnectWhatsAppCallResponse.fromJson(data, { ignoreUnknownFields: true });\n  }\n\n  /**\n   * Connect a Twilio call to a LiveKit room\n   *\n   * @param options - Twilio call connection options\n   * @returns Promise containing the WebSocket connect URL for Twilio media stream\n   */\n  async connectTwilioCall(options: ConnectTwilioCallOptions): Promise<ConnectTwilioCallResponse> {\n    const participantIdentity = options.participantIdentity || '';\n    const participantName = options.participantName || '';\n    const participantMetadata = options.participantMetadata || '';\n    const destinationCountry = options.destinationCountry || '';\n\n    const req = new ConnectTwilioCallRequest({\n      twilioCallDirection: options.twilioCallDirection,\n      roomName: options.roomName,\n      agents: options.agents,\n      participantIdentity,\n      participantName,\n      participantMetadata,\n      participantAttributes: options.participantAttributes,\n      destinationCountry,\n    }).toJson();\n\n    const data = await this.rpc.request(\n      svc,\n      'ConnectTwilioCall',\n      req,\n      await this.authHeader({ roomCreate: true }),\n    );\n    return ConnectTwilioCallResponse.fromJson(data, { ignoreUnknownFields: true });\n  }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,sBAWO;AAEP,yBAA4B;AAC5B,sBAAmD;AAEnD,MAAM,MAAM;AAkFL,MAAM,wBAAwB,+BAAY;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAS/C,YAAY,MAAc,QAAiB,QAAiB,SAAyB;AACnF,UAAM,QAAQ,MAAM;AACpB,UAAM,cAAa,mCAAS,kBACxB,EAAE,gBAAgB,QAAQ,eAAe,IACzC;AACJ,SAAK,MAAM,IAAI,yBAAS,MAAM,gCAAgB,UAAU;AAAA,EAC1D;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,iBAAiB,SAAqE;AAC1F,UAAM,gCAAgC,QAAQ,iCAAiC;AAC/E,UAAM,WAAW,QAAQ,YAAY;AACrC,UAAM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