如何在Heroku上运行Slack聊天机器人?配置问题咨询
Deploying Your Slack Bot to Heroku: Answers to Your Questions
Hey there! Let me break down each of your questions clearly since I’ve deployed a few Slack bots to Heroku myself.
1. What PORT should you configure in your .env file?
You don’t need to hardcode a specific port like 3000 for Heroku. Here’s why:
- Heroku automatically assigns a dynamic port to your app at runtime, which is stored in the
PORTenvironment variable. - In your code, you should always reference
process.env.PORTinstead of a fixed number. For example:const port = process.env.PORT || 3000; app.listen(port, () => { console.log(`Bot running on port ${port}`); }); - For local development, you can still set
PORT=3000in your .env file—this acts as a fallback whenprocess.env.PORTisn’t available (like on your local machine). When deployed to Heroku, the platform will override this with its own dynamic port, so you don’t need to change anything in .env for deployment (just make sure .env is in your.gitignoreso it’s not pushed to Heroku).
2. Where to find the OAuth & Permissions redirect URL on Heroku?
Heroku gives your app a public domain that you’ll use for the redirect URL. Here’s how to get it:
- Go to your Heroku Dashboard and select your bot’s app.
- Click the Settings tab.
- Scroll down to the Domains section—you’ll see a URL formatted like
https://<your-app-name>.herokuapp.com. - Combine this base URL with the redirect path your bot uses (from the tutorial you followed). For example, if your tutorial used
/slack/oauth_redirect, your full redirect URL would be:https://<your-app-name>.herokuapp.com/slack/oauth_redirect - Don’t forget to add this full URL to your Slack app’s OAuth & Permissions page under "Redirect URLs".
3. Where to find the Request URL (for Slack Events API, I assume)?
Since your question cut off, I’m guessing you’re asking about the Request URL for Slack’s Events API (common for bots that listen to messages). The process is similar to the redirect URL:
- Grab your app’s public domain from Heroku’s Settings > Domains (same as step 2 above).
- Append the path your bot uses to receive Slack events. If your tutorial used
/slack/events, the full Request URL would be:https://<your-app-name>.herokuapp.com/slack/events - This is the URL you’ll enter in your Slack app’s Event Subscriptions page under "Request URL".
内容的提问来源于stack exchange,提问作者Richard Reis
相关产品推荐
相关产品推荐

