       for channel in channels
         robot.messageRoom channel, attachments: [content]
 
-    channelsByPost = (content, callback) ->
+    channelsByWebhookContent = (content, callback) ->
       defaultChannels = [options.default_room]
-
       if content.title and process.env.HUBOT_ESA_SLACK_ROOM_SELECTOR == 'true'
-        channels = []
-        robot.http('https://slack.com/api/channels.list')
-          .query({token: options.slack_token, exclude_archived: '1'})
-          .header('Accept', 'application/json')
-          .get() (error, response, body) ->
-            if response.statusCode is 200
-              availableChannels = []
-              for availableChannel in JSON.parse(body).channels
-                if availableChannel.is_member
-                  availableChannels.push availableChannel.name
-
-              tagsPattern = /#(\w+)/g
-              while (matches = tagsPattern.exec(content.title))
-                channels.push matches[1]
-
-              channels = channels.filter (channel) ->
-                availableChannels.indexOf(channel) > -1
-
-              if channels.length == 0
-                dirsPattern = /\/{0,1}(\w+)\//g
-                while (matches = dirsPattern.exec(content.title))
-                  channels = [matches[1]] if availableChannels.indexOf(matches[1]) > -1
-
-              channels = defaultChannels if channels.length == 0
-              callback(channels)
+        selector = new ChannelSelector(robot, content.title, options.slack_token)
+        selector.select defaultChannels, (selectedChannels) ->
+          callback(selectedChannels)
       else
         callback(defaultChannels)
 

# Author:
#   hmsk <k.hamasaki@gmail.com>
#

module.exports = (robot) ->
  options =

        when 'member_join'
          content.text = data.user.screen_name

      channelsByWebhookContent content, (targetChannels) ->
        robot.emit 'esa.slack.attachment', content, targetChannels

    robot.on 'esa.hear.stats', (res, stats) ->
      content = buildContent 'The stats of esa'
