Skip to main content

Overview

CometChat AI features enhance your chat experience with intelligent suggestions and summaries. Once enabled in your dashboard, they integrate automatically into the UI Kit components.
FeatureWhat It DoesWhere It Appears
Conversation StartersSuggests opening messages for new chatsCometChatMessageList
Smart RepliesSuggests responses based on contextCometChatMessageComposer
Conversation SummarySummarizes long conversationsCometChatMessageComposer
AI AssistantChat with AI botCometChatAIAssistanceChatHistory

Enable AI Features

1

Open CometChat Dashboard

Go to app.cometchat.com and select your app.
2

Navigate to AI Features

Click AI in the sidebar, then enable the features you want:
  • ✅ Conversation Starter
  • ✅ Smart Replies
  • ✅ Conversation Summary
3

Configure (Optional)

Customize AI behavior, response style, and triggers in the dashboard settings.
That’s it! AI features now work automatically in your app.

Conversation Starters

When a user opens a new chat with no message history, AI suggests conversation openers.

How It Works

  1. User opens chat with someone they haven’t messaged before
  2. AI analyzes user profiles and context
  3. Suggested messages appear in the message list
  4. User taps a suggestion to send it

Implementation

Conversation starters appear automatically in CometChatMessages:
import UIKit
import CometChatUIKitSwift
import CometChatSDK

class ChatViewController: UIViewController {
    
    func openChatWithUser(uid: String) {
        CometChat.getUser(UID: uid) { [weak self] user in
            DispatchQueue.main.async {
                let messagesVC = CometChatMessages()
                messagesVC.user = user
                
                // Conversation starters appear automatically
                // if enabled in dashboard and no previous messages exist
                
                self?.navigationController?.pushViewController(messagesVC, animated: true)
            }
        } onError: { error in
            print("Error: \(error?.errorDescription ?? "")")
        }
    }
}

Smart Replies

AI suggests contextual responses based on the conversation.

How It Works

  1. User receives a message
  2. AI analyzes the message and conversation context
  3. Smart reply suggestions appear in the composer action sheet
  4. User taps a suggestion to insert it

Implementation

Smart replies appear automatically in CometChatMessageComposer:
import UIKit
import CometChatUIKitSwift
import CometChatSDK

class ChatViewController: UIViewController {
    
    func openChat(with user: CometChat.User) {
        let messagesVC = CometChatMessages()
        messagesVC.user = user
        
        // Smart replies appear automatically in the composer
        // when enabled in dashboard
        
        navigationController?.pushViewController(messagesVC, animated: true)
    }
}

Conversation Summary

AI generates summaries of long conversations so users can catch up quickly.

How It Works

  1. User opens a conversation with many messages
  2. User taps the summary option in composer action sheet
  3. AI processes the conversation
  4. Summary of key points is displayed

Implementation

Conversation summary is available automatically:
import UIKit
import CometChatUIKitSwift
import CometChatSDK

class ChatViewController: UIViewController {
    
    func openChat(with user: CometChat.User) {
        let messagesVC = CometChatMessages()
        messagesVC.user = user
        
        // Conversation summary option appears in composer action sheet
        // when enabled in dashboard and sufficient messages exist
        
        navigationController?.pushViewController(messagesVC, animated: true)
    }
}

AI Assistant Chat History

View and continue conversations with AI assistants.

Basic Implementation

import UIKit
import CometChatUIKitSwift
import CometChatSDK

class AIAssistantViewController: UIViewController {
    
    var user: CometChat.User!
    
    func showAIChatHistory() {
        let chatHistory = CometChatAIAssistanceChatHistory()
        chatHistory.user = user  // Required
        
        navigationController?.pushViewController(chatHistory, animated: true)
    }
}

Full Implementation with Callbacks

import UIKit
import CometChatUIKitSwift
import CometChatSDK

class AIAssistantViewController: UIViewController {
    
    var user: CometChat.User!
    
    func showAIChatHistory() {
        let chatHistory = CometChatAIAssistanceChatHistory()
        chatHistory.user = user
        
        // Handle new chat button
        chatHistory.onNewChatButtonClicked = { [weak self] in
            self?.startNewAIChat()
        }
        
        // Handle message tap
        chatHistory.onMessageClicked = { message in
            print("Tapped message: \(message.text ?? "")")
        }
        
        // Handle load success
        chatHistory.set(onLoad: { messages in
            print("Loaded \(messages.count) AI messages")
        })
        
        // Handle empty state
        chatHistory.set(onEmpty: {
            print("No AI chat history")
        })
        
        // Handle errors
        chatHistory.set(onError: { [weak self] error in
            self?.showError(error.localizedDescription)
        })
        
        navigationController?.pushViewController(chatHistory, animated: true)
    }
    
    private func startNewAIChat() {
        // Navigate to new AI chat
        print("Starting new AI conversation")
    }
    
    private func showError(_ message: String) {
        let alert = UIAlertController(title: "Error", message: message, preferredStyle: .alert)
        alert.addAction(UIAlertAction(title: "OK", style: .default))
        present(alert, animated: true)
    }
}

Customize AI Chat History Styling

import UIKit
import CometChatUIKitSwift

class AIAssistantViewController: UIViewController {
    
    var user: CometChat.User!
    
