AI Chat Button
Overview
The LMChatAIButton
is a customizable button widget used within the chat interface to allow for direct initialization of the AI chatbot. It can be used as a floating action button or as a regular button, supporting icons, text, and state management for active and inactive modes.
Protocols
LMChatAIButtonDelegate
didTapAIButton(_:props:)
: Called when the AI chat button is tapped, providing the button instance and its configuration properties.
Properties
delegate
: The delegate that handles button tap eventsLMChatAIButtonDelegate
props
: Configuration properties for AI chatbot initializationLMChatAIButtonProps
Methods
setProps(_:)
: Sets the configuration properties for the buttonconfigureIconPlacement(_:spacing:)
: Configures the placement of the icon and textcreateButton(with:image:textColor:textFont:backgroundColor:cornerRadius:iconPlacement:spacing:contentInsets:iconSize:)
: Factory method to create a pre-configured button instance
Props Model
The LMChatAIButton
accepts the following properties through the LMChatAIButtonProps
class:
Prop | Type | Required | Description |
---|---|---|---|
apiKey | String | Required* | The API key used for authentication when not using token-based security. Required when using the non-token based authentication method. |
uuid | String | Required* | The unique identifier for the user. Required when using the non-token based authentication method. |
userName | String | Required* | The display name of the user. Required when using the non-token based authentication method. |
imageUrl | String | Optional | The URL of the user's profile image. Used for user profile customization. |
isGuest | Bool | Optional | Indicates whether the user is a guest user. Defaults to false if not provided. |
accessToken | String | Required** | The access token for token-based security authentication. Required when using the token-based authentication method. |
refreshToken | String | Required** | The refresh token for token-based security authentication. Required when using the token-based authentication method. |
* Required for client-side authentication ** Required for server-side authentication
Customization
let button = LMChatAIButton.createButton(
with: "Custom AI Chat", // Custom title
image: UIImage(named: "custom_icon"), // Custom icon
textColor: .white, // Custom text color
textFont: .systemFont(ofSize: 16), // Custom font
backgroundColor: .systemBlue, // Custom background color
cornerRadius: 20, // Custom corner radius
iconPlacement: .start, // Icon placement (start or end)
spacing: 8, // Spacing between icon and text
contentInsets: UIEdgeInsets(top: 8, left: 16, bottom: 8, right: 16), // Content insets
iconSize: CGSize(width: 20, height: 20) // Icon size
)