The agent can request that the user transfer a file by clicking the Attach File button from the Service Cloud Console.
See Transfer Files During a Chat in Salesforce Help for details about setting up this functionality in the Service Cloud Console.
With the default UI, the user sees a FILE TRANSFER REQUESTED message in the app and can then send a file using the camera button.
If you're using the default UI, no coding is necessary in your app to get this behavior.
However, if you're using the Core API, you must present your own file transfer UI based on file transfer events. Create a FileTransferRequestListener and pass it to the ChatClient using the addFileTransferRequestListener method. This listener gives you access to two events.
- onFileTransferRequest
- The SDK calls this method when an agent requests a file transfer. You're given a FileTransferAssistant object, which lets you upload a file with the uploadFile method.
- onFileTransferStatusChanged
- The SDK calls this method when the status of a file transfer has changed. You're given a FileTransferStatus enumerated type that describes the status of the file transfer.
You can use the following code sample as a starting point for your listener implementation.
In Java:
class MyFileTransferRequestListener implements FileTransferRequestListener { private byte[] uploadFile = new byte[]; // TO DO: File to upload private String fileType = "image/png"; // TO DO: File type @Override public void onFileTransferRequest (FileTransferAssistant fileTransferAssistant) { // TO DO: Prompt user and read the file from storage fileTransferAssistant.uploadFile(uploadFile, fileType); } @Override public void onFileTransferStatusChanged (FileTransferStatus status) { switch (status) { case Completed: // TO DO: File transfer completed break; case Canceled: // TO DO: File transfer canceled break; case Failed: // TO DO: File transfer failed break; case LocalError: // TO DO: Local error with transfer break; case Requested: // TO DO: File transfer requested // NOTE: You'll also get a call to // onFileTransferRequest during this state, // where you can handle the request and // then upload a file... break; } } }
In Kotlin:
class MyFileTransferRequestListener : FileTransferRequestListener { var uploadFile = ByteArray(32768) // TO DO: File to upload var fileType: String = "image/png" // TO DO: File type override fun onFileTransferRequest(fileTransferAssistant: FileTransferAssistant?) { // TO DO: Prompt user and read the file from storage fileTransferAssistant?.uploadFile(uploadFile, fileType) } override fun onFileTransferStatusChanged(status: FileTransferStatus?) { when (status) { FileTransferStatus.Completed -> { // TO DO: File transfer completed } FileTransferStatus.Canceled -> { // TO DO: File transfer canceled } FileTransferStatus.Failed -> { // TO DO: File transfer failed } FileTransferStatus.LocalError -> { // TO DO: Local error with transfer } FileTransferStatus.Requested -> { // TO DO: File transfer requested // NOTE: You'll also get a call to // onFileTransferRequest during this state, // where you can handle the request and // then upload a file... } } } }