Populate Pre-Chat Form Fields for iOS

When customers start a messaging conversation, you sometimes already know basic information such as their name, email address, and what product they're looking at. You can set up a pre-chat form in the UI with visible fields such as name, email address, and product name. Then use the SDK to populate the pre-chat fields with this information so it appears when the user first opens the pre-chat form.

This feature requires version 1.5.0 or later of the Messaging for In-App SDK.

This article applies to the following implementations:

UI SDKCore SDK

Before you use the SDK, add the visible fields to the pre-chat form. See Customize Pre-Chat for Messaging for In-App and Web in Salesforce Help.

After you add the visible fields to the pre-chat form, you can populate these values by using the SDK.

  1. To populate known values in the pre-chat fields, implement preChatFieldValueProvider.
  2. Add your provider to the SDK by using init in the Interface.swift file.
  3. To modify the pre-chat fields, create a setPreChatValues function.
  4. To make the pre-chat fields editable, set isEditable to true. To make the pre-chat fields non-editable, set isEditable to false.

If you configure the pre-populated fields to be non-editable, make sure that the pre-chat form fields follow the validation rules. If a required field exceeds the character limit or is set to an invalid data type, the createConversation flow stops and the form isn't submitted. In these cases, the SDK logs error messages in the developer console.