send

Sends a message and optionally notifies the client about the message being processed or sent.

If the message has been processed but not sent within a reasonable amount of time, the client is permitted to retry.

Execution (processing) of a given message is immediately moved to a background thread, though listener will always be invoked on a foreground thread.

Note that messages with no test, attachments, or postback specified will be silently ignored.

If you are supplying attachments for upload, then be aware of the following.

  • If attachment misses file name, the file is named to "document" upon being sent to the server. Please take care to provide localized file names if you want to display them to the user.

  • The upload of files is performed at most once before subsequent processing of the message and sending it to the server. If the file call succeeds, it's cached internally to avoid doubling uploads. Therefore, subsequent calls (if the primary were to fail) are much faster. Also, if the user tries to send the same attachment again, it will not be uploaded again instead it's referenced by the origin upload. This cache is active as long as the ChatBuilder instance remains the same. Reinitializing the Chat doesn't clear the cache.

  • If any upload of any attachment fails by connection error, listener will not be invoked for even processing triggers. The error is passed to the ChatStateListener.onChatRuntimeException as an instance of com.nice.cxonechat.exceptions.RuntimeChatException.AttachmentUploadError with information about the failed attachment upload.

  • If any upload of any attachment fails by server error (returns but an empty body), then the attachment is skipped, and execution continues.

Parameters

message

Message to be sent.

listener

listener to be notified when the message has been sent.

Throws

InvalidParameterException

if the message is empty, ie., has no attachment, message, or postback.


open fun send(message: String, postback: String? = null, listener: ChatThreadMessageHandler.OnMessageTransferListener? = null)

Simplified method to send a simple user message to the agent.

Parameters

message

message to send to agent.

postback

optional "postback" to send with attachments.

listener

listener to be invoked when the message has been sent

See also


open fun send(attachments: Iterable<ContentDescriptor>, message: String = "", postback: String? = null, listener: ChatThreadMessageHandler.OnMessageTransferListener? = null)

Simplified method to send an attachment to the agent.

Parameters

attachments

attachments to send.

message

optional message to send with attachments.

postback

optional "postback" to send with attachments.

listener

listener to be invoked when the message has been sent

See also