You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在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 PORT environment variable.
  • In your code, you should always reference process.env.PORT instead 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=3000 in your .env file—this acts as a fallback when process.env.PORT isn’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 .gitignore so 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:

  1. Go to your Heroku Dashboard and select your bot’s app.
  2. Click the Settings tab.
  3. Scroll down to the Domains section—you’ll see a URL formatted like https://<your-app-name>.herokuapp.com.
  4. 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
  5. 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:

  1. Grab your app’s public domain from Heroku’s Settings > Domains (same as step 2 above).
  2. 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
  3. This is the URL you’ll enter in your Slack app’s Event Subscriptions page under "Request URL".

内容的提问来源于stack exchange,提问作者Richard Reis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 09:09:13