This page was last edited on October 12, 2018, at 19:56.
Comments or questions about this documentation? Contact us for support!
The page describes how to implement file transfer (uploading and downloading) in custom agent desktop application using Platform SDK (supported from version 8.5.201.00). For high-level overview of file transfer in Chat Solution please refer to File Transfer in Chat Solutions.
It is important to understand the following general concepts about file transfer in Chat Solution:
Agent desktop application can perform the following operations:
In code samples, it is assumed that connection objects to UCS and Chat Server are initialized with the proper connection parameters, and that Chat Server basic protocol user has registered and joined the session.
The following code snippet demonstrates how to upload a file:
// Prepare connections
BasicChatProtocol chatConnection = ...;
UniversalContactServerProtocol ucsConnection = ...;
// Uploading file into UCS
RequestAddDocument docReq = RequestAddDocument.Create();
// mime-type is mandatory, however not verified by UCS or Chat Server.
docReq.MimeType = "application/octet-stream";
docReq.Content = File.ReadAllBytes("C:\\myfile.txt");
docReq.TheName = "myfile.txt";
docReq.TheSize = docReq.Content.Length;
IMessage addDocReply = ucsConnection.Request(docReq);
EventAddDocument addDocEvent = addDocReply as EventAddDocument;
// Sending notification in chat session
RequestNotify fileReq = RequestNotify.Create();
fileReq.SessionId = ...;
fileReq.NoticeText = NoticeText.Create(NoticeType.SystemCommand, "file-uploaded");
fileReq.UserData = new KeyValueCollection();
fileReq.UserData.Add("file-name", docReq.TheName); // mandatory
fileReq.UserData.Add("file-size", docReq.TheSize); // mandatory
fileReq.UserData.Add("file-source", "ucs"); // mandatory
fileReq.UserData.Add("file-document-id", addDocEvent.DocumentId); // mandatory for UCS
fileReq.UserData.Add("file-upload-type", "file-system"); // optional
fileReq.UserData.Add("file-description", "Sample text file."); // optional
IMessage fileUploadedReply = chatConnection.Request(fileReq);
Below is the description of input parameters which must be provided in the “file-uploaded” notice request to Chat Server.
Name | Mandatory | Description |
---|---|---|
file-name | Yes | File name including extension. |
file-size | Yes | File size in bytes. |
file-source | Yes | File storage type. Currently supported values by Genesys Solution (but not limited by Chat Server itself):
|
file-document-id | Yes only for file-source=“ucs" | Document Id in UCS. |
file-upload-type |
Optional | Values used by Genesys Interaction Workspace:
|
<any additional parameters> | Optional | Could be used by application logic. |
The following code snippet demonstrates how to download file:
// Prepare connections
UniversalContactServerProtocol ucsConnection = ...;
// Download file from UCS
RequestGetDocument docReq = RequestGetDocument.Create();
docReq.DocumentId = ...; // obtain from chat transcript event userdata
IMessage getDocReply = ucsConnection.Request(docReq);
// Saving file in filesystem
EventGetDocument getDocEvent = getDocReply as EventGetDocument;
string filePath = Path.Combine("C:\\", getDocEvent.TheName);
File.WriteAllBytes(filePath, getDocEvent.Content);