AI Agent Reference Spec
AI Agent Reference Spec
Overview
The UI Kit’s core function is to extend the CometChat SDK, translating raw data and functionality into visually appealing, easy-to-use UI components. To effectively manage and synchronize UI elements and data across all components, the UI Kit uses internal events. These events enable real-time change tracking and ensure the UI reflects the most current state of data. The CometChat UI Kit encapsulates critical CometChat SDK methods within its wrapper to efficiently manage internal eventing. This abstraction layer simplifies interaction with the underlying SDK, making it more developer-friendly.Methods
Access all public methods exposed by the CometChat UI Kit through theCometChatUIKit class.
Init
You must invoke this method before using any other UI Kit methods. This initialization ensures the UI Kit and Chat SDK function correctly in your application. Best practice is to make this one of the first lines of code executed in your application’s lifecycle.Replace APP_ID, REGION, and AUTH_KEY with your CometChat App ID, Region, and Auth Key. The
Auth Key is an optional property of the UIKitSettings class, intended primarily for proof-of-concept (POC) development or early stages of application development. For production, use Auth Token instead.UIKitSettings Properties
| Method | Type | Description |
|---|---|---|
| set(appID:) | String | Sets the unique ID for the app, available on dashboard |
| set(region:) | String | Sets the region for the app (‘us’ or ‘eu’) |
| set(authKey:) | String | Sets the auth key for the app, available on dashboard |
| subscribePresenceForAllUsers | String | Sets subscription type for tracking the presence of all users |
| subscribePresenceForFriends | String | Sets subscription type for tracking the presence of friends |
| subscribePresenceForRoles | String | Sets subscription type for tracking the presence of users with specified roles |
| setAutoEstablishSocketConnection | Boolean | Configures if web socket connections will established automatically on app initialization or be done manually, set to true by default |
| setAIFeatures | List<AIExtensionDataSource> | Sets the AI Features that need to be added in UI Kit |
| setExtensions | List<ExtensionsDataSource> | Sets the list of extension that need to be added in UI Kit |
Example
- Swift
Login using Auth Key
Only theUID of a user is needed to log in. This simple authentication procedure is useful for POC or development phases. For production apps, use AuthToken instead.
- Swift
Login using Auth Token
This advanced authentication procedure does not use the Auth Key directly in your client code, ensuring better security.- Create a User via the CometChat API when the user signs up in your app.
- Create an Auth Token via the CometChat API for the new user and save the token in your database.
- Load the Auth Token in your client and pass it to the
login(authToken:)method.
- Swift
Logout
The CometChat UI Kit and Chat SDK handle the session of the logged-in user within the framework. Before a new user logs in, clean this data to avoid potential conflicts or unexpected behavior by invoking the.logout(user:) function.
- Swift
Create User
Dynamically create users on CometChat using the.create(user:) function. This is useful when users are registered or authenticated by your system and need to be created on CometChat.
- Swift
Base Message
Text Message
To send a text message to a single user or a group, use thesendTextMessage() function. This function requires a TextMessage object containing the necessary information for delivering the message.
- Swift
CometChatUIKit.sendTextMessage() automatically adds the message to the MessagesComponent and ConversationsComponent, handling all related cases for you. In contrast, CometChat.sendTextMessage() only sends the message without updating these UI Kit components.Media Message
To send a media message to a single user or a group, use thesendMediaMessage() function. This function requires a MediaMessage object containing the necessary information for delivering the message.
- Swift
CometChatUIKit.sendMediaMessage() automatically adds the message to the MessagesComponent and ConversationsComponent, handling all related cases for you. In contrast, CometChat.sendMediaMessage() only sends the message without updating these UI Kit components.Custom Message
To send a custom message to a single user or a group, use thesendCustomMessage() function. This function requires a CustomMessage object containing the necessary information for delivering the message.
- Swift
CometChatUIKit.sendCustomMessage() automatically adds the message to the MessagesComponent and ConversationsComponent, handling all related cases for you. In contrast, CometChat.sendCustomMessage() only sends the message without updating these UI Kit components.Interactive Message
Form Message
To send a Form message to a single user or a group, use thesendFormMessage() function. This function requires a FormMessage object containing the necessary information to create a form bubble for that message.
- Swift
Card Message
To send a Card message to a single user or a group, use thesendCardMessage() function. This function requires a CardMessage object containing the necessary information to create a card bubble for the message.
- Swift
Scheduler Message
To send a Scheduler message to a single user or a group, use thesendSchedulerMessage() function. This function requires a SchedulerMessage object containing the necessary information to create a scheduler bubble for the message.
- Swift