slackapi / bolt-js

A framework to build Slack apps using JavaScript
https://slack.dev/bolt-js
MIT License
2.72k stars 387 forks source link

Event triggered by unknown workspace #2145

Open kronosapiens opened 3 weeks ago

kronosapiens commented 3 weeks ago

@slack/bolt version

^3.17.0

Your App and Receiver Configuration

const app = new App({
  logLevel: LogLevel.WARN,
  signingSecret: process.env.CHORES_SIGNING_SECRET,
  clientId: process.env.CHORES_CLIENT_ID,
  clientSecret: process.env.CHORES_CLIENT_SECRET,
  stateSecret: process.env.STATE_SECRET,
  customRoutes: [ common.homeEndpoint('Chores') ],
  scopes: [
    'channels:history',
    'channels:join',
    'chat:write',
    'commands',
    'groups:history',
    'users:read',
  ],
  installationStore: {
    storeInstallation: async (installation) => {
      await Admin.addHouse(installation.team.id, installation.team.name); # team_id stored in the DB
      await Admin.updateHouseConf(installation.team.id, CHORES_CONF, { oauth: installation });
      console.log(`chores installed @ ${installation.team.id}`);
    },
    fetchInstallation: async (installQuery) => {
      ({ choresConf } = (await Admin.getHouse(installQuery.teamId)));
      return choresConf.oauth;
    },
    deleteInstallation: async (installQuery) => {
      await Admin.updateHouseConf(installQuery.teamId, CHORES_CONF, { oauth: null });
      console.log(`chores uninstalled @ ${installQuery.teamId}`);
    },
  },
  installerOptions: { directInstall: true },
});

Node.js runtime version

^20.11.0

More information:

Original issue here.

I am seeing the following error in my logs:

chores user_change

[ERROR]  bolt-app error: insert into "Resident" ("activeAt", "exemptAt", "houseId", "slackId") values ($1, $2, $3, $4)
  detail: 'Key (houseId)=(E011XGDUJMC) is not present in table "House".', 

This is caused by the app receiving the user_change event for a workspace (E011XGDUJMC) which is not stored in the database. This is surprising, as it is unclear why the app is receiving an event from a workspace which has never installed the app. The main clue is the leading character of the identifier - E - suggests that this is not a typical workspace. Perhaps this is some feature of Enterprise which I am unaware of?

Would be curious to resolve the issue. Thanks!

hello-ashleyintech commented 3 weeks ago

Hi, @kronosapiens! 👋 Thanks for submitting this issue!

Based on the description provided, it sounds like your issue could be due to grid migration. I would recommend using one of (or even better, both!) of the following approaches:

I hope this helps - let me know if you have further questions! 😄