Closed apanzerj closed 8 years ago
not sure if I read this code correctly, but you return rick, terminating the function; pretty much everything below that never gets executed.
It says in the docs if you return a never resolving promise it won't terminate
edit: https://github.com/claudiajs/claudia-api-builder/blob/master/docs/api.md#responding-to-requests
edit 2: I'm totally sure I'm just doing it wrong but I'm lost as to where/how.
yes, but basic JS syntax is that functions get terminated after a return. you need to process stuff before returning the promise.
by the way, there's no reason to do custom termination to call a third-party API that takes too long; just increase the lambda timeout.
It's because slack has a 3 second timeout. So you use the response url to re-respond after the fact.
still, you can't return from a function and do other stuff later. that simply won't work because of how javascript executes functions.
for the slack timeout, the workaround at the moment is to split the work into two lambdas, one that will receive the initial slack request and respond to slack immediately, and another that actually processes the work and responds back. you can use SQS or SNS to decouple the two.
we're modifying the bot builder soon to make delayed responses easier to code. once the change is complete, you'll be able just to add a config argument to the bot builder to allow it to return delayed responses to slack.
ahh, is there way to add the extra lambda within the framework of claudia js ? Or do I just have to manually make an extra lambda myself?
(also, thanks for the help :-D )
you can create the extra lambda using claudia.js as another project. check out https://github.com/claudiajs/claudia/blob/master/getting_started.md
We implemented much better support for delayed responses in Bot Builder 1.4.0. here's how you can use it to achieve the trick with async calls easily, with a single lambda: https://github.com/claudiajs/example-projects/tree/master/slack-delayed-response
Nice!
Here's a full tutorial how to run delayed responses with Slack https://claudiajs.com/tutorials/slack-delayed-responses.html
Thanks. I'm going to play with it now.
@gojko playing with it, I get a permissions error in IAM.
I tore down, updated, redeployed. What am I missing?
{ [AccessDeniedException: U
ser: arn:aws:sts::-:assumed-role/pagerduty_bot_for_dev-executor/awslambda_71_20160721182
648621 is not authorized to perform: lambda:InvokeFunction on resource: arn:aws:lambda:us-east-1:72
-:function:pagerduty_bot_for_dev]
message: 'User: arn:aws:sts::-:assumed-role/pagerduty_bot_for_dev-executor/awslambda_7
1_20160721182648621 is not authorized to perform: lambda:InvokeFunction on resource: arn:aws:lambda
:us-east-1:-:function:pagerduty_bot_for_dev',
code: 'AccessDeniedException',
time: Thu Jul 21 2016 18:26:50 GMT+0000 (UTC),
requestId: 'b0d306da-4f70-11e6-bb01-c30f53add707',
statusCode: 403,
retryable: false,
retryDelay: 24.02851819060743 }
Please use gitter for questions, issue tracker is for issues with the library itself.
For the error: check if your user has lambda:InvokeFunction permission, also check if you invoked claudia create with --allow-recursion
option, it's required to allow lambda function to invoke itself.
Probably missing something but here goes:
I have a bot that makes an api request and returns a result. Sometimes the whole roundtrip takes too long so I'm trying to do custom termination.
In amazon I just see the following in cloudwatch: