I want to create a tool where callee say can you h...
# ask-ai
b
I want to create a tool where callee say can you hangup the call. Also how can i call webhook once hangup the call based on above?
t
Thanks for reaching out, Dhruvil. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To create a tool where the callee can say "can you hang up the call" and then programmatically hang up the call in LiveKit, you would need to integrate a speech-to-text or natural language processing service to detect that phrase, as LiveKit does not provide built-in voice phrase detection. Once the phrase is detected, you can use LiveKit's API to remove the participant from the room programmatically, effectively hanging up the call. Here's an example of a callable function that can perform the hang-up by removing the participant:
Copy code
class CallActions(llm.FunctionContext):
    async def hangup(self):
        try:
            await self.api.room.remove_participant(api.RoomParticipantIdentity(
                room=self.room.name,
                identity=self.participant.identity,
            ))
        except Exception as e:
            <http://logger.info|logger.info>(f"received error while ending call: {e}")

    @llm.ai_callable()
    async def end_call(self):
        <http://logger.info|logger.info>(f"ending the call for {self.participant.identity}")
        await self.hangup()
For calling a webhook once the call is hung up, LiveKit does not have a specific event webhook for call hang-up, but you can monitor the
sip.callStatus
attribute of participants. When it changes to "hangup", you can trigger your webhook call. Example of monitoring the call status and triggering a webhook:
Copy code
import requests

participant = ...  # obtain participant instance
if participant.attributes.get("sip.callStatus") == "hangup":
    <http://requests.post|requests.post>("<https://your-webhook-url.com/call-ended>", data={"caller": participant.identity})
This approach allows you to integrate webhook notification for call hang-up events. Note the limitation that LiveKit needs external services for phrase detection and you must implement monitoring and webhook calling logic yourself. Sources: Making calls using SIP | LiveKit Docs | Making calls using SIP | LiveKit Docs | Agents telephony integration | LiveKit Docs