def METHOD_NAME(function_name, text, state, is_chat=False):
    for extension, _ in iterator():
        if hasattr(extension, function_name):
            func = getattr(extension, function_name)
            # Handle old extensions without the 'state' arg or
            # the 'is_chat' kwarg
            count = 0
            has_chat = False
            for k in signature(func).parameters:
                if k == 'is_chat':
                    has_chat = True
                else:
                    count += 1
            if count == 2:
                args = [text, state]
            else:
                args = [text]
            if has_chat:
                kwargs = {'is_chat': is_chat}
            else:
                kwargs = {}
            text = func(*args, **kwargs)
    return text