Skip to content

On Call Invite

Fired when an inbound call invite is received. Use this event to present incoming call UI and decide whether to answer or reject.

Event Registration

fun setCallInviteListener(
  fn: (callId: String, from: String, channelType: VoiceChannelType) -> Unit
): Subscription

Usage Example


 // Answer Call
 client.setCallInviteListener {inviteId, from, channelType ->
     println("Incoming Call from $from by channel $channelType")
     client.answer(inviteId) {
         it?.let {err ->
             // Handle Error in answering call
             println("Error in answering call: $err")
         }
     }
 }

 // Or reject the call:
 // client.setCallInviteListener { inviteId, from, channelType ->
 //     client.reject(inviteId) {
 //         it?.let {err ->
 //             println("Error in rejecting call: $err")
 //         }
 //     }
 // }

 // Invite Cancelled
 client.setCallInviteCancelListener { inviteId, reason ->
         when (reason) {
             VoiceInviteCancelReason.RemoteCancel -> println("Call Invite for call $inviteId was cancelled by the caller")
             VoiceInviteCancelReason.AnsweredElsewhere -> println("Call Invite for call $inviteId was answered on another device")
             VoiceInviteCancelReason.RejectedElsewhere -> println("Call Invite for call $inviteId was rejected on another device")
             VoiceInviteCancelReason.RemoteTimeout -> println("Call Invite for call $inviteId timed out")
         }
     }

Event Data

ParameterTypeDescription
callIdstringUnique call invite/call identifier
fromstringCaller identity
channelTypeVoiceChannelTypeInbound channel type — see below

VoiceChannelType

Android / Web valueiOS valueDescription
appVGVoiceChannelTypeAppIn-app call
phoneVGVoiceChannelTypePhonePSTN phone call
sipVGVoiceChannelTypeSipSIP call
websocketVGVoiceChannelTypeWebsocketWebSocket call

Notes

  • This event is emitted for new inbound invites only
  • Keep a strong reference to invite/call state in your application layer
  • Invites may be canceled or timeout before user action

Context / Custom Data

The onCallInvite event does not include the context object that was passed to serverCall() by the caller. The invite only provides the callId, from (caller identity), and channelType.

If you need to pass custom data from caller to callee, include it in your NCCO answer webhook response (e.g. as custom headers) or retrieve it from your backend after the call is connected using the callId.

  • answer - Accept the inbound invite
  • reject - Decline the inbound invite

Built with VitePress.