Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implement api key<->room/staff state tracking; show the real url the …

…widget was called from, not the widget url itself, when opening a chat
  • Loading branch information...
commit 4c188b390e7a1eeea285e1fac56bbd7137069977 1 parent 72fc098
@courtenay authored
Showing with 31 additions and 25 deletions.
  1. +14 −6 README.md
  2. +3 −11 public/index.html
  3. +5 −4 server.rb
  4. +9 −4 server_test.rb
View
20 README.md
@@ -32,22 +32,30 @@ Note that if you have other stuff in your redis database it might delete everyth
## TODO:
+- refactor index.html into separate .js files
- better design
-- api keys that determine 'room' and 'user'
--- keep general user state
---- send user state messages (like current location) instead of sending those as text
-- redisize api keys
+- auto-create api keys if none provided and user has not been seen (cookies? local storage?)
+- keep general user state (by api key)
+-- send user state messages (like current location) instead of sending those as text
+-- user state api
+- open this as discussion in tender with contents of chat as ? internal reply ? or visible to customer?
+- better/bigger staff ui for chats
+- javascript tests!
+- system messages visible to everyone, like closing chat or performing a public action
+- clean up widget code, removing Tender stuff
+- implement SSO decoder, requires tracking api keys<-->private encryption keys
- link up urls particularly in location changes
- persist chat open/closed state with a? cookie?
- proactive open/close chat window (push-open from support)
- "close chat" from user side notifies support with special message
- aggressively timeout chat
-- support buttons
+- support buttons for things like "location" or "search kb" that match up with commands
- implement hooks to tender using api keys or w/e
--- implement kb api search with inline pasting
+-- implement kb api search with inline pasting of url and snippet
## TODONE recently:
+- redisize api keys
- widgetize
- redisize backend
- ajax posting of messages
View
14 public/index.html
@@ -50,7 +50,6 @@
<input type="submit" value="Send Message" />
</p>
<input type="hidden" name="key" value="asdf1234" />
- <input type="hidden" name="room" value="1225" />
<input type="hidden" name="internal" id="internal" value="" />
</form>
</div>
@@ -71,8 +70,6 @@
Chat.messages.refresh()
}, 2500);
- Chat.messages.set("room", $(document.forms[0].room).val());
-
// todo: only if name is set
// if not a staff member, send current page url
if (queryValueFor(window.location.href, 'staff') != "1") {
@@ -101,7 +98,6 @@
Chat.messages = Em.ArrayController.create({
content: [],
- room: null,
_idCache: {},
addMessage: function(message){
@@ -114,13 +110,9 @@
},
refresh: function(){
- var room = this.get("room");
- if (Em.empty(room)){
- this.set("content", [])
- return;
- }
var self = this;
- var url = "/messages?key=asdf1234&room=" + room + "&staff=" + queryValueFor(window.location.href, 'staff') + "&callback=?"
+ var url = "/messages?key=" + queryValueFor(window.location.href, 'key') + "&callback=?"
+
$.getJSON(url, function(data) {
for (var i=0; i < data.results.length; i++) {
self.addMessage(Chat.Message.create(data.results[i]))
@@ -130,7 +122,7 @@
console.log('error');
console.log(data)
});
- }.observes("room")
+ }
})
Chat.messages.refresh()
View
9 server.rb
@@ -15,16 +15,17 @@
end
before do
- if params[:key] != API_KEY
+ @auth = REDIS.hgetall "key.#{params[:key]}"
+ if @auth.nil?
halt 401, 'bad key'
end
+ params[:room] = @auth['room']
+ params[:staff] = @auth['staff']
end
get '/messages' do
content_type :json
- # todo: decrypt sso string or check api key and detect user is staff
- is_staff = (params[:staff] == "1")
- arr = { :results => Message.all(params[:room], is_staff) }
+ arr = { :results => Message.all(params[:room], params[:staff]) }
params[:callback] + "(#{arr.to_json})"
end
View
13 server_test.rb
@@ -10,6 +10,11 @@ class ServerTest < Test::Unit::TestCase
def app
Sinatra::Application
end
+
+ def setup
+ REDIS.hmset 'key.asdfxxx', :staff, false, :room, 'test-1'
+ end
+
def test_api_key_required
get '/messages'
@@ -19,14 +24,14 @@ def test_api_key_required
def test_index
Message.clear "test-1"
- get "/messages?room=test-1&key=asdf1234&callback=callme"
+ get "/messages?key=asdfxxx&callback=callme"
assert last_response.ok?
assert_equal "callme({\"results\":[]})", last_response.body
end
def test_makes_message
Message.clear "test-1"
- post "/messages", { :key => "asdf1234", :name => "joe", :message => "test", :room => "test-1" }
+ post "/messages", { :key => "asdfxxx", :name => "joe", :message => "test" }
assert last_response.redirect?
results = Message.all("test-1", false)
@@ -37,10 +42,10 @@ def test_makes_message
def test_ignores_internal
Message.clear "test-1"
- post "/messages", { :key => "asdf1234", :name => "joe", :message => "test", :room => "test-1", :internal => "0" }
+ post "/messages", { :key => "asdfxxx", :name => "joe", :message => "test", :internal => "0" }
assert last_response.redirect?
- post "/messages", { :key => "asdf1234", :name => "admin", :message => "test2", :room => "test-1", :internal => "1" }
+ post "/messages", { :key => "asdfxxx", :name => "admin", :message => "test2", :internal => "1" }
assert last_response.redirect?
results = Message.all("test-1", false)
Please sign in to comment.
Something went wrong with that request. Please try again.