Skip to main content

Getting Started

The LikeMinds Chat SDK allows you to seamlessly integrate personalized and engaging chats into your iOS application. This can significantly enhance the user experience and drive user engagement within your app. This getting started guide will walk you through the steps to integrate it into your application.

Prerequisites

Before you begin, ensure that you have the following:

  1. Xcode: Make sure you have Xcode 11 or above installed on your development machine.
  2. LikeMinds API Key: Sign up on the LikeMinds dashboard and obtain an API key for your application.

Dependencies

The SDK tries to keep the list of external dependencies to a minimum, these are the dependencies currently used:

LikeMindsChatUI

LikeMindsChatCore

LikeMindsChatData

Step-by-Step Integration Guide

Follow these steps to integrate the LikeMinds Chat SDK into your iOS application using CocoaPods:

Step 1: Adding Dependency

Open your project's Podfile and add the following lines:

platform :ios, '13.0'

target 'YourProjectName' do
use_frameworks!
pod 'LikeMindsChatCore', '~> 1.8.0'
end

Then, run pod install from the terminal to install the required dependencies.

Step 2: Setup LikeMinds Chat

In your AppDelegate.swift file, import the LikeMindsChatCore framework and set up the LikeMinds Chat in the application(_:willFinishLaunchingWithOptions:) method:

import LikeMindsChatCore

func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) {
LMChatCore.shared.setupChat(deviceId: deviceId)
}
tip

It is advised to initiate LMChatCore at the beginning of your App Cycle.

Step 3: Initiate User Session

You have successfully initiated the LMChatCore. Now, when integrating the LikeMinds Chat SDK into your application, you provide the API Key directly to the LikeMinds Chat SDK, which will be used to initiate a user session by calling the showChat() method from LMChatCore.

import LikeMindsChatCore

func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) {
LMChatCore.shared.showChat(apiKey: "YOUR_API_KEY", username: username, uuid: userId, completionHandler: { })
}
tip

For enhanced security, you can use Server Side User Authentication to initiate user sessions through your own server.

Step 4: Navigate to Chat

In the view controller where you want to display the LikeMinds Chat, import the LikeMindsChatCore framework and initialize the Chat with the appropriate user credentials:

import LikeMindsChatCore

let username = "USER_NAME"
let uuid = "USER_UUID"
let apiKey = "YOUR API KEY"

try? LMChatCore.shared.showChat(apiKey: apiKey, username: username, userId: userId) { [weak self] result in
switch result {
case .success:
do {
let chatFeedVC = try LMCommunityChatViewModel.createModule()
self?.navigationController?.pushViewController(chatFeedVC, animated: true)
} catch {
let alert = UIAlertController(
title: "Error",
message: "Failed to open chat: \(error.localizedDescription)",
preferredStyle: .alert
)
alert.addAction(UIAlertAction(title: "OK", style: .default))
self?.present(alert, animated: true)
}
case .failure(let error):
let alert = UIAlertController(title: "Error", message: error.localizedDescription, preferredStyle: .alert)
alert.addAction(.init(title: "OK", style: .default))
self?.present(alert, animated: true)
return
}
}

Replace USER_NAME, USER_UUID and DEVICE_ID with the appropriate user credentials and device unique identifier for your application.

The createModule() method returns the view controller that displays the LikeMinds Chat. - In case of success, it sets the returned view controller as the root view controller of the application's window. - In case of failure, it displays an alert with the error message.

note

The view controller where you initialize the LikeMinds Chat should have a navigation controller, as the Chat requires navigation capabilities.

Step 5: Add Chatbot Button to your Screen (Optional)

note

Add AI Assitant to LikeMinds: Follow this tutorial to add Assistant to LikeMinds Dashboard, before proceeding with this step.

Add the LMChatAIButton to your app's UI by placing it in the desired location within your app's widget tree. Ideally, a Floating Action Button (FAB) is the best place to put it.

Here's how to implement it in your view controller:

class YourViewController: UIViewController {
// Create the button using the factory method
private lazy var aiChatButton: LMChatAIButton = {
let button = LMUIComponents.shared.lmChatAIButton.createButton()
button.delegate = self
button.translatesAutoresizingMaskIntoConstraints = false
return button
}()

override func viewDidLoad() {
super.viewDidLoad()
setupAIChatButton()
}

// Configure the button with required props
private func setupAIChatButton() {
let props = LMChatAIButtonProps(
apiKey: "your_api_key",
uuid: "user_id",
userName: "username"
)
aiChatButton.setProps(props)
}

// Function to start AI chat
private func startAIChatBot(apiKey: String, username: String, userId: String) {
LMChatCore.shared.showChat(
apiKey: apiKey,
username: username,
uuid: userId
) { [weak self] result in
switch result {
case .success:
do {
let vc = try LMChatAIBotInitiaitionViewModel.createModule()
self?.navigationController?.pushViewController(vc, animated: true)
} catch {
// Handle error
}
case .failure(let error):
// Handle error
}
}
}
}

// Implement the delegate method
extension YourViewController: LMChatAIButtonDelegate {
public func didTapAIButton(_ button: LMChatAIButton, props: LMChatAIButtonProps) {
guard let props = button.props,
let apiKey = props.apiKey,
let username = props.userName,
let userId = props.uuid else {
// Handle missing credentials
return
}
startAIChatBot(apiKey: apiKey, username: username, userId: userId)
}
}

Now, whenever the button is pressed, the entire chat experience will be initialized with the provided props. A fresh chatroom (if not already present) will be created with the user's details, and the chatbot will be ready to take the user's queries.

That's it! You have successfully integrated the LikeMinds Chat SDK into your iOS application. The next step would be to explore additional customization options or configurations provided by the SDK to tailor the Chat to your application's needs.