### Start Agentforce Conversation in Swift Source: https://github.com/salesforce/agentforcemobilesdk-ios/blob/main/README.md Illustrates how to initiate a conversation with an agent using the `startAgentforceConversation` method on the `AgentforceClient`, which returns an `AgentConversation` object representing the session. ```Swift let conversation = agentforceClient.startAgentforceConversation(forAgentId: "YOUR_AGENT_ID") ``` -------------------------------- ### Implement AgentforceAuthCredentialProviding Protocol in Swift Source: https://github.com/salesforce/agentforcemobilesdk-ios/blob/main/README.md Provides an example Swift implementation of the 'AgentforceAuthCredentialProviding' protocol, demonstrating how to supply authentication credentials (OAuth or OrgJWTs) to the Agentforce SDK. ```swift import Foundation import AgentforceSDK // An example implementation that retrieves auth details from a hypothetical SessionManager. class MyAppCredentialProvider: AgentforceAuthCredentialProviding { public func getAuthCredentials() -> AgentforceAuthCredential { // If using OAuth return .OAuth(authToken: getCurentAuthToken(), orgId: orgId, userId: userId) // If using OrgJWTs return .OrgJWT(orgJWT: getOrgJWT()) } } ``` -------------------------------- ### Display Agentforce Chat UI in SwiftUI Source: https://github.com/salesforce/agentforcemobilesdk-ios/blob/main/README.md Provides an example of how to display the chat UI by calling `createAgentforceChatView` on the `AgentforceClient`. This method returns a SwiftUI view that can be presented to the user, with options for a delegate and a close handler. ```Swift do { let chatView = try agentforceClient.createAgentforceChatView( conversation: conversation, delegate: self, onContainerClose: { // Handle chat view close } ) // Present the chatView in your SwiftUI hierarchy } catch { // Handle error } ``` -------------------------------- ### AgentforceClient.createAgentforceChatView Parameters Source: https://github.com/salesforce/agentforcemobilesdk-ios/blob/main/README.md Details the parameters required for creating the Agentforce chat SwiftUI view. ```APIDOC createAgentforceChatView method parameters: - conversation: The AgentConversation object that you created earlier - delegate: An object that conforms to the AgentforceUIDelegate protocol. This delegate will receive notifications about UI events - onContainerClose: A closure that will be called when the user closes the chat view ``` -------------------------------- ### Create AgentforceConfiguration Instance in Swift Source: https://github.com/salesforce/agentforcemobilesdk-ios/blob/main/README.md Demonstrates how to create an instance of the `AgentforceConfiguration` struct, which is used to configure the Agentforce SDK with essential parameters like agent ID, organization ID, and Salesforce instance URL. ```Swift import AgentforceSDK let agentforceConfiguration = AgentforceConfiguration( agentId: "YOUR_AGENT_ID", // Replace with your Agent ID orgId: "YOUR_ORG_ID", // Replace with your Salesforce Org ID forceConfigEndpoint: "YOUR_INSTANCE_URL" // e.g. "https://your-domain.my.salesforce.com" ) ``` -------------------------------- ### AgentforceConfiguration Struct Reference Source: https://github.com/salesforce/agentforcemobilesdk-ios/blob/main/README.md Defines the configuration parameters for the Agentforce SDK, including required identifiers and optional protocol implementations for custom behavior. ```APIDOC AgentforceConfiguration struct parameters: - agentId: The unique identifier for your agent - orgId: Your Salesforce organization ID - forceConfigEndpoint: The URL of your Salesforce instance Optional protocol implementations: - dataProvider: Provide custom data to the agent - imageProvider: Provide custom images to the UI - agentforceCopier: Handle copy to clipboard functionality - instrumentationHandler: Receive detailed instrumentation events - salesforceNavigation: Handle navigation events - salesforceLogger: Provide a custom logger - ttsVoiceProvider: Provide a custom text-to-speech engine - speechRecognizer: Provide a custom speech-to-text engine ``` -------------------------------- ### Receive Messages from Agent in Swift Source: https://github.com/salesforce/agentforcemobilesdk-ios/blob/main/README.md Demonstrates how to subscribe to the `messages` publisher on the `AgentConversation` object to asynchronously receive and handle new messages sent from the agent. ```Swift conversation.messages .sink { messages in // Handle new messages } .store(in: &cancellables) ``` -------------------------------- ### Add Agentforce SDK Pod to Podfile Source: https://github.com/salesforce/agentforcemobilesdk-ios/blob/main/README.md Includes the AgentforceSDK pod in the project's target, allowing CocoaPods to manage its dependencies and integration. ```ruby pod 'AgentforceSDK' ``` -------------------------------- ### Configure CocoaPods Post-Install for Library Distribution Source: https://github.com/salesforce/agentforcemobilesdk-ios/blob/main/README.md Sets the 'BUILD_LIBRARY_FOR_DISTRIBUTION' build setting to 'YES' for all targets in the pods project during the post-install phase, which is required for proper library distribution. ```ruby post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| config.build_settings['BUILD_LIBRARY_FOR_DISTRIBUTION'] = 'YES' end end end ``` -------------------------------- ### Agentforce Mobile SDK Core Service Protocols Source: https://github.com/salesforce/agentforcemobilesdk-ios/blob/main/README.md Details the essential protocols that host applications must implement to integrate with and provide core functionalities to the Agentforce Mobile SDK, including authentication, networking, navigation, and logging. ```APIDOC AgentforceSDK Interfaces: AgentforceAuthCredentialProviding: Purpose: Supplies the SDK with the authentication token (e.g., OAuth 2.0 access token) required to communicate securely with Salesforce APIs. AgentforceInstrumentation: Purpose: A handler for the SDK to emit instrumentation and telemetry data into your app's analytics system. Salesforce Mobile Interfaces: SalesforceNetwork.Network: Purpose: Provides the SDK with the ability to make authenticated network calls to Salesforce. Your implementation will handle the underlying networking logic, leveraging your app's existing network stack, and will be responsible for attaching the necessary authentication tokens to each request. SalesforceNavigation.Navigation: Purpose: Handles navigation requests from the agent. For example, if the agent provides a link to a specific record, this interface allows your app to intercept that request and navigate the user to the appropriate screen within your native application. SalesforceLogging.Logger: Purpose: Allows the SDK to pipe its internal logs into your application's logging system for easier debugging and monitoring. ``` -------------------------------- ### Instantiate AgentforceClient for Full UI Experience in Swift Source: https://github.com/salesforce/agentforcemobilesdk-ios/blob/main/README.md Shows how to create and retain an instance of `AgentforceClient` within an `ObservableObject`. This client manages the session and requires configuration and implementations of core service protocols. It must be retained for the conversation's duration. ```Swift import AgentforceSDK class AgentforceManager: ObservableObject { let agentforceClient: AgentforceClient init() { // Initialize with your config and protocol implementations let config = AgentforceConfiguration(...) let credentialProvider = MyAppCredentialProvider(...) let networkProvider = MyAppNetworkProvider(...) let contextProvider = MyAppContextProvider(...) self.agentforceClient = AgentforceClient( credentialProvider: credentialProvider, agentforceConfiguration: config, contextProvider: contextProvider, network: networkProvider ) } } ``` -------------------------------- ### Configure CocoaPods Spec Repos for Agentforce SDK Source: https://github.com/salesforce/agentforcemobilesdk-ios/blob/main/README.md Adds the Salesforce Mobile iOS Spec Repo and CocoaPods CDN to the Podfile, which are necessary for resolving Agentforce SDK dependencies. ```ruby source 'https://github.com/forcedotcom/SalesforceMobileSDK-iOS-Specs.git' source 'https://cdn.cocoapods.org/' ``` -------------------------------- ### Implement Instrumentation with AgentforceInstrumentationHandling Source: https://github.com/salesforce/agentforcemobilesdk-ios/blob/main/README.md The Agentforce SDK offers a detailed instrumentation framework. By implementing the AgentforceInstrumentationHandling protocol, developers can receive and process instrumentation events to monitor performance and usage within their application. ```APIDOC AgentforceInstrumentationHandling protocol: - recordEvent(_ event: AgentforceInstrumentationEvent): Handles incoming instrumentation events. ``` ```Swift class MyInstrumentationHandler: AgentforceInstrumentationHandling { func recordEvent(_ event: AgentforceInstrumentationEvent) { // Handle instrumentation events print("Instrumentation event: \(event)") } } // Include in your config let agentforceConfiguration = AgentforceConfiguration( agentId: "YOUR_AGENT_ID", orgId: "YOUR_ORG_ID", forceConfigEndpoint: "YOUR_INSTANCE_URL", instrumentationHandler: MyInstrumentationHandler() ) ``` -------------------------------- ### Send Messages to Agent in Swift Source: https://github.com/salesforce/agentforcemobilesdk-ios/blob/main/README.md Shows how to send a text message to the agent using the `sendUtterance` method available on the `AgentConversation` object, with an option for an attachment. ```Swift await conversation.sendUtterance(utterance: "Hello, world!", attachment: nil) ``` -------------------------------- ### Provide Custom Views with AgentforceViewProviding Source: https://github.com/salesforce/agentforcemobilesdk-ios/blob/main/README.md The AgentforceViewProviding protocol enables developers to supply custom views for components displayed in the chat interface. This is useful for replacing default component implementations with custom UI, such as a custom rich text view. ```APIDOC AgentforceViewProviding protocol: - canHandle(type:): Returns true if a custom view should be provided for the given component type. - view(for:data:): Returns the custom view for the specified component type, using provided data. ``` ```Swift import AgentforceSDK import SwiftUI class CustomViewProvider: AgentforceViewProviding { func canHandle(type: String) -> Bool { return type == "AF_RICH_TEXT" } @MainActor func view(for type: String, data: [String : Any]) -> AnyView { if type == "AF_RICH_TEXT" { let value = data["value"] as? String ?? "" return AnyView(Text(value).font(.custom("YourFont", size: 16))) } return AnyView(EmptyView()) } } ``` ```Swift let agentforceClient = AgentforceClient( credentialProvider: yourCredentialProvider, agentforceConfiguration: agentforceConfiguration, viewProvider: CustomViewProvider() ) ``` -------------------------------- ### Handle UI Events with AgentforceUIDelegate Source: https://github.com/salesforce/agentforcemobilesdk-ios/blob/main/README.md The AgentforceUIDelegate protocol allows developers to intercept and modify UI-related events within the Agentforce SDK. This includes modifying utterances before they are sent, handling utterances after they have been sent, and responding to user-initiated agent switches. ```APIDOC AgentforceUIDelegate protocol: - modifyUtteranceBeforeSending(_:): Called before an utterance is sent to the agent. Allows modification. - didSendUtterance(_:): Called after an utterance has been sent to the agent. - userDidSwitchAgents(newConversation:): Called when the user switches to a different agent. ``` ```Swift extension YourViewController: AgentforceUIDelegate { func modifyUtteranceBeforeSending(_ utterance: AgentforceUtterance) async -> AgentforceUtterance { // Modify the utterance if needed return utterance } func didSendUtterance(_ utterance: AgentforceUtterance) { // Handle sent utterance } func userDidSwitchAgents(newConversation: AgentConversation) { // Handle agent switch } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.