Use Full UI

This guide shows you how to use the prebuilt UI components to quickly integrate Agentforce chat functionality into your iOS app.

Chat UI 

The Chat UI is the primary chat view for interacting with Agents.

TODO:

To display the chat UI, use the createAgentforceChatView method. This method returns a SwiftUI view that you can present to the user.

1do {
2    let chatView = try agentforceClient.createAgentforceChatView(
3        conversation: conversation,
4        delegate: self,
5        onContainerClose: {
6            // Handle chat view close
7        }
8    )
9    // Present the chatView in your SwiftUI hierarchy
10} catch {
11    // Handle error
12}

The createAgentforceChatView method takes the following parameters:

  • conversation: The AgentConversation object that you created earlier
  • delegate: An object that conforms to the AgentforceUIDelegate protocol. This delegate receives notifications about UI events
  • onContainerClose: A closure that’s called when the user closes the chat view

Handle UI Events 

To handle UI events, implement the AgentforceUIDelegate protocol. This protocol has the following methods:

  • modifyUtteranceBeforeSending(_:): This method is called before an utterance is sent to the agent. It allows you to modify the utterance before it is sent.
  • didSendUtterance(_:): This method is called after an utterance has been sent to the agent.
  • userDidSwitchAgents(newConversation:): This method is called when the user switches to a different agent.
1extension YourViewController: AgentforceUIDelegate {
2    func modifyUtteranceBeforeSending(_ utterance: AgentforceUtterance) async -> AgentforceUtterance {
3        // Modify the utterance if needed
4        return utterance
5    }
6
7    func didSendUtterance(_ utterance: AgentforceUtterance) {
8        // Handle sent utterance
9    }
10
11    func userDidSwitchAgents(newConversation: AgentConversation) {
12        // Handle agent switch
13    }
14}

Next Steps