<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def _smart_get_initialized_channel_for_service(self, metadata, filter_by, is_try_initailize = True):
        '''
         - filter_by can be sender or signer
        '''
        channels = self._get_initialized_channels_for_service(self.args.org_id, self.args.service_id)
        group_id = metadata.get_group_id(self.args.group_name)
        channels = [c for c in channels if c[filter_by].lower() == self.ident.address.lower() and c["groupId"] == group_id]

        if (len(channels) == 0 and is_try_initailize):
           # this will work only in simple case where signer == sender
           self._initialize_already_opened_channel(metadata, self.ident.address, self.ident.address)
           return self._smart_get_initialized_channel_for_service(metadata, filter_by, is_try_initailize = False)

        if (len(channels) == 0):
            raise Exception("Cannot find initialized channel for service with org_id=%s service_id=%s and signer=%s"%(self.args.org_id, self.args.service_id, self.ident.address))
        if (self.args.channel_id is None):
            if (len(channels) > 1):
                channel_ids = [channel["channelId"] for channel in channels]
                raise Exception("We have several initialized channel: %s. You should use --channel-id to select one"%str(channel_ids))
            return channels[0]
        for channel in channels:
            if (channel["channelId"] == self.args.channel_id):
                return channel
        raise Exception("Channel %i has not been initialized or your are not the sender/signer of it"%self.args.channel_id)