seratch / bolt-on-cloud-functions-for-firebase

Read this issue first - https://github.com/slackapi/bolt/issues/361
https://github.com/slackapi/bolt/issues/361
MIT License
24 stars 4 forks source link

Request for Guidance: Best practices for local development and production deployments #7

Open nazarsh opened 4 years ago

nazarsh commented 4 years ago

Thanks so much for putting this together! We got a bot up and running in no time using your guidelines.

One issue I am bumping into right now if trying to figure out how to do local development on a bot without interfering with a deployed production one. Do you happen to have any tips on that or best practices?

adwam12 commented 3 years ago

Thanks so much for putting this together! We got a bot up and running in no time using your guidelines.

One issue I am bumping into right now if trying to figure out how to do local development on a bot without interfering with a deployed production one. Do you happen to have any tips on that or best practices?

Try using ngrok! It's what im using for local development. You'll have to change the redirect url in the slack app event subscription from the firebase link to the ngrok https link

nazarsh commented 3 years ago

Thanks @adwam12, I ended up doing just that and here is some code in case anybody is looking for guidance:

const ENV = process.env.FUNCTIONS_EMULATOR ? 'dev' : 'prod'

const getEnvAwareConfigs = (environment) => {
  const env = environment === 'dev' ? 'dev_' : ''
  return [
    config.slack[`${env}signing_secret`],
    config.slack[`${env}bot_token`]
  ]
}

const [
  SIGNING_SECRET,
  BOT_TOKEN
] = getEnvAwareConfigs(ENV)

which is then powered by:

$ firebase functions:config:set slack.bot_token ="YOUR_PROD_TOKEN"
$ firebase functions:config:set slack.dev_bot_token ="YOUR_DEV_TOKEN"
$ firebase functions:config:get > .runtimeconfig.json

I ended up spinning up two Bots, and this config setup allows you, paired with ngrok to test out the changes without any interference with prod deployed version.