Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(bot): use bolt for app #1391

Merged
merged 9 commits into from
Jun 5, 2024
Merged

ref(bot): use bolt for app #1391

merged 9 commits into from
Jun 5, 2024

Conversation

seaerchin
Copy link
Contributor

@seaerchin seaerchin commented May 27, 2024

Problem

At present, we are using express' router for interfacing with slack, which is less ergonomic than using bolt. this is problematic because we want to offload some tasks from form -> slack bot, which might be more cumbersome using bolt.

Solution

Shift from using express to using bolt + ExpressReceiver. This simplifies code-flow abit, but note that there si some validation logic which isn't captured here but will be downstream

Tests

NOTE: This is untested at present

Deploy Notes

  • go to SSM
  • search for SLACK
  • check that there are four secrets (2 tokens * 2 envs)
  • go to slack app directory
  • check that the slash commands are updated to the latest end-point
  • check that the slash commands are:
    • site-up
    • whitelist

@seaerchin seaerchin changed the base branch from develop to harish/isom-1037-create-automation-for-prod-ops-to-whitelist May 27, 2024 17:34
@seaerchin seaerchin changed the title Ref/isobolt ref(bot): use bolt for app May 28, 2024
@seaerchin seaerchin marked this pull request as ready for review May 28, 2024 12:43
@seaerchin seaerchin requested a review from a team May 28, 2024 12:43
@seaerchin seaerchin requested review from a team and harishv7 May 29, 2024 17:02
@seaerchin
Copy link
Contributor Author

seaerchin commented May 29, 2024

pending actions on my end: spin up local ngrok instance, register a mock endpoint and check to see if it works

@seaerchin seaerchin force-pushed the harish/isom-1037-create-automation-for-prod-ops-to-whitelist branch from 3103275 to 4e961c3 Compare June 4, 2024 09:25
Base automatically changed from harish/isom-1037-create-automation-for-prod-ops-to-whitelist to develop June 4, 2024 10:09
seaerchin added 6 commits June 4, 2024 18:26
add slack signing secrets
use bolt for our app; commented out whitelist emails for now
add extra env vars
had to omit using shared middleware - not sure if this will impact
anything. this is because bolt runs their own custom middleware and
using our shared middleware for this path runs into errors.

additionally, we might want to version it better
shift to extra const file
@seaerchin seaerchin enabled auto-merge (squash) June 4, 2024 10:27
Comment on lines -22 to -26
const slackTimestamp = req.headers["x-slack-request-timestamp"] as string
const slackSig = req.headers["x-slack-signature"] as string

if (!slackTimestamp || !slackSig)
return res.send({ message: "Missing header/signature" })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need this as bolt provides this by default - see here

Comment on lines -19 to -29
export interface SlackPayload {
token: string
team_id: string
team_domain: string
channel_id: string
channel_name: string
user_id: string
user_name: string
command: string
text: string
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

used inbuilt type SlashCommand

Comment on lines -43 to -57
return ResultAsync.fromPromise(
Promise.race([
dns.resolveCname(domain),
new Promise<null>((_, reject) =>
setTimeout(() => reject(null), DNS_TIMEOUT)
),
]),
() => {
logger.info({
message: "Error resolving CNAME",
meta: { domain, method: "checkCname" },
})
return new Error()
}
)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to Promise.race because we await ack() in the caller - that's the ack within 3s that slack is waiting for.

see here under listening and responding to commands

support/routes/v2/isobot/ops/botService.ts Outdated Show resolved Hide resolved
}

public async whitelistEmails(payload: SlackPayload) {
public async whitelistEmails(text: string) {
// Sample user input:
// email1,expDate email2,expDate
// email1@xyz.com,2024-06-22 email2@abc.com,2025-01-31
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this format make sense, feel free to suggest alternatives

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can run with this first and let prod ops decide. tbh i think this won't quite work for >2-3 emails but idk how rare that would be

support/routes/v2/isobot/index.ts Show resolved Hide resolved
@@ -173,6 +173,14 @@
"name": "SITE_PASSWORD_SECRET_KEY",
"valueFrom": "STAGING_SITE_PASSWORD_SECRET_KEY"
},
{
"name": "SLACK_SIGNING_SECRET",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to add to SSM also right. Rmb when deploying!

@seaerchin seaerchin requested review from harishv7 and a team June 5, 2024 10:13
@seaerchin seaerchin merged commit b8c10f7 into develop Jun 5, 2024
11 of 12 checks passed
@seaerchin seaerchin deleted the ref/isobolt branch June 5, 2024 10:15
@alexanderleegs alexanderleegs mentioned this pull request Jun 13, 2024
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants