'determine if a rule of the given channel matches with the given url
:param channel_id : the identifier of the channel_id
:param url : the url to match with a rule
:param country_id : the identifier of the country
:returns the rule that matches the given condition. False otherwise.
:rtype : im_livechat.channel.rule'

def match_rule(self, channel_id, url, country_id=False):

    def _match(rules):
        for rule in rules:
            if re.search(rule.regex_url, url):
                return rule
        return False
    if country_id:
        domain = [('country_ids', 'in', [country_id]), ('channel_id', '=', channel_id)]
        rule = _match(self.search(domain))
        if rule:
            return rule
    domain = [('country_ids', '=', False), ('channel_id', '=', channel_id)]
    return _match(self.search(domain))
