Permalink
Browse files

Merge pull request #22 from flowdock/external-user-messages

Support chat messages from external users.
  • Loading branch information...
2 parents d2be1e8 + e74e52a commit c5533b25ddd7f07b2b3b2ae49779ceb9802ccfb0 Otto Hilska committed Aug 29, 2012
@@ -1,5 +1,6 @@
class MessageEvent < FlowdockEvent
register_event "message"
+ INVALID_NICK_CHARS = /[^a-zA-Z0-9\[\]`_\-\^{\|}]/
def process
if !@irc_connection.remove_outgoing_message(@message) # don't render own messages twice
@@ -10,6 +11,13 @@ def process
end
def render
- render_privmsg(@user.irc_host, @channel.irc_id, @message['content'])
+ irc_host = if @user
+ @user.irc_host
+ elsif @message['external_user_name']
+ nick = @message['external_user_name'].gsub(INVALID_NICK_CHARS, '_')
+ "#{nick}!#{IrcServer::UNKNOWN_USER_EMAIL}"
+ end
+
+ render_privmsg(irc_host, @channel.irc_id, @message['content'])
end
end
@@ -0,0 +1 @@
+{"id":907,"app":"chat","flow":"irc:ottotest","event":"message","sent":1334660642345,"attachments":[],"uuid":"KE1tqxXhhmNMVkKC","external_user_name":"Robot","content":"test","tags":[]}
@@ -22,6 +22,25 @@
event.process
end
+ it "should process standard chat message from external user" do
+ message_event = message_hash('message_from_external_user_event')
+ @irc_connection.should_receive(:remove_outgoing_message).with(message_event).and_return(false)
+
+ @irc_connection.should_receive(:send_reply).with(":Robot!unknown@user.flowdock PRIVMSG #{@channel.irc_id} :test").once
+ event = FlowdockEvent.from_message(@irc_connection, message_event)
+ event.process
+ end
+
+ it "should validate external user in chat messages" do
+ message_event = message_hash('message_from_external_user_event')
+ message_event['external_user_name'] += ':!@'
+ @irc_connection.should_receive(:remove_outgoing_message).with(message_event).and_return(false)
+
+ @irc_connection.should_receive(:send_reply).with(":Robot___!unknown@user.flowdock PRIVMSG #{@channel.irc_id} :test").once
+ event = FlowdockEvent.from_message(@irc_connection, message_event)
+ event.process
+ end
+
it "should render standard chat message" do
message_event = message_hash('message_event')

0 comments on commit c5533b2

Please sign in to comment.