         # find channel/group/dm and add it to history
         m = new Message @, message
 
-        if message.channel[0] == 'C'
-          channel = @getChannelByID message.channel
-        else
-          if message.channel[0] == 'G'
-            channel = @getGroupByID message.channel
-          else
-            channel = @getDMByID message.channel
-
+        channel = @getChannelGroupOrDMByID message.channel
         if channel
           console.log "Adding message "+m.ts+" to "+channel.name
           channel.addMessage m

          console.warn "Could not find channel "+message.channel+" for message"

      when "channel_marked"
        console.log "Channel marked: "+message
      when "user_typing"
        console.log "User is typing"
      else

    for k of @groups
      if @groups[k].name == name
        return @groups[k]

  getChannelGroupOrDMByID: (id) ->
    if id[0] == 'C'
      return @getChannelByID id
    else
      if id[0] == 'G'
        return @getGroupByID id
      else
        return @getDMByID id

  #
  # Message handler callback and dispatch
