//UI Console testing commands. Open the browser console (F12) and paste these into the console to test the UI appearance without opening a chat.

// 1. set up details here
var agentName = 'Dr Samuel Gall';
var custName = 'Graf Otto Bernd Thomas von Schtickschtock';
webChat.g_user = custName;
webChat.chatBotName = 'Assistant';

// 2. source: http://stackoverflow.com/a/1732454/3861543
var customerMessage = 'This is a customer message. You can edit the style by changing the p.sent entry in style.css. T� m� sa chist�n, agus n�l beoir ar bith i mo chuisneoir! This is a test. Don\'t try using regex to parse HTML! Messages should wrap around. I think this is working.'

// 3. open UI panel
chatUI.changeToChatMode();

// 4. test system message
webChat.writeResponse('This is a system message. The style for this message type is defined by the p.system entry in style.css', chatConfig.writeResponseClassSystem);
webChat.writeResponse('Agent timestamps use the p.agentDate class. This results in them being right-aligned in bold italics', chatConfig.writeResponseClassSystem);
webChat.writeResponse('Web-On-Hold messages and URLs are treated as system messages. If you want them to appear as agent messages, edit the playWebOnHoldMessages method inside webChat.js', chatConfig.writeResponseClassSystem)

// 5. send an agent message. In this case, I am skipping the low-level handleMessage() method in webChatSocket.js
var date = new Date().valueOf();
var agentChatMessage = { 'method' : 'newMessage', 'message' : 'Testing agent chat message. This uses the p.response class', 'displayName' : agentName, 'timestamp' : date - 9000 };
webChat.notifyNewMessage(agentChatMessage);

// 6. simulate a page push message
var pagePushMessage = { 'method':  'newPushPageMessage', 'displayName' : agentName, 'senderType' : 'LIVE_AGENT', 'pagePushURL' : 'https://confluence.forge.avaya.com/display/OCPROVIDER/Customer+WebSocket+API#CustomerWebSocketAPI-PagePushNotification', 'pagePushDestination' : 'newTab', 'timestamp' : date - 7000 };
webChat.notifyNewPagePushMessage(pagePushMessage);
var pagePushMessage = { 'method':  'newPushPageMessage', 'displayName' : webChat.chatBotName, 'senderType' : 'BOT', 'pagePushURL' : 'https://confluence.forge.avaya.com/display/OCPROVIDER/Customer+WebSocket+API#CustomerWebSocketAPI-PagePushNotification', 'pagePushDestination' : 'newTab', 'timestamp' : date - 7000 };
webChat.notifyNewPagePushMessage(pagePushMessage);


// 7. test chatbot
webChat.writeResponse('Testing a chatbot message next. The actual name would be assigned when the chatbot joins the room; to change the name, you need to configure AutomationController in System Manager to use a different name', chatConfig.writeResponseClassSystem);
var chatBotMessage = { 'method' : 'newMessage', 'message' : 'Testing chatbot message. If you want to change the style, edit the p.chatbot entry in style.css', 'displayName' : webChat.chatBotName, 'senderType' : 'BOT', 'timestamp' : date - 5000 };
webChat.notifyNewMessage(chatBotMessage);


// 8. simulate a customer chat message. The second line will throw a TypeError about "webSocket is undefined" - this is expected.
webChat.writeResponse('Testing customer messages next. Customer messages require a WebSocket to be opened, so the console will throw an exception about "webSocket is undefined". This is expected', chatConfig.writeResponseClassSystem);
webChat.outMessage.value = customerMessage;
webChat.sendChatMessage();


// 9. Test Supervisor observes and Agent drops the contact
// First perform steps 1, 3
var agentJoinEvent = {"method":"newParticipant", "agentId":"cpagentone_OCP ChatRoutableAddress", "displayName":"Agent", "role":"active_participant", "webOnHoldComfortGroup":[{"messages":[]}], "numberOfParticipants":1, "participants":[{"id":"cpagentone_OCP ChatRoutableAddress", "name":"Agent", "type":"active_participant"}]};
var supervisorJoinEvent = {"method":"newParticipant", "agentId":"cpagentfour_OCP ChatRoutableAddress", "displayName":"Agent", "role":"supervisor_observe", "webOnHoldComfortGroup":[{"messages":[]}], "numberOfParticipants":2, "participants":[{"id":"cpagentone_OCP ChatRoutableAddress", "name":"Agent", "type":"active_participant"}, {"id":"cpagentfour_OCP ChatRoutableAddress", "name":"Agent", "type":"supervisor_observe"}]};
var agentLeaveEvent = {"method":"participantLeave", "agentId":"cpagentone_OCP ChatRoutableAddress", "endChatFlag":true, "numberOfParticipants":0, "participants":[], "leaveReason":"default"};
var supervisorLeaveEvent = {"method":"participantLeave", "agentId":"cpagentfour_OCP ChatRoutableAddress", "endChatFlag":true, "numberOfParticipants":0, "participants":[], "leaveReason":"default"}
webChat.notifyNewParticipant(agentJoinEvent);
webChat.notifyNewParticipant(supervisorJoinEvent);
// Agent leaves
webChat.notifyParticipantLeave(agentLeaveEvent);
webChat.notifyParticipantLeave(supervisorLeaveEvent);


