Topic: Implementing Real Time Chat
I'm' thinking about adding one of those slide up buttons that says something along the lines of "Click to Chat with our Sales Associates". To my knowledge there aren't any magic gems that handle this for us yet, so I was thinking of doing it this way..
rails g model ChatUser \
ip_address:string user_agent:string tracking_cookie:text
rails g scaffold Message \
chatroom_session:integer chat_user_id:integer
So then I can attribute all of the messages to a particular browser or store them in the database just in case the user gets disconnected and would like to start where they left off. I've mocked up some .html.erb files and they look like this right now..
(chatroom_assistance.html.erb)
<link type=text/css rel='stylesheet' href='/stylesheets/chat.css'>
<div class="generic_h1">Customer Chat</div>
<div class="chatEncapsulator">
<div id="chat-msgs">
<p>One of our specialists will be with you momentarily.</p>
<br>
</div>
<input id="real_time_interaction_msg" name="real_time_interaction[msg]" type="text" onkeypress="handleKeyPress(event,this.form)" value="">
</div>
<script>
function getUniqueChatroomSessionId(){
return 00000001;
}
function checkThatSessionIsUnqiue(){
}
function channelPullingLoop(sessionId){
// URL: "/real_time_interaction/getData?sessonId=" + sessionId + "&lastSuccessfulPull=" + lastSuccessfulPull
var newData = "GetDataFromAjaxFeed";
if (newData != null){
$('#chat-msgs').append("<p>" + newData + "</p>");
}
}
var lastSuccessfulPull = "12:00";
var uniqueChatroomSessionId = getUniqueChatroomSessionId();
checkThatSessionIsUnqiue();
setInterval("channelPullingLoop('" + uniqueChatroomSessionId + "')", 1000);
</script>So down the road, that channelPullingLoop() will be pulling down data from rails via a route like
URL: "/real_time_interaction/getData?sessonId=" + sessionId + "&lastSuccessfulPull=" + lastSuccessfulPullSo with the above URL, it would do a query for any messages made since lastSuccessfulPull, which would be a date time value.
Does anyone know of any tuts that could help me with this project? I actually don't know very much about cookies or if they can be stored in the database as text like I'm thinking, but yeah, this is where I am right now on things =/ I'm thinking tommorrow I'll caffinate and cludge through this problem, so any advice is appreciated.
Last edited by nsj (2012-10-22 16:29:34)