<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ayush Bisaria on Medium]]></title>
        <description><![CDATA[Stories by Ayush Bisaria on Medium]]></description>
        <link>https://medium.com/@ayushbisaria_99566?source=rss-e0b1df729d63------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*kJ4y2u1kUGS2HrcuWnvvBA.png</url>
            <title>Stories by Ayush Bisaria on Medium</title>
            <link>https://medium.com/@ayushbisaria_99566?source=rss-e0b1df729d63------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 23:33:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ayushbisaria_99566/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Build a web chat app using CCAI-Platform Headless Web SDK]]></title>
            <link>https://medium.com/google-cloud/build-a-web-chat-app-using-ccai-platform-headless-web-sdk-a5b256e7b0fb?source=rss-e0b1df729d63------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5b256e7b0fb</guid>
            <category><![CDATA[ccai]]></category>
            <category><![CDATA[google-cloud-platform]]></category>
            <category><![CDATA[google-ccai]]></category>
            <dc:creator><![CDATA[Ayush Bisaria]]></dc:creator>
            <pubDate>Fri, 25 Jul 2025 09:51:38 GMT</pubDate>
            <atom:updated>2025-07-25T09:51:38.502Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Have you ever wanted to integrate a powerful, customizable chat experience directly into your web application without the overhead of a full-blown contact center solution? Building a seamless chat interface often involves complex backend authentication and secure configuration management. This blog post provides a practical walkthrough to building a chat application using a <a href="https://cloud.google.com/contact-center/ccai-platform/docs/headless-web-guide"><strong>CCAIP Headless Web SDK</strong></a>, demonstrating a robust client-server architecture.</p><p>In this blog, you’ll learn how to:</p><ul><li>Set up a Node.js backend for secure authentication and dynamic configuration delivery.</li><li>Develop a pure JavaScript frontend for a rich chat user interface.</li><li>Handle various message types, including text, files, and rich content cards.</li><li>Manage environment variables securely to protect sensitive information.</li></ul><h3>Understanding the Core Concepts of a Headless Web SDK</h3><p>Before diving into the implementation, let’s understand what a <strong>Headless Web SDK</strong> is and why it’s beneficial for building chat applications.</p><p>A Headless SDK, in the context of CCAI-Platform, provides the core functionalities of a contact center (like chat, voice, etc.) as a library, but without a pre-built user interface (UI). This gives developers complete control over the frontend experience, allowing for deep customization and seamless integration into existing applications.</p><p>Key advantages of using a Headless SDK:</p><ul><li><strong>Flexibility:</strong> Design and implement your chat UI exactly as you envision it, matching your brand’s aesthetics.</li><li><strong>Control:</strong> You have full control over the user experience and data flow.</li><li><strong>Integration:</strong> Easily embed chat functionality into any web application or framework.</li><li><strong>Security:</strong> By handling authentication and configuration on the backend, sensitive information remains secure.</li></ul><p>Our demo project leverages this approach with a <strong>client-server architecture</strong>. The <strong>Node.js backend</strong> (server.js) is responsible for:</p><ul><li><strong>Securely generating JSON Web Tokens (JWTs)</strong> for client authentication with the headless SDK.</li><li><strong>Dynamically providing necessary CCAIP SDK configuration variables</strong> (like host, company ID, etc.) to the client, loaded securely from environment variables.</li></ul><p>The <strong>pure JavaScript frontend</strong> provides the actual chat user interface, interacting with the CCAI-Platform via the headless SDK. This clear separation of concerns ensures a maintainable and scalable application.</p><h3>Implementation Steps: Setting Up Your Chat Demo</h3><p>This section will walk you through setting up and running the Headless SDK chat demo. We’ll cover prerequisites, project structure, and detailed installation steps for both the backend and frontend.</p><h3>Project Structure</h3><p>Understanding the project’s layout is crucial for navigating the codebase:</p><pre>.<br>├── client/<br>│   ├── favicon23.png<br>│   ├── favicon.png<br>│   ├── index.html             // Main HTML file for the chat interface<br>│   ├── node_modules/<br>│   ├── package.json<br>│   ├── package-lock.json<br>│   ├── public/<br>│   │   └── vite.svg<br>│   └── src/<br>│       ├── javascript.svg<br>│       ├── main.js            // Core JavaScript for frontend logic and SDK interaction<br>│       └── style.css          // Styling for the chat interface<br>├── Readme.md<br>└── server/<br>    ├── config                 // Directory for environment variables<br>    ├── node_modules<br>    ├── package.json<br>    ├── package-lock.json<br>    └── server.js              // Node.js backend for authentication and config</pre><p><strong>Architecture</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kp-qbLiN9UgPefRt" /><figcaption>Client-Server Architecture</figcaption></figure><h3>Prerequisites</h3><p>Before you begin, make sure you have the following installed on your system:</p><ul><li><strong>Node.js</strong>: The LTS (Long Term Support) version is recommended. You can download it from<a href="https://nodejs.org/en/download/"> nodejs.org</a>.</li><li><strong>npm</strong>: Node Package Manager, which comes bundled with <a href="http://node.js/">Node.js</a>.</li><li><strong>CCAIP Instance</strong>: You must have an existing ccaip instance. At least one queue should be configured and integrated with a Dialogflow CX agent, and at least one human agent should be assigned to that queue. Make sure to note the queue ID, as it will be required in the SDK configuration.</li><li><strong>DFCX Agent:</strong> Refer uploaded dfcx agent blob <a href="https://github.com/ayushbisaria/ccaip-headless-sdk-demo/tree/main/example/sample_dfcx_agent_zip">here</a>, restore it in your dfcx console and integrate it with ccai-platform web queue. This agent contains <a href="https://cloud.google.com/contact-center/ccai-platform/docs/va-custom-payload">samples of different ccaip custom payloads</a> (like inline_buttons, content cards etc.) implemented within page intent routes.</li></ul><h3>Setup &amp; Installation</h3><p>Follow these steps to get the demo running on your local machine:</p><ol><li><strong>Clone the Repository:</strong> Start by cloning the demo repository from GitHub and navigating into its directory:</li></ol><pre>git clone https://github.com/ayushbisaria/ccaip-headless-sdk-demo.git<br>cd ccaip-headless-sdk-demo</pre><p>2. <strong>Backend Setup:</strong> Next, set up the Node.js backend. This involves installing dependencies and configuring environment variables for secure communication with your ccai-platform.</p><pre>cd server<br>npm install<br>mkdir config<br>cd config<br>touch .env</pre><p>Now, open the newly created .env file in your server/config directory using a text editor and fill in your actual ccaip related vars. <strong>It is crucial not to commit this .env file to Git.</strong></p><pre># server/config/.env<br>COMPANY_SECRET=&quot;YOUR_CCAIP_COMPANY_SECRET_FROM_CCAIP_DEVELOPER_SETTINGS&quot;<br>HOST=&quot;YOUR_CCAIP_HOST&quot;<br>COMPANY_ID=&quot;YOUR_CCAIP_COMPANY_ID_FROM_CCAIP_DEVELOPER_SETTINGS&quot;<br>MENU_ID=&quot;YOUR_QUEUE_ID&quot; # e.g., &quot;23&quot;<br>TENANT=&quot;YOUR_CCAIP_TENANT_NAME&quot;</pre><p>3. <strong>Frontend Setup:</strong> Finally, set up the frontend. The client-side application fetches its configuration securely from the backend, so fewer environment variables are needed directly on the client.</p><pre>cd ../client # Go back to the root and then into client<br>npm install</pre><p>For this specific project, the frontend currently fetches its configuration from the backend, so you typically won’t need to create a .env.development file in the client/ directory unless your Vite setup explicitly uses it for other purposes (e.g., VITE_API_URL if your backend was hosted elsewhere).</p><h3>Running the Application</h3><p>You have two options for running the Headless Web SDK chat demo:</p><h3>Option 1: Recommended (Using npm run dev from root)</h3><p>This method simplifies the process by using concurrently to start both the backend and frontend simultaneously, making it the easiest way to get everything up and running.</p><ol><li>From the <strong>root directory</strong> of your project (ccaip-headless-sdk-demo/), run:</li></ol><pre>npm install # Only needed the very first time after cloning<br>npm run dev</pre><p>2. This command will:</p><ul><li>Start the backend server on <a href="http://localhost:3000.">http://localhost:3000.</a></li><li>Start the frontend development server (Vite) and automatically open your browser to the client application (e.g., <a href="http://localhost:5173).">http://localhost:5173).</a></li></ul><p>3. <strong>Note:</strong> Due to the asynchronous nature of starting two servers, you might occasionally experience a “failed to load config” error on the very first auto-opened browser tab. A quick manual browser refresh (F5 or Cmd+R) should resolve this, allowing the backend server sufficient time to be fully ready.</p><h3>Option 2: Manual Start (Alternative)</h3><p>If you prefer to start each component individually, or if you encounter issues with the recommended method, you can use this alternative:</p><ol><li><strong>Start the Backend Server:</strong> Open your first terminal window, navigate to the server directory, and run:</li></ol><pre>cd server<br>node server.js</pre><p>2. You should see a message similar to: Authentication server listening at <a href="http://localhost:3000.">http://localhost:3000.</a></p><p>3. <strong>Start the Frontend Development Server:</strong> Open a second terminal window, navigate to the client directory, and run:</p><pre>cd client<br>npm run dev</pre><p>4. This will start the Vite development server and automatically open the client application in your browser (e.g., <a href="http://localhost:5173).">http://localhost:5173).</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ufAH8JLiqq8qCbPm5WrVLA.png" /><figcaption>Chatbot Interface</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BvRlaFuj7xZSHAIpGFrmsw.png" /><figcaption>DFCX VA — Demo CCAIP Custom Payloads</figcaption></figure><h3>Real-World Application: Features and Technical Deep Dive</h3><p>Once the application is running, you’ll see a simple web-based chat interface. This demo showcases several key features vital for a practical chat application built with a Headless SDK:</p><ul><li><strong>Client-Server Architecture:</strong> The clear separation of frontend and backend ensures maintainability and scalability. The backend (server.js) focuses on secure authentication and configuration delivery, while the frontend (main.js, index.html, style.css) handles the chat UI.</li><li><strong>Secure Authentication:</strong> The backend dynamically generates signed <strong>JSON Web Tokens (JWTs)</strong>, which are essential for authenticating the client with the SDK. This prevents sensitive credentials from being exposed on the client side.</li><li><strong>Dynamic Configuration:</strong> Instead of hardcoding SDK details, the backend securely loads configuration variables (like COMPANY_SECRET, HOST, COMPANY_ID, MENU_ID, TENANT) from its .env file and provides them to the frontend.</li><li><strong>Chat Interface:</strong> The frontend provides a fully functional chat interface which utilizes <a href="https://www.npmjs.com/package/@ujet/websdk-headless?activeTab=code">@ujet/websdk-headless</a>, capable of:<br>- Displaying <strong>text messages</strong>.<br>- Handling and displaying <strong>file messages</strong>.<br>- Rendering <strong>inline buttons</strong> for interactive responses. These buttons are typically sent from the Dialogflow CX agent as a CCAIP custom payload, like the following example:</li></ul><pre>{<br>  &quot;ujet&quot;: {<br>    &quot;buttons&quot;: [<br>      {<br>        &quot;title&quot;: &quot;Yes&quot;,<br>        &quot;action&quot;: &quot;quick_reply&quot;<br>      },<br>      {<br>        &quot;title&quot;: &quot;No&quot;,<br>        &quot;action&quot;: &quot;escalation&quot;<br>      }<br>    ],<br>    &quot;title&quot;: &quot;Escalate to Agent&quot;,<br>    &quot;type&quot;: &quot;inline_button&quot;<br>  }<br>}</pre><ul><li>Showcasing <strong>rich content cards</strong> for enhanced user experience. These cards are also typically sent from the Dialogflow CX agent as a CCAIP custom payload. Here’s an example(there are other variations mentioned in sample dfcx agent):</li></ul><pre>{<br>  &quot;ujet&quot;: {<br>    &quot;cards&quot;: [<br>      {<br>        &quot;images&quot;: [<br>          &quot;https://ujet-seonhak.s3.us-west-2.amazonaws.com/main/images/1.jpg&quot;<br>        ],<br>        &quot;body&quot;: &quot;Body 1&quot;,<br>        &quot;event_params&quot;: {},<br>        &quot;link&quot;: &quot;https://www.google.com/search?q=1&quot;,<br>        &quot;subtitle&quot;: &quot;Subtitle 1&quot;,<br>        &quot;title&quot;: &quot;Title 1&quot;<br>      },<br>      {<br>        &quot;subtitle&quot;: &quot;Subtitle 2&quot;,<br>        &quot;body&quot;: &quot;Body 2&quot;,<br>        &quot;images&quot;: [<br>          &quot;https://ujet-seonhak.s3.us-west-2.amazonaws.com/main/images/2.jpg&quot;<br>        ],<br>        &quot;title&quot;: &quot;Title 2&quot;,<br>        &quot;link&quot;: &quot;https://www.google.com/search?q=2&quot;,<br>        &quot;event_params&quot;: {}<br>      },<br>      {<br>        &quot;images&quot;: [<br>          &quot;https://ujet-seonhak.s3.us-west-2.amazonaws.com/main/images/3.jpg&quot;<br>        ],<br>        &quot;link&quot;: &quot;https://www.google.com/search?q=3&quot;,<br>        &quot;event_params&quot;: {},<br>        &quot;subtitle&quot;: &quot;Subtitle 3&quot;,<br>        &quot;body&quot;: &quot;Body 3&quot;,<br>        &quot;title&quot;: &quot;Title 3&quot;<br>      },<br>      {<br>        &quot;subtitle&quot;: &quot;Subtitle 4&quot;,<br>        &quot;body&quot;: &quot;Body 4&quot;,<br>        &quot;link&quot;: &quot;https://www.google.com/search?q=4&quot;,<br>        &quot;event_params&quot;: {},<br>        &quot;title&quot;: &quot;Title 4&quot;,<br>        &quot;images&quot;: [<br>          &quot;https://ujet-seonhak.s3.us-west-2.amazonaws.com/main/images/4.jpg&quot;<br>        ]<br>      },<br>      {<br>        &quot;body&quot;: &quot;Body 5&quot;,<br>        &quot;images&quot;: [<br>          &quot;https://ujet-seonhak.s3.us-west-2.amazonaws.com/main/images/5.jpg&quot;<br>        ],<br>        &quot;event_params&quot;: {},<br>        &quot;link&quot;: &quot;https://www.google.com/search?q=5&quot;,<br>        &quot;subtitle&quot;: &quot;Subtitle 5&quot;,<br>        &quot;title&quot;: &quot;Title 5&quot;<br>      }<br>    ],<br>    &quot;type&quot;: &quot;content_card&quot;<br>  }<br>}</pre><ul><li><strong>File Attachment:</strong> The demo supports sending <strong>image and video attachments</strong>, demonstrating a common requirement for modern chat applications.</li><li><strong>Environment Variable Management:</strong> The use of .env files in server/config ensures that sensitive and environment-specific configurations are managed securely and are not exposed in the codebase.</li><li><strong>Human agent escalations and end conversation:</strong> The chat interface supports human agent escalations and end conversation via ccaip custom payload being sent from dfcx agent.</li></ul><h3>Headless Web SDK Methods/Event Utilized</h3><p>The client-side code (main.js) extensively utilizes various methods and listens for events provided by the headless web SDK to manage the chat lifecycle and interactions. Below is a summary of the key <a href="https://cloud.google.com/contact-center/ccai-platform/docs/headless-web-api">methods</a> and <a href="https://cloud.google.com/contact-center/ccai-platform/docs/headless-web-events">events</a> implemented in this demo:</p><p><strong>Methods Used:</strong></p><ul><li><strong>createChat:</strong> Initiates a new chat session with the ccai-platform.</li><li><strong>finishChat: </strong>Ends an ongoing chat session.</li><li><strong>resumeChat:</strong> Resumes a dismissed chat.</li><li><strong>destroyChat:</strong> destroys the current ongoing chat.</li><li><strong>fetchMessages:</strong> Retrieves the history of messages for the current chat.</li><li><strong>sendTextMessage: </strong>Sends a plain text message from the user.</li><li><strong>sendFileMessage:</strong> Sends a file (e.g., image, video) as an attachment in the chat.</li></ul><p><strong>Events Used:</strong></p><ul><li><strong>ready:</strong> Fired when the SDK is successfully initialized and ready for interaction.</li><li><strong>authenticated:</strong> Indicates that the client has been successfully authenticated with the ccai-platform.</li><li><strong>chat.ongoing:</strong> Triggered when a chat session transitions to an ongoing state.</li><li><strong>chat.message:</strong> Fired when a new message (text, file, custom payload) is received in the chat.</li><li><strong>chat.update:</strong> Provides updates on the chat session status or properties.</li><li><strong>chat.connected:</strong> Indicates that the chat connection has been successfully established.</li></ul><h3>Technical Notes</h3><ul><li>The client-side main.js script plays a crucial role in fetching the ccaip configuration (host, companyId, menuId, tenant) and the JWT authentication token from the Node.js backend. This design prevents hardcoding sensitive or environment-specific SDK details directly in the client-side bundle, enhancing security.</li><li>The server.js file utilizes the dotenv package to load configurations from its config/.env file. This is a standard practice for managing secrets in Node.js applications.</li><li>The package-lock.json files in both server/ and client/ directories are committed to the repository. This ensures consistent dependency installations across all development and deployment environments, preventing “it works on my machine” scenarios.</li></ul><h3>Conclusion</h3><p>This blog has walked you through building a functional chat demonstration using a CCAIP Headless SDK, highlighting the importance of a robust client-server architecture for secure authentication and dynamic configuration. By leveraging a Headless SDK, you gain unparalleled flexibility and control over your chat user experience, making it a powerful tool for integrating custom communication solutions.</p><h3>Ready to build your own custom chat experience?</h3><ul><li><strong>Try out the techniques discussed:</strong> Feel free to <a href="https://github.com/ayushbisaria/ccaip-headless-sdk-demo">clone the repository</a> and experiment with the code. You can modify the UI, add new message types, or integrate with other services. Additionally, implement other headless methods and events within your client code.</li><li><strong>Explore additional resources:<br>- </strong>Check out the official repo for the <strong>CCAIP Headless SDK</strong> (<a href="https://www.npmjs.com/package/@ujet/websdk-headless">@ujet/websdk-headless</a>).<br>- Also, Check out the official documentation for <a href="https://cloud.google.com/contact-center/ccai-platform/docs/headless-web-guide">Headless web SDK</a><br>- Dive deeper into <strong>Node.js</strong> and <strong>Express.js</strong> for backend development.<br>- Learn more about <strong>Vite</strong> for fast frontend development.</li><li><strong>Leave comments and questions:</strong> Share your thoughts, challenges, or successful implementations in the comments section below!</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5b256e7b0fb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/google-cloud/build-a-web-chat-app-using-ccai-platform-headless-web-sdk-a5b256e7b0fb">Build a web chat app using CCAI-Platform Headless Web SDK</a> was originally published in <a href="https://medium.com/google-cloud">Google Cloud - Community</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>