def set_channels!(message) # :doc:
      channel_type = message.channel_type

      # select channels with the same channel_type as the incoming message
      channels = @app_channels.select { |channel| channel["channel_type"].eql?(channel_type) }

      # filter channels
      case message.channel_type
        when "twitter"  # filter by from or to account
          channels = channels.select { |channel| 
            channel["accounts"].select { |item| 
              item["name"].eql?(message.from) or item["name"].eql?(message.to)
            }.length > 0 
          }
        when "voice" # filter by did
          channels = channels.select { |channel| 
            channel["uid"].eql?(message.channel_name)
            #channel["phones"].select{|item| 
            #  item["phone_number"].eql?(message.to)
            #}.length > 0 
          }
        when "sms"
          channels = channels.select { |channel| 
            channel["phones"].select{|item| 
              item["phone_number"].eql?(message.to)
            }.length > 0 
          }
        when "rss"
          channels = channels.select { |channel| 
            channel["uri"].eql?(message.channel_name)
          }
        else
          logger.warn("This code should not be executed because the first select should avoid this")
          logger.info("Unexpected message: #{message.channel_type}")
          channels = []
      end

      # get only the channel unique identifier
      channels = channels.map { |channel| channel["uid"] }

      logger.debug "Setting channels in the incoming message to #{channels}"
      message.channel_name = channels
    end
def set_channels!(message) # :doc:
      channel_type = message.channel_type

      # select channels with the same channel_type as the incoming message
      channels = @app_channels.select { |channel| channel["channel_type"].eql?(channel_type) }

      # filter channels
      case message.channel_type
        when "twitter"  # filter by from or to account
          channels = channels.select { |channel| 
            channel["accounts"].select { |item| 
              item["name"].eql?(message.from) or item["name"].eql?(message.to)
            }.length > 0 
          }
        when "voice" # filter by did
          channels = channels.select { |channel| 
            channel["uid"].eql?(message.channel_name)
            #channel["phones"].select{|item| 
            #  item["phone_number"].eql?(message.to)
            #}.length > 0 
          }
        when "sms"
          channels = channels.select { |channel| 
            channel["phones"].select{|item| 
              item["phone_number"].eql?(message.to)
            }.length > 0 
          }
        when "rss"
          channels = channels.select { |channel| 
            channel["uri"].eql?(message.channel_name)
          }
        else
          logger.warn("This code should not be executed because the first select should avoid this")
          logger.info("Unexpected message: #{message.channel_type}")
          channels = []
      end

      # get only the channel unique identifier
      channels = channels.map { |channel| channel["uid"] }

      logger.debug "Setting channels in the incoming message to #{channels}"
      message.channel_name = channels
    end
Sets the message channel_name attribute.
 The result is a list of application channels that should be advised about
 the inbound message

 * if message["type"].eql?("twitter"): message["channel_type"] is an
 array of all the application twitter channels that has associated the message twitter account.
   i.e.
     Application channels:
       @app_channels = [
                 {"uid"=>"twitter-channel-1", "type"=>"twitter", "accounts"=>[{"name"=>"juandebravo"}, {"name"=>"connfudev"}]},
                 {"uid"=>"twitter-channel-2", "type"=>"twitter", "accounts"=>[{"name"=>"telefonicaid"}]}]
     Incoming message:
       message.channel_type = "twitter"
       message.from = "juandebravo"

      set_channels!(message) => message.channel_name = ["twitter-channel-1"]

 ==== Parameters
 * +message+ Connfu::Message with no channel_name info
 ==== Return
 * Connfu::Message with the channel_name filled with the relevant app channels