> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tavus.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Call Client Examples

> Client-side examples for joining a CVI call with Daily and sending and receiving interaction events from your app. For server-side sending, see Send App Message.

These examples run in your client, such as a browser or app. They join the call with Daily, send interactions over the call's data channel, and listen for events the PAL sends back. To send interactions from your backend without joining the call, use [Send App Message](https://docs.tavus.io/api-reference/conversations/send-app-message.md) instead.

Interaction events use a WebRTC data channel for communication. In Tavus's case, this is powered by [Daily](https://www.daily.co/), which makes setting up the call client quick and simple.

> [tab] Daily JS
>
> Here’s an example of using [DailyJS](https://docs.daily.co/reference/daily-js/daily-call-client) to create a call client in JavaScript:
>
> ```html theme={null}
> <html>
>   <script crossorigin src="https://unpkg.com/@daily-co/daily-js"></script>
>   <body>
>     <!-- Add input field and send button -->
>     <input type="text" id="messageInput" placeholder="Enter your message">
>     <button onclick="sendAppMessage()">Send Message</button>
>
>     <script>
>       call = window.Daily.createFrame();
>       call.on('app-message', (event) => {
>         console.log('app-message', event);
>       });
>
>       call.join({ url: 'YOUR_CONVERSATION_URL' });
>
>       function sendAppMessage() {
>         const messageInput = document.getElementById('messageInput');
>         const message = messageInput.value;
>         if (message) {
>           const interaction = {
>             "message_type": "conversation",
>             "event_type": "conversation.respond",
>             "conversation_id": "YOUR_CONVERSATION_ID",
>             "properties": {
>               "text": `${message}`
>             }
>           }
>           const hi = call.sendAppMessage(interaction, '*');
>           console.log('Sending message: ', hi);
>           console.log('Sent message: ', interaction);
>           messageInput.value = '';
>         }
>       }
>     </script>
>   </body>
> </html>
> ```

> [tab] Daily Python
>
> Here’s an example of using [Daily Python](https://docs.daily.co/reference/daily-python) to create a call client in Python:
>
> ```py theme={null}
> from daily import CallClient, Daily, EventHandler
>
> call_client = None
>
> class RoomHandler(EventHandler):
>     def __init__(self):
>         super().__init__()
>
>     def on_app_message(self, message, sender: str) -> None:
>         print(f"Incoming app message from {sender}: {message}")
>
> def join_room(url):
>     global call_client
>     try:
>         Daily.init()
>         output_handler = RoomHandler()
>         call_client = CallClient(event_handler=output_handler)
>         call_client.join(url)
>     except Exception as e:
>         print(f"Error joining room: {e}")
>         raise
>
> def send_message(text):
>     global call_client
>     interaction = {
>         "message_type": "conversation",
>         "event_type": "conversation.respond",
>         "conversation_id": "YOUR_CONVERSATION_ID",
>         "properties": {"text": text},
>     }
>     # Without a participant ID, Daily Python sends the message to everyone in the room.
>     call_client.send_app_message(interaction)
> ```

> [tab] Daily JS in React
>
> Here’s an example of using [Daily JS](https://docs.daily.co/reference/daily-js/daily-call-client) inside a React component:
>
> ```tsx theme={null}
> "use client"
>
> import React, { useEffect, useRef, useState } from 'react';
>
>
> const TavusConversation = () => {
>   const [message, setMessage] = useState('');
>   const callRef = useRef(null);
>   const containerRef = useRef(null);
>
>
>   useEffect(() => {
>     const loadDaily = async () => {
>       const DailyIframe = (await import('@daily-co/daily-js')).default;
>
>
>       callRef.current = DailyIframe.createFrame({
>         iframeStyle: {
>           width: '100%',
>           height: '500px',
>           border: '0',
>         }
>       });
>
>
>       if (containerRef.current) {
>         containerRef.current.appendChild(callRef.current.iframe());
>       }
>
>
>       callRef.current.on('app-message', (event) => {
>         console.log('app-message received:', event);
>       });
>
>
>       callRef.current.join({
>         url: 'YOUR_CONVERSATION_URL',
>       });
>     };
>
>
>     loadDaily();
>
>
>     return () => {
>       if (callRef.current) {
>         callRef.current.leave();
>         callRef.current.destroy();
>       }
>     };
>   }, []);
>
>
>   const sendAppMessage = () => {
>     if (!message || !callRef.current) return;
>
>
>     const interaction = {
>       message_type: 'conversation',
>       event_type: 'conversation.respond',
>       conversation_id: 'YOUR_CONVERSATION_ID',
>       properties: { text: message }
>     };
>
>
>     callRef.current.sendAppMessage(interaction, '*');
>     setMessage('');
>   };
>
>
>   return (
>     <div className="w-full h-full flex flex-col items-center">
>       <div ref={containerRef} className="w-full mb-4" />
>       <div>
>         <input
>           type="text"
>           className="border p-2 mr-2"
>           value={message}
>           onChange={(e) => setMessage(e.target.value)}
>           placeholder="Type a message"
>         />
>         <button onClick={sendAppMessage} className="bg-blue-500 text-white px-4 py-2 rounded">
>           Send Message
>         </button>
>       </div>
>     </div>
>   );
> };
>
>
> export default TavusConversation;
> ```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.