    func showStyledAIChatHistory() {
        let chatHistory = CometChatAIAssistanceChatHistory()
        chatHistory.user = user
        
        // Custom styling
        let style = AiAssistantChatHistoryStyle()
        style.backgroundColor = .systemBackground
        style.itemTextFont = UIFont.systemFont(ofSize: 16, weight: .medium)
        style.itemTextColor = .label
        style.newChatTitleFont = UIFont.systemFont(ofSize: 18, weight: .bold)
        style.newChatTitleColor = .systemBlue
        chatHistory.style = style
        
        // Custom empty state
        chatHistory.emptyStateText = "No AI conversations yet"
        chatHistory.emptyStateSubtitleText = "Tap 'New Chat' to start"
        
        // Custom date formatting
        chatHistory.dateTimeFormatter.today = { timestamp in
            let date = Date(timeIntervalSince1970: TimeInterval(timestamp))
            let formatter = DateFormatter()
            formatter.timeStyle = .short
            return "Today at \(formatter.string(from: date))"
        }
        
        navigationController?.pushViewController(chatHistory, animated: true)
    }
}

Complete App with AI Features

Full implementation showing all AI features:
import UIKit
import CometChatUIKitSwift
import CometChatSDK

// MARK: - Scene Delegate
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    
    var window: UIWindow?
    
    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
        guard let windowScene = (scene as? UIWindowScene) else { return }
        
        let uikitSettings = UIKitSettings()
            .set(appID: "YOUR_APP_ID")
            .set(authKey: "YOUR_AUTH_KEY")
            .set(region: "YOUR_REGION")
            .subscribePresenceForAllUsers()
            .build()
        
        CometChatUIKit.init(uiKitSettings: uikitSettings) { [weak self] result in
            switch result {
            case .success:
                CometChatUIKit.login(uid: "cometchat-uid-1") { loginResult in
                    switch loginResult {
                    case .success:
                        DispatchQueue.main.async {
                            self?.setupUI(windowScene: windowScene)
                        }
                    case .onError(let error):
                        print("Login failed: \(error.description)")
                    @unknown default:
                        break
                    }
                }
            case .failure(let error):
                print("Init failed: \(error.localizedDescription)")
            }
        }
    }
    
    private func setupUI(windowScene: UIWindowScene) {
        let tabBar = AIEnabledTabBarController()
        window = UIWindow(windowScene: windowScene)
        window?.rootViewController = tabBar
        window?.makeKeyAndVisible()
    }
}

// MARK: - Tab Bar Controller
class AIEnabledTabBarController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupTabs()
    }
    
    private func setupTabs() {
        // Chats - AI features (starters, smart replies, summary) work automatically
        let chatsVC = CometChatConversationsWithMessages()
        let chatsNav = UINavigationController(rootViewController: chatsVC)
        chatsNav.tabBarItem = UITabBarItem(
            title: "Chats",
            image: UIImage(systemName: "message"),
            selectedImage: UIImage(systemName: "message.fill")
        )
        
        // AI Assistant
        let aiVC = AIAssistantListViewController()
        let aiNav = UINavigationController(rootViewController: aiVC)
        aiNav.tabBarItem = UITabBarItem(
            title: "AI Assistant",
            image: UIImage(systemName: "sparkles"),
            selectedImage: UIImage(systemName: "sparkles")
        )
        
        // Users
        let usersVC = CometChatUsersWithMessages()
        let usersNav = UINavigationController(rootViewController: usersVC)
        usersNav.tabBarItem = UITabBarItem(
            title: "Users",
            image: UIImage(systemName: "person.2"),
            selectedImage: UIImage(systemName: "person.2.fill")
        )
        
        viewControllers = [chatsNav, aiNav, usersNav]
    }
}

// MARK: - AI Assistant List
class AIAssistantListViewController: UIViewController {
    
    private let tableView = UITableView()
    private var users: [CometChat.User] = []
    
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "AI Assistant"
        setupTableView()
        fetchUsers()
    }
    
    private func setupTableView() {
        view.addSubview(tableView)
        tableView.frame = view.bounds
        tableView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        tableView.delegate = self
        tableView.dataSource = self
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
    }
    
    private func fetchUsers() {
        let request = UsersRequest.UsersRequestBuilder()
            .set(limit: 30)
            .build()
        
        request.fetchNext { [weak self] users in
            self?.users = users
            DispatchQueue.main.async {
                self?.tableView.reloadData()
            }
        } onError: { error in
            print("Error: \(error?.errorDescription ?? "")")
        }
    }
}

extension AIAssistantListViewController: UITableViewDelegate, UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return users.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
        let user = users[indexPath.row]
        cell.textLabel?.text = user.name
        cell.accessoryType = .disclosureIndicator
        return cell
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        tableView.deselectRow(at: indexPath, animated: true)
        
        let user = users[indexPath.row]
        let chatHistory = CometChatAIAssistanceChatHistory()
        chatHistory.user = user
        
        chatHistory.onNewChatButtonClicked = { [weak self] in
            // Start new AI chat
            let messagesVC = CometChatMessages()
            messagesVC.user = user
            self?.navigationController?.pushViewController(messagesVC, animated: true)
        }
        
        navigationController?.pushViewController(chatHistory, animated: true)
    }
}

Troubleshooting

ProblemSolution
AI features not appearingEnable them in CometChat Dashboard → AI
Conversation starters not showingOnly appear for new conversations with no messages
Smart replies not appearingEnsure feature is enabled and messages exist
Summary not generatingNeed sufficient messages in conversation
AI Assistant emptyVerify user has AI chat history