// 10. Test Supervisor Coaches and Agent drops the contact
// First perform steps 1, 3
// Agent joins
var agentJoinEvent = {"method":"newParticipant", "agentId":"cpagentone_OCP ChatRoutableAddress", "numberOfParticipants":1, "displayName":"Agent", "role":"active_participant", "webOnHoldComfortGroup":[{"messages":[]}], "participants":[{"id":"cpagentone_OCP ChatRoutableAddress", "name":"Agent", "type":"active_participant"}]}
webChat.notifyNewParticipant(agentJoinEvent)
// Supervisor joins (Observer -> Coach)
var supervisorJoinEvent = {"method":"newParticipant", "agentId":"cpagentfour_OCP ChatRoutableAddress", "numberOfParticipants":2, "displayName":"Agent", "role":"supervisor_observe", "webOnHoldComfortGroup":[{"messages":[]}], "participants":[{"id":"cpagentone_OCP ChatRoutableAddress", "name":"Agent", "type":"active_participant"},{"id":"cpagentfour_OCP ChatRoutableAddress", "name":"Agent", "type":"supervisor_observe"}]}
webChat.notifyNewParticipant(supervisorJoinEvent)
var supervisorCoachJoinEvent = {"method":"newParticipant", "agentId":"cpagentfour_OCP ChatRoutableAddress", "numberOfParticipants":2, "displayName":"Agent", "role":"supervisor_coach", "webOnHoldComfortGroup":[{"messages":[]}], "participants":[{"id":"cpagentone_OCP ChatRoutableAddress", "name":"Agent", "type":"active_participant"},{"id":"cpagentfour_OCP ChatRoutableAddress", "name":"Agent", "type":"supervisor_coach"}]}
webChat.notifyNewParticipant(supervisorCoachJoinEvent)
// Agent drops the contact
var agentLeaveEvent_1  = {"method":"participantLeave", "leaveReason":"default", "agentId":"cpagentone_OCP ChatRoutableAddress", "endChatFlag":true, "numberOfParticipants":0, "participants":[]}
webChat.notifyParticipantLeave(agentLeaveEvent_1)
var agentLeaveEvent_2  = {"method":"participantLeave", "leaveReason":"default", "agentId":"cpagentone_OCP ChatRoutableAddress", "endChatFlag":true, "numberOfParticipants":0, "participants":[]}
webChat.notifyParticipantLeave(agentLeaveEvent_2)
var supervisorLeaveEvent = {"method":"participantLeave", "leaveReason":"default", "agentId":"cpagentfour_OCP ChatRoutableAddress", "endChatFlag":true, "numberOfParticipants":0, "participants":[]}
webChat.notifyParticipantLeave(supervisorLeaveEvent)


