Skip to main content

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

Methods

  • setProps(_:): Sets the configuration properties for the button
  • configureIconPlacement(_:spacing:): Configures the placement of the icon and text
  • createButton(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:

PropTypeRequiredDescription
apiKeyStringRequired*The API key used for authentication when not using token-based security. Required when using the non-token based authentication method.
uuidStringRequired*The unique identifier for the user. Required when using the non-token based authentication method.
userNameStringRequired*The display name of the user. Required when using the non-token based authentication method.
imageUrlStringOptionalThe URL of the user's profile image. Used for user profile customization.
isGuestBoolOptionalIndicates whether the user is a guest user. Defaults to false if not provided.
accessTokenStringRequired**The access token for token-based security authentication. Required when using the token-based authentication method.
refreshTokenStringRequired**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
)