slack requires the webhook to respond within 3 sec...
# software-contributors
c
slack requires the webhook to respond within 3 seconds of the slash command. Generating the AI response might take longer. As long as the bot responds on time, slack provides mechanisms to keep the workflow open and continue working on it. But With lambda its a bit tricky. It's possible that starting a new thread before returning a response will force the lambda to stay open, but I think something like SQS might be a better option (though I dont know AWS so well) I imagine something like
Copy code
Slack Slash Command
        │
        ▼
send task to SQS then return a response to slack quickly

SQS Receivees task
        │
        ▼
calls another lambda which generates AI response and sends it
How does this sound @mysterious-tomato-10057? And how confusing is it?
m
i think this makes sense, the rest of our application uses a producer and consumer model for the lambdas, so i guess we should do it here also!
so frist lambda tells slack we got the message good, then second lambda receives the sqs message from the first
c
yes exactly.
m
sounds good to me!
c
In terms of setting that up, where should I be looking? deploy.sh?
m
this is sounding like lambda one should live in the https://github.com/frumfinance/SlackApp/ repo, which is what i was kinda trying to avoi
avoid
which part of setting that app do you want me to point you to?
i think we should maybe just focus on the second lambda for now and get that working, then we can worry about the interface for it later? what do you think?
c
Ok.
Now should I built it in frumfinancecore or slackapp
m
i am thinking lambda 1 is in slack app and lambda two is in core
c
ok, so I will just write the lambda 2 where the current lambda exists
m
right
c
ok and I'll test it using example slack payload
m
👍
sounds good to me!
c
how can I put my slack token in aws environment variables
m
In the cdk stack for the lambda there is a patameter to pass in env var.
c
cdk stack for the lambda
what is that? infra/lib/slack-admin.stack.ts?
yeah I see
Copy code
environment: {
        SLACK_BOT_TOKEN: isLocal ? process.env.SLACK_BOT_TOKEN! : 'xxxxx',
        SLACK_SIGNING_SECRET: isLocal ? process.env.SLACK_SIGNING_SECRET! : 'xxxxx',
        DEPLOY_STAGE: props.stageConfig.name,
      },
m
Awesome
Any questions on that part? Basically when you deploy you just need to have the env vars set locally it looks like.
c
yeah looks perfect
m
awesome, pieces starting to feel like they fit together?
c
yes! but... I think it will be easier for me to create this lambda if I set up the other one first, so that I can deal with real slack payloads.
m
👍 sure that makes sense
you have full access to the slack repo and slack aws account as well
the process might be a bit outdated compared to the core app
like i don’t think i setup
just
yet
c
Ok Ill try and let you know if I get stuck
m
👍
c
should I work in the awslambda folder? Create a new lambdas folder or slack_respond_lambda folder?
image.png
m
awslambda/slack_admin
c
whats awslambda/pyproject.toml? copilot is trying to add
aws-lambda-powertools
abd
slack-sdk
there but seems unnecessary (because app_home_page uses both without it)
m
@full-wall-37598 can tell us for sure but the history is we used to have multiple pyproject.toml files for each lambda but have since been migrating to just one for each repo that have each lambda in groups.
c
is the current aswlambda folder built for multiple lambdas or one big lambda? whats function and constants?
m
its multiple lambdas, you can look at the infra in slack.stack.ts
c
ok thanks
m
👍
c
so the pyproject.toml file in awslambda is not really used anymore, and now we just use the one in root and make a group for each lambda, correct?
m
i know that is the end goal, but i dont’ remember where we are holding in the process of getting there
the fact the sub folder one still is there is throwing me off
c
the one in the root of the repo looks like it has all the groups, and the one in the awslambda folder doesnt have all the deps the lambdas use so look slike you got there, or got there for most lambdas. Who knows? not so important for my task I guess.
m
Exactly. I'd just focus on the root one. Zier would know.
@full-wall-37598 can tell us in the morning
c
I hope it doesnt mess anyone up if I run
./deploy.sh alpha
in slackapp
m
It wont
c
I think I need to configure aws
should I name the session frumfinance
m
That's a good question. What does the deploy script say
c
I dont think it does
I will come back to this tomorrow
m
👍
if anything is missing in this deploy script compared to the core one feel free to upgrade
c
Im a bit lost. Should I be passing the
--bootstrap
flag? I assume not but not sure. last night I was getting errors like
Copy code
Need to perform AWS calls for account 515966538624, but no credentials have been configured
I thought aws configure sso might help with that but it didnt. searching 515966538624 in the repo seemed to imply the account id was hardcoded in stages.ts and another file. I replaced those with my account id and I got the same error just with my account id
m
when you say you replaced it with your account id, which id is that?
c
354918380135
m
why is that “your account id”?
c
image.png
m
that is the core account
are we talking about the core repo or the slack app repo
c
slackapp
m
right so you want the slackapp account
not the core account
c
so when I did aws configure sso I chose slackapp but yeah I guess I had wrong id
m
right so the repo is already configured for the right id
so you don’t want to switch that
c
ok so should I rerun aws configure sso
or are you saying I wasnt supposed to run that in the first place?
m
run what?
f
hey can I help here? Long thread
m
@full-wall-37598 is the slack app repo using one yproject toml yet? bc we see two
f
should be one that was done a while ago
could be needs to be deleted or something but need to check
m
@curved-bear-18232 i think you’ll need to port the profile logic from the core deploy script over to slack app deploy script to get it working. i can do that for you if you get stuck
f
it should be working with one
👍 1
you should create a new dep group for your new lambda if there is one and add deps there
like poetry add hello-world --group new_lambda
💪 1
c
yeah ok I think copilot did that for me @full-wall-37598 thanks
💪 1
@mysterious-tomato-10057 I will try porting it over. should the frumfinance and the same start url etc?
m
same start url, i think same session name of frumfinance
c
Ok I will work on that later today
m
definitely same start url though
awesome!
c
and should I be doing
--bootstrap
? whats that for?
ok looks simple I already copied it from the other script
but then I realized I might need to change these values
this looks right?
Copy code
alpha_account=515966538624
    prod_account=235494775606
m
No you don't need to be doing bootstrap.
👍 1
You can check the account IDs in the stages file
c
I got it from here
fair warning. I accidentally ran the deploy script before changing the values. I cancelled it in middle and I think (hope) it didnt do anything or mess anything up, and I am really sorry if it did
image.png
image.png
oh wait thats my fault
🎯 1
Ill fix it
m
looks like a path issue
c
I cant remember the start url or where I found it last time
never mind I think I found it
👍 1
image.png
Copy code
Could not assume role in target account using current credentials (which are for account 515966538624) User: arn:aws:sts::515966538624:assumed-role/AWSReservedSSO_AlphaDeveloperAccess_aedbb0da43ef43a5/shlomo.rabinowitz@frum.finance is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::354918380135:role/cdk-hnb659fds-deploy-role-354918380135-us-east-1 . Please make sure that this role exists in the account. If it doesn't exist, (re)-bootstrap the environment with the right '--trust', using the latest version of the CDK CLI.
m
look at the mismatching account ids there
looks like you are trying to deploy something to the core account using slack account credentials
c
omg did I do that again? One sec
ok should be fixed. Im glad these protextions are in place
m
Bh
f
not caught up on this but is there now a consumer to send slack messages? We were going to build that but if it’s done we can use that same consumer