// 11. Test Supervisor barges and drops the contact
// First perform steps 1, 3
// Agent joins
var agentJoinEvent = {"agentId":"cpagentone_OCP ChatRoutableAddress","numberOfParticipants":1,"displayName":"Agent","role":"active_participant","webOnHoldComfortGroup":[{"messages":[]}],"participants":[{"id":"cpagentone_OCP ChatRoutableAddress","name":"Agent","type":"active_participant"}],"method":"newParticipant"}
webChat.notifyNewParticipant(agentJoinEvent)
// Supervisors join
var observerJoinEvent = {"agentId":"cpagentfour_OCP ChatRoutableAddress","numberOfParticipants":2,"displayName":"Agent","role":"supervisor_observe","webOnHoldComfortGroup":[{"messages":[]}],"participants":[{"id":"cpagentone_OCP ChatRoutableAddress","name":"Agent","type":"active_participant"},{"id":"cpagentfour_OCP ChatRoutableAddress","name":"Agent","type":"supervisor_observe"}],"method":"newParticipant"}
webChat.notifyNewParticipant(observerJoinEvent)
var coachJoinEvent = {"agentId":"cpagentfour_OCP ChatRoutableAddress","numberOfParticipants":2,"displayName":"Agent","role":"supervisor_coach","webOnHoldComfortGroup":[{"messages":[]}],"participants":[{"id":"cpagentone_OCP ChatRoutableAddress","name":"Agent","type":"active_participant"},{"id":"cpagentfour_OCP ChatRoutableAddress","name":"Agent","type":"supervisor_coach"}],"method":"newParticipant"}
webChat.notifyNewParticipant(coachJoinEvent)
var bargeJoinEvent = {"agentId":"cpagentfour_OCP ChatRoutableAddress","numberOfParticipants":2,"displayName":"Agent","role":"supervisor_barge","webOnHoldComfortGroup":[{"messages":[]}],"participants":[{"id":"cpagentfour_OCP ChatRoutableAddress","name":"Agent","type":"active_participant"},{"id":"cpagentone_OCP ChatRoutableAddress","name":"Agent","type":"passive_participant"}],"method":"newParticipant"}
webChat.notifyNewParticipant(bargeJoinEvent)
// Agent going to leave
var agentMessageEvent = {"displayName":"Agent","message":"Agent 60001 is leaving the chat","timestamp":1623310998303,"senderType":"live_agent","data":{"message": "Agent 60001 is leaving the chat"},"type":"message","customData":[],"method":"newMessage"}
webChat.notifyNewMessage(agentMessageEvent)
var transferEvent_1 = {"agentId":"cpagentone_OCP ChatRoutableAddress","endChatFlag":false,"numberOfParticipants":1,"participants":[{"id":"cpagentfour_OCP ChatRoutableAddress","name":"Agent","type":"active_participant"}],"leaveReason":"transfer","method":"participantLeave"}
webChat.notifyParticipantLeave(transferEvent_1)
var transferEvent_2 ={"agentId":"cpagentfour_OCP ChatRoutableAddress","endChatFlag":false,"numberOfParticipants":1,"participants":[{"id":"cpagentfour_OCP ChatRoutableAddress","name":"Agent","type":"active_participant"}],"leaveReason":"transfer","method":"participantLeave"}
webChat.notifyParticipantLeave(transferEvent_2)
// Supervisor going to leave
var supervisorMessageEvent = {"displayName":"Agent","message":"Barging Agent is leaving the chat now","timestamp":1623311030084,"senderType":"live_agent","data":{"message": "Barging Agent is leaving the chat now"},"type":"message","customData":[],"method":"newMessage"}
webChat.notifyNewMessage(supervisorMessageEvent)
var supervisorLeaveEvent = {"agentId":"cpagentfour_OCP ChatRoutableAddress","endChatFlag":true,"numberOfParticipants":0,"participants":[],"leaveReason":"default","method":"participantLeave"}
webChat.notifyParticipantLeave(supervisorLeaveEvent)


// 12. Test Transfer to service
// First perform steps 1, 3
var agentJoinEvent_1 = {"method":"newParticipant", "agentId":"cpagentone_OCP ChatRoutableAddress", "numberOfParticipants":1, "displayName":"Agent", "role":"active_participant", "webOnHoldComfortGroup":[{"messages":[]}], "participants":[{"id":"cpagentone_OCP ChatRoutableAddress", "name":"Agent", "type":"active_participant"}]}
webChat.notifyNewParticipant(agentJoinEvent_1)
var agentLeaveEvent_1  = {"method":"participantLeave", "leaveReason":"transfer", "agentId":"cpagentone_OCP ChatRoutableAddress", "endChatFlag":false, "numberOfParticipants":0, "participants":[]}
webChat.notifyParticipantLeave(agentLeaveEvent_1)
var agentJoinEvent_2 = {"method":"newParticipant", "agentId":"cpagentthree_OCP ChatRoutableAddress", "numberOfParticipants":1, "displayName":"Agent", "role":"active_participant", "webOnHoldComfortGroup":[{"messages":[]}], "participants":[{"id":"cpagentthree_OCP ChatRoutableAddress", "name":"Agent", "type":"active_participant"}]}
webChat.notifyNewParticipant(agentJoinEvent_2)
var agentLeaveEvent_2 = {"agentId":"cpagentthree_OCP ChatRoutableAddress", "endChatFlag":true, "numberOfParticipants":0, "participants":[], "leaveReason":"default", "method":"participantLeave"}
webChat.notifyParticipantLeave(agentLeaveEvent_2)


// 13. Test Supervisor joins twice
// First perform steps 1, 3
var agentJoinEvent = {"agentId":"cpagentone_OCP ChatRoutableAddress","numberOfParticipants":1,"displayName":"Agent","role":"active_participant","webOnHoldComfortGroup":[{"messages":[]}],"participants":[{"id":"cpagentone_OCP ChatRoutableAddress","name":"Agent","type":"active_participant"}],"method":"newParticipant"}
webChat.notifyNewParticipant(agentJoinEvent)
// Sup joins
var observerJoinEvent = {"method":"newParticipant", "agentId":"cpagentfour_OCP ChatRoutableAddress", "numberOfParticipants":2, "displayName":"Agent", "role":"supervisor_observe", "webOnHoldComfortGroup":[{"messages":[]}], "participants":[{"id":"cpagentone_OCP ChatRoutableAddress", "name":"Agent", "type":"active_participant"},{"id":"cpagentfour_OCP ChatRoutableAddress", "name":"Agent", "type":"supervisor_observe"}]}
webChat.notifyNewParticipant(observerJoinEvent)
var coachJoinEvent = {"method":"newParticipant", "agentId":"cpagentfour_OCP ChatRoutableAddress", "numberOfParticipants":2, "displayName":"Agent", "role":"supervisor_coach", "webOnHoldComfortGroup":[{"messages":[]}], "participants":[{"id":"cpagentone_OCP ChatRoutableAddress", "name":"Agent", "type":"active_participant"},{"id":"cpagentfour_OCP ChatRoutableAddress", "name":"Agent", "type":"supervisor_coach"}]}
webChat.notifyNewParticipant(coachJoinEvent)
// Sup leaves
var transferEvent_1 = {"method":"participantLeave", "leaveReason":"transfer", "agentId":"cpagentone_OCP ChatRoutableAddress", "endChatFlag":false, "numberOfParticipants":2, "participants":[{"id":"cpagentone_OCP ChatRoutableAddress", "name":"Agent", "type":"active_participant"},{"id":"cpagentfour_OCP ChatRoutableAddress", "name":"Agent", "type":"supervisor_observe"}]}
webChat.notifyParticipantLeave(transferEvent_1)
var transferEvent_2 = {"method":"participantLeave", "leaveReason":"transfer", "agentId":"cpagentfour_OCP ChatRoutableAddress", "endChatFlag":false, "numberOfParticipants":1, "participants":[{"id":"cpagentone_OCP ChatRoutableAddress", "name":"Agent", "type":"active_participant"}]}
webChat.notifyParticipantLeave(transferEvent_2)
// Sup joins again
observerJoinEvent = {"method":"newParticipant", "agentId":"cpagentfour_OCP ChatRoutableAddress", "numberOfParticipants":2, "displayName":"Agent", "role":"supervisor_observe", "webOnHoldComfortGroup":[{"messages":[]}], "participants":[{"id":"cpagentone_OCP ChatRoutableAddress", "name":"Agent", "type":"active_participant"},{"id":"cpagentfour_OCP ChatRoutableAddress", "name":"Agent", "type":"supervisor_observe"}]}
webChat.notifyNewParticipant(observerJoinEvent)
coachJoinEvent = {"method":"newParticipant", "agentId":"cpagentfour_OCP ChatRoutableAddress", "numberOfParticipants":2, "displayName":"Agent", "role":"supervisor_coach", "webOnHoldComfortGroup":[{"messages":[]}], "participants":[{"id":"cpagentone_OCP ChatRoutableAddress", "name":"Agent", "type":"active_participant"},{"id":"cpagentfour_OCP ChatRoutableAddress", "name":"Agent", "type":"supervisor_coach"}]}
webChat.notifyNewParticipant(coachJoinEvent)
// Agent drops the contact
var agentLeaveEvent_1  = {"method":"participantLeave", "leaveReason":"default", "agentId":"cpagentone_OCP ChatRoutableAddress", "endChatFlag":true, "numberOfParticipants":0, "participants":[]}
webChat.notifyParticipantLeave(agentLeaveEvent_1)
var agentLeaveEvent_2  = {"method":"participantLeave", "leaveReason":"default", "agentId":"cpagentone_OCP ChatRoutableAddress", "endChatFlag":true, "numberOfParticipants":0, "participants":[]}
webChat.notifyParticipantLeave(agentLeaveEvent_2)
var agentLeaveEvent_3  = {"method":"participantLeave", "leaveReason":"default", "agentId":"cpagentfour_OCP ChatRoutableAddress", "endChatFlag":true, "numberOfParticipants":0, "participants":[]}
webChat.notifyParticipantLeave(agentLeaveEvent_3)