📄 chatbot.java
字号:
/**
* Returns the message to send to the user when the user asks to leave the waiting queue.
*
* @return the message to send to the user when the user asks to leave the waiting queue.
*/
private String getDepartureConfirmedMessage() {
return settings.getChatSetting(KeyEnum.departure_confirmed_message).getValue();
}
/**
* Returns the message to inform the user that the requested command cannot be processed.
*
* @return the message to inform the user that the requested command cannot be processed.
*/
private String getNotAcceptableMessage() {
return settings.getChatSetting(KeyEnum.not_acceptable_message).getValue();
}
/**
* Returns the message to inform the user that he is not in a waiting queue yet. This message
* may be sent to the user if the user sent a "position" command and the user is not in the
* queue yet.
*
* @return the message to inform the user that he is not in a waiting queue yet.
*/
private String getNotInQueueMessage() {
return settings.getChatSetting(KeyEnum.not_in_queue_message).getValue();
}
/**
* Returns the message to send to the user informing that the workgroup is currently closed.
*
* @return the message to send to the user informing that the workgroup is currently closed.
*/
private String getWorkgroupClosedMessage() {
return settings.getChatSetting(KeyEnum.workgroup_closed_message).getValue();
}
/**
* Returns the message to send to the user informing that the user is not allowed to join
* the queue. This may happen because the workgroup is closed or the specific user cannot join
* due to some restriction policy.
*
* @return the message to send to the user informing that the user is not allowed to join
* the queue.
*/
private String getCannotJoinMessage() {
return settings.getChatSetting(KeyEnum.cannot_join_message).getValue();
}
/**
* Returns the message to send to the user asking if he wants to receive the chat transcript
* by email.
*
* @return the message to send to the user asking if he wants to receive the chat transcript
* by email.
*/
private String getSendEmailQuestion() {
return settings.getChatSetting(KeyEnum.send_email_question).getValue();
}
/**
* Returns the message to send to the user informing that he is now being routed to an agent.
*
* @return the message to send to the user informing that he is now being routed to an agent.
*/
private String getInvitationSentMessage() {
return settings.getChatSetting(KeyEnum.invitation_sent_message).getValue();
}
/**
* Returns the message to send to the user asking if he wants to receive again the room
* invitation.
*
* @return the message to send to the user asking if he wants to receive again the room
* invitation.
*/
private String getSendInvitationQuestion() {
return settings.getChatSetting(KeyEnum.send_invitation_question).getValue();
}
/**
* Returns the message that will ask the user for his email address so that the chatbot can
* send the chat transcript by email. This question will only be made if the user hasn't
* entered an email address before (that means that the form is not asking for an email).
*
* @return the message that will ask the user for his email address so that the chatbot can
* send the chat transcript by email.
*/
private String getGetEmailQuestion() {
return settings.getChatSetting(KeyEnum.send_get_email_question).getValue();
}
/**
* Returns the message to send to the user informing that the invitation was sent again.
*
* @return the message to send to the user informing that the invitation was sent again.
*/
private String getInvitationResentMessage() {
return settings.getChatSetting(KeyEnum.invitation_resent_message).getValue();
}
/**
* Returns the message to send to the user informing that the chat transcript was sent by email.
*
* @return the message to send to the user informing that the chat transcript was sent by email.
*/
private String getEmailSentMessage() {
return settings.getChatSetting(KeyEnum.email_sent_message).getValue();
}
/**
* Returns the message that describes the effect of running the <b>back</b> command.
*
* @return the message that describes the effect of running the <b>back</b> command.
*/
private String getBackHelpMessage() {
return settings.getChatSetting(KeyEnum.back_help_message).getValue();
}
/**
* Returns the message that describes the effect of running the <b>repeat</b> command.
*
* @return the message that describes the effect of running the <b>repeat</b> command.
*/
private String getRepeatHelpMessage() {
return settings.getChatSetting(KeyEnum.repeat_help_message).getValue();
}
/**
* Returns the message that describes the effect of running the <b>help</b> command.
*
* @return the message that describes the effect of running the <b>help</b> command.
*/
private String getHelpHelpMessage() {
return settings.getChatSetting(KeyEnum.help_help_message).getValue();
}
/**
* Returns the message that describes the effect of running the <b>bye</b> command.
*
* @return the message that describes the effect of running the <b>bye</b> command.
*/
private String getByeHelpMessage() {
return settings.getChatSetting(KeyEnum.bye_help_message).getValue();
}
/**
* Returns the message that describes the effect of running the <b>position</b> command.
*
* @return the message that describes the effect of running the <b>position</b> command.
*/
private String getPositionHelpMessage() {
return settings.getChatSetting(KeyEnum.position_help_message).getValue();
}
/**
* Returns the string that indicates that the user is requesting to go back one step in
* the dialog and repeat the previous message.
*
* @return the string that indicates that the user is requesting to go back one step in
* the dialog and repeat the previous message.
*/
private String getBackCommand() {
return settings.getChatSetting(KeyEnum.back_command).getValue();
}
/**
* Returns the string that indicates that the user is requesting to repeat the last message.
* This may happen if for instance the user closed his chat window by mistake.
*
* @return the string that indicates that the user is requesting to repeat the last message.
*/
private String getRepeatCommand() {
return settings.getChatSetting(KeyEnum.repeat_command).getValue();
}
/**
* Returns the string that indicates that the user is requesting the list of available commands.
*
* @return the string that indicates that the user is requesting the list of available commands.
*/
private String getHelpCommand() {
return settings.getChatSetting(KeyEnum.help_command).getValue();
}
/**
* Returns the string that indicates that the user is closing the chat session no matter
* the if he already joined a waiting queue or not. If the user joined a waiting queue then
* the user will leave the queue.
*
* @return the string that indicates that the user is closing the chat session no matter
* the if he already joined a waiting queue or not.
*/
private String getByeCommand() {
return settings.getChatSetting(KeyEnum.bye_command).getValue();
}
/**
* Returns the string that indicates that the user wants to know his position in the
* waiting queue. If the user is not in the waiting queue then send the "notInQueueMessage"
* message.
*
* @return the string that indicates that the user wants to know his position in the
* waiting queue.
*/
private String getPositionCommand() {
return settings.getChatSetting(KeyEnum.position_command).getValue();
}
/**
* Removes idle sessions. After a session has been removed, if a user sends a message to the
* chatbot then the script will start from scratch. Therefore, all the stored information
* in the session will be lost.
*/
public void cleanup() {
final long deadline = System.currentTimeMillis() - getIdleTimeout();
for (ChatbotSession session : sessions.values()) {
// Do not clean up sessions whose users are having a chat with an agent.
if (!session.isStartedSupport() && session.getLastActiveDate().getTime() < deadline) {
ComponentManagerFactory.getComponentManager().getLog().debug("Removing idle chat " +
"session for: " +
session.getUserJID());
removeSession(session.getUserJID());
}
}
}
/**
* Sets the time to wait before considering an idle session candidate to be removed.
*
* @param timeout the number of milliseconds that a session must be idle.
*/
public void setIdleTimeout(long timeout) {
try {
workgroup.getProperties().setProperty("chatbot.session.timeout",
String.valueOf(timeout));
}
catch (UnauthorizedException e) {
ComponentManagerFactory.getComponentManager().getLog().error("Error setting timeout",
e);
}
}
/**
* Returns the milliseconds that a session must be idle to be considered candidate for removal.
*
* @return the milliseconds that a session must be idle to be considered candidate for removal.
*/
public long getIdleTimeout() {
long timeout = 30 * 60 * 1000;
try {
timeout =Long.parseLong(workgroup.getProperties().getProperty(
"chatbot.session.timeout"));
}
catch (NumberFormatException e) {
// Ignore.
}
return timeout;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -