I'm working on an Alexa skill with Flask-Ask. I want to log all intent calls and their arguments, and since intents are all conveniently annotated with the ask.intent
decorator, I figured that I could either change the code of Flask-Ask to do the logging in the code of the decorator, or I could decorate myself, which is preferable to avoid problems with patching the library when deploying to production.
I've built the solution below, but the problem is that *args and **kwargs are always empty, instead of being passed on like on the most voted solution for this issue.
def tracked_intent(intent_name, mapping={}, convert={}, default={}):
def decorator(f):
@ask.intent(intent_name, mapping, convert, default)
def new_func(*args, **kwargs):
print('Got intent {} with arguments {} and {}'.format(intent_name, str(args), str(kwargs)))
return f(*args, **kwargs)
new_func.__name__ = f.__name__
return new_func
return decorator
Thus, when I have an intent call that requires an argument, I get something like TypeError: function() missing 2 required positional arguments: 'arg1' and 'arg2'
How can I fix my decorator to "extend" the ask.intent
decorator while correctly forwarding the function arguments?