📄 chatsettingscreator.java
字号:
bytes = new byte[(int)image.length()];
int read = stream.read(bytes);
if (read != bytes.length) {
throw new IOException("Failed to read all image bytes.");
}
stream.close();
final String encodedFile = StringUtils.encodeBase64(bytes);
createImageChatSetting(workgroupJID, key,
ChatSettings.SettingType.image_settings, encodedFile);
}
catch (IOException e) {
ComponentManagerFactory.getComponentManager().getLog().error(e);
}
}
}
}
/**
* Adds the default text settings to the database.
*
* @param workgroupJID - the JID of the workgroup to setup.
*/
private void createTextSettings(JID workgroupJID) {
for (KeyEnum key : textMap.keySet()) {
String value = textMap.get(key);
createChatSetting(workgroupJID, key, ChatSettings.SettingType.text_settings, value);
}
}
/**
* Adds the default bot settings to the database.
*
* @param workgroupJID - the JID of the workgroup to setup.
*/
private void createBotSettings(JID workgroupJID) {
try {
// Enable the workgroup chatbot by default
Workgroup workgroup = WorkgroupManager.getInstance().getWorkgroup(workgroupJID);
workgroup.chatbotEnabled(true);
for (KeyEnum key : botMap.keySet()) {
String value = botMap.get(key);
createChatSetting(workgroupJID, key, ChatSettings.SettingType.bot_settings, value);
}
}
catch (UserNotFoundException e) {
ComponentManagerFactory.getComponentManager().getLog().error(e);
}
catch (UnauthorizedException e) {
ComponentManagerFactory.getComponentManager().getLog().error(e);
}
}
private void createChatSetting(JID workgroupJID, KeyEnum key, ChatSettings.SettingType type,
final String value) {
ChatSetting setting = new ChatSetting(key);
setting.setWorkgroupNode(workgroupJID.getNode());
setting.setType(type);
setting.setValue(value);
setting.setDefaultValue(value);
String label = labelMap.get(key);
if (!ModelUtil.hasLength(label)) {
label = "";
}
String description = descriptions.get(label);
if (!ModelUtil.hasLength(description)) {
description = descriptions.get(key.toString());
}
if (!ModelUtil.hasLength(description)) {
description = "";
}
setting.setDescription(description);
setting.setLabel(label);
chatSettingsManager.addChatSetting(setting);
}
private void createImageChatSetting(JID workgroupJID, KeyEnum key,
ChatSettings.SettingType type, final String value)
{
ChatSetting setting = new ChatSetting(key);
setting.setWorkgroupNode(workgroupJID.getNode());
setting.setType(type);
setting.setValue(value);
setting.setDefaultValue("");
String label = labelMap.get(key);
if (!ModelUtil.hasLength(label)) {
label = "";
}
String description = descriptions.get(label);
if (!ModelUtil.hasLength(description)) {
description = descriptions.get(key.toString());
}
if (!ModelUtil.hasLength(description)) {
description = "";
}
setting.setDescription(description);
setting.setLabel(label);
chatSettingsManager.addChatSetting(setting);
}
/**
* Add default settings to a workgroup.
*
* @param workgroupJID the full-jid of the workgroup.
*/
public void createDefaultSettings(JID workgroupJID) {
final XStream xstream = new XStream();
xstream.alias("ChatSettings", ChatSettings.class);
xstream.alias("Key", KeyEnum.class);
xstream.alias("Setting", ChatSetting.class);
createImageSettings(workgroupJID);
createTextSettings(workgroupJID);
createBotSettings(workgroupJID);
}
public void createDefaultSetting(JID workgroupJID, KeyEnum key) {
if (imageMap.containsKey(key)) {
String value = imageMap.get(key);
InputStream stream = getClass().getResourceAsStream("fastpath/imageMap/" + value);
if (stream == null) {
stream = getClass().getResourceAsStream("/fastpath/imageMap/" + value);
}
if (stream == null) {
stream = getClass().getResourceAsStream("/fastpath/images/" + value);
}
if (stream != null) {
byte[] bytes;
try {
bytes = new byte[stream.available()];
int read = stream.read(bytes);
if (read != bytes.length) {
throw new IOException("Failed to read all bytes.");
}
stream.close();
final String encodedFile = StringUtils.encodeBase64(bytes);
createChatSetting(workgroupJID, key, ChatSettings.SettingType.image_settings,
encodedFile);
}
catch (IOException e) {
ComponentManagerFactory.getComponentManager().getLog().error(e);
}
}
}
else if (textMap.containsKey(key)) {
String value = textMap.get(key);
createChatSetting(workgroupJID, key, ChatSettings.SettingType.text_settings, value);
}
else if (botMap.containsKey(key)) {
String value = botMap.get(key);
createChatSetting(workgroupJID, key, ChatSettings.SettingType.bot_settings, value);
}
}
private void populateTextMap() {
textMap.put(KeyEnum.user_input_page_title, "<b>Start a Live Chat</b><p>Enter your name and all required information.</p>");
labelMap.put(KeyEnum.user_input_page_title, "User Input Page Greeting");
descriptions.put(KeyEnum.user_input_page_title.toString(), "The user information text displayed at the top of the page.");
textMap.put(KeyEnum.start_chat_button, "Start Chat");
labelMap.put(KeyEnum.start_chat_button, "Start Chat Button");
descriptions.put(KeyEnum.start_chat_button.toString(), "Text to display on the button to put user into a queue.");
textMap.put(KeyEnum.queue_title_text, "<b>Routing Your Request...</b><p>Your chat request is being routed. You can cancel your request by clicking \"Close Window\" below.</p>");
labelMap.put(KeyEnum.queue_title_text, "Title Text In Queue Page");
descriptions.put(KeyEnum.queue_title_text.toString(), "Text displayed to user while they are waiting in the queue.");
textMap.put(KeyEnum.queue_description_text, "<div style=\"border:1px #ccc solid; background-color:#ffe;padding:3px;\"><table border=\"0\"><tr><td><img src=\"images/busy.gif\"></td><td>" +
"You are currently number ${position} in the queue. It is estimated that your wait time will be ${waitTime}.</td></tr></table></div>");
labelMap.put(KeyEnum.queue_description_text, "Queue Position Text");
descriptions.put(KeyEnum.queue_description_text.toString(), "Notifies user of their position in the queue and their estimated wait time.");
textMap.put(KeyEnum.queue_footer_text, "Please stand by, or you can <a href=\"javascript:showLeaveAMessage()\">leave a message</a>.");
labelMap.put(KeyEnum.queue_footer_text, "Queue Footer Text");
descriptions.put(KeyEnum.queue_footer_text.toString(), "Footer text seen in queue.");
textMap.put(KeyEnum.no_agent_text, "We are unable to route your request at this time. To leave a message or request a call back <a href=\"javascript:showLeaveAMessage()\">click here</a>.");
labelMap.put(KeyEnum.no_agent_text, "No Agent Available");
descriptions.put(KeyEnum.no_agent_text.toString(), "Message seen when no agent was able to take the request.");
textMap.put(KeyEnum.accepted_chat_text, "You are now chatting with ${agent}");
labelMap.put(KeyEnum.accepted_chat_text, "Chat Room Greeting");
descriptions.put(KeyEnum.accepted_chat_text.toString(), "The message to display to the user when they first join the room.");
textMap.put(KeyEnum.transferred_chat_text, "Your conversation is being transferred to another agent.");
labelMap.put(KeyEnum.transferred_chat_text, "Agent Transfer Message");
descriptions.put(KeyEnum.transferred_chat_text.toString(), "Message displayed to the user when an agent transfers their chat to another agent.");
textMap.put(KeyEnum.agent_invite_text, "Inviting another agent to the conversation. Please wait.");
labelMap.put(KeyEnum.agent_invite_text, "Agent Invitation Message");
descriptions.put(KeyEnum.agent_invite_text.toString(), "Message displayed to the user when the agent invites another agent into the conversation");
/*
textMap.put(KeyEnum.chat_disconnected_text, "Your chat session has ended");
labelMap.put(KeyEnum.chat_disconnected_text, "Chat session has ended");
*/
textMap.put(KeyEnum.agent_ends_chat_text, "Your chat session has been ended by ${agent}");
labelMap.put(KeyEnum.agent_ends_chat_text, "Agent ends the conversation");
descriptions.put(KeyEnum.agent_ends_chat_text.toString(), "Message displayed to user when their session has been closed by the agent.");
textMap.put(KeyEnum.transcript_text, "Thank you for chatting with us. Enter your email address below to have a copy of the transcript mailed to you.");
labelMap.put(KeyEnum.transcript_text, "Message displayed on transcript email page");
descriptions.put(KeyEnum.transcript_text.toString(), "Message displayed to the user on the email transcript page.");
textMap.put(KeyEnum.transcript_sent_text, "The transcript has been sent. Thank you for chatting with us.");
labelMap.put(KeyEnum.transcript_sent_text, "Transcript Sent Message");
descriptions.put(KeyEnum.transcript_sent_text.toString(), "Message displayed to user when their transcript has been sent successfully");
textMap.put(KeyEnum.transcript_not_sent_text, "The transcript could not be sent. We are sorry for the inconvience");
labelMap.put(KeyEnum.transcript_not_sent_text, "Transcript Send Error");
descriptions.put(KeyEnum.transcript_not_sent_text.toString(), "Message displayed when a transcript could not be sent.");
textMap.put(KeyEnum.no_help, "<b>Live Chat Not Available</b><p>Sorry we were not available to handle your request. Please try again later.</p>");
labelMap.put(KeyEnum.no_help, "No Help Available");
descriptions.put(KeyEnum.no_help.toString(), "Message displayed when no agent is online and offline settings is not configured.");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -