Skip to content

Commit

Permalink
chore: handle app_uninstalled event
Browse files Browse the repository at this point in the history
  • Loading branch information
slowbackspace committed Dec 20, 2023
1 parent d6b397e commit 02f2460
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 97 deletions.
189 changes: 92 additions & 97 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,113 +211,108 @@ We need to subscribe to following events types
- `message.channels` - listens for messages in public channels that the app is added to
- `message.groups` - listens for messages in private channels that the app is added to
- `member_joined_channel` - sent when an user joins a channel, used for sending welcome message after adding the app to a channel
- `app_uninstalled` - sent when an user removes the app from the workspace, used for removing installation data from the database

To speed up your setup process, simply copy and paste the following JSON into the App Manifest. This action will auto-configure OAuth, event subscriptions, and slash commands for you.

> Note: You need to replace `<YOUR-DOMAIN>` with the domain where you deployed the app.
```json
{
"display_information": {
"name": "Blockfrost for Slack"
"display_information": {
"name": "Blockfrost for Slack"
},
"features": {
"bot_user": {
"display_name": "Blockfrost for Slack",
"always_online": false
},
"features": {
"bot_user": {
"display_name": "Blockfrost for Slack",
"always_online": false
},
"slash_commands": [
{
"command": "/tx",
"url": "https://slack-integration.blockfrost.io/slack/events",
"description": "Retrieves content of the requested transaction",
"usage_hint": "[hash]",
"should_escape": false
},
{
"command": "/link",
"url": "https://slack-integration.blockfrost.io/slack/events",
"description": " Link Blockfrost project to enable querying data directly within the Slack App",
"usage_hint": "{project|webhook}",
"should_escape": false
},
{
"command": "/asset",
"url": "https://slack-integration.blockfrost.io/slack/events",
"description": "Retrieves information about a specific asset",
"usage_hint": "<hex>",
"should_escape": false
},
{
"command": "/block",
"url": "https://slack-integration.blockfrost.io/slack/events",
"description": "Retrieves content of the requested block",
"usage_hint": "[hash-or-number]",
"should_escape": false
},
{
"command": "/address",
"url": "https://slack-integration.blockfrost.io/slack/events",
"description": "Retrieves information about the requested address",
"usage_hint": "<bech32 address>",
"should_escape": false
},
{
"command": "/account",
"url": "https://slack-integration.blockfrost.io/slack/events",
"description": "Retrieves information about the stake account",
"usage_hint": "<bech32 stake address>",
"should_escape": false
},
{
"command": "/pool",
"url": "https://slack-integration.blockfrost.io/slack/events",
"description": "Retrieves information about the requested stake pool",
"usage_hint": "<pool_id>",
"should_escape": false
},
{
"command": "/blockfrost",
"url": "https://slack-integration.blockfrost.io/slack/events",
"description": "Show help",
"usage_hint": "help",
"should_escape": false
}
]
"slash_commands": [
{
"command": "/tx",
"url": "https://slack-integration.blockfrost.io/slack/events",
"description": "Retrieves content of the requested transaction",
"usage_hint": "[hash]",
"should_escape": false
},
{
"command": "/link",
"url": "https://slack-integration.blockfrost.io/slack/events",
"description": " Link Blockfrost project to enable querying data directly within the Slack App",
"usage_hint": "{project|webhook}",
"should_escape": false
},
{
"command": "/asset",
"url": "https://slack-integration.blockfrost.io/slack/events",
"description": "Retrieves information about a specific asset",
"usage_hint": "<hex>",
"should_escape": false
},
{
"command": "/block",
"url": "https://slack-integration.blockfrost.io/slack/events",
"description": "Retrieves content of the requested block",
"usage_hint": "[hash-or-number]",
"should_escape": false
},
{
"command": "/address",
"url": "https://slack-integration.blockfrost.io/slack/events",
"description": "Retrieves information about the requested address",
"usage_hint": "<bech32 address>",
"should_escape": false
},
{
"command": "/account",
"url": "https://slack-integration.blockfrost.io/slack/events",
"description": "Retrieves information about the stake account",
"usage_hint": "<bech32 stake address>",
"should_escape": false
},
{
"command": "/pool",
"url": "https://slack-integration.blockfrost.io/slack/events",
"description": "Retrieves information about the requested stake pool",
"usage_hint": "<pool_id>",
"should_escape": false
},
{
"command": "/blockfrost",
"url": "https://slack-integration.blockfrost.io/slack/events",
"description": "Show help",
"usage_hint": "help",
"should_escape": false
}
]
},
"oauth_config": {
"redirect_urls": ["https://slack-integration.blockfrost.io/slack/oauth_redirect"],
"scopes": {
"bot": [
"channels:history",
"chat:write",
"groups:history",
"commands",
"channels:read",
"groups:read",
"mpim:read"
]
}
},
"settings": {
"event_subscriptions": {
"request_url": "https://slack-integration.blockfrost.io/slack/events",
"bot_events": ["member_joined_channel", "message.channels", "message.groups"]
},
"oauth_config": {
"redirect_urls": [
"https://slack-integration.blockfrost.io/slack/oauth_redirect"
],
"scopes": {
"bot": [
"channels:history",
"chat:write",
"groups:history",
"commands",
"channels:read",
"groups:read",
"mpim:read"
]
}
"interactivity": {
"is_enabled": true,
"request_url": "https://slack-integration.blockfrost.io/slack/events"
},
"settings": {
"event_subscriptions": {
"request_url": "https://slack-integration.blockfrost.io/slack/events",
"bot_events": [
"member_joined_channel",
"message.channels",
"message.groups"
]
},
"interactivity": {
"is_enabled": true,
"request_url": "https://slack-integration.blockfrost.io/slack/events"
},
"org_deploy_enabled": false,
"socket_mode_enabled": false,
"token_rotation_enabled": false
}
"org_deploy_enabled": false,
"socket_mode_enabled": false,
"token_rotation_enabled": false
}
}
```

Expand Down
2 changes: 2 additions & 0 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { registerBlockfrostHelpCommand } from './commands/blockfrost-help/blockf
import { registerRootEndpoint } from './endpoints/index.js';
import { logger } from './utils/logger.js';
import { initializeSentry } from './utils/sentry.js';
import { registerAppUninstalledEvent } from './events/app-uninstalled.js';
const { App, ExpressReceiver, LogLevel } = bolt;

const port = Number(process.env.PORT) || 3000;
Expand Down Expand Up @@ -69,6 +70,7 @@ registerPoolCommand(app);
registerBlockfrostHelpCommand(app);

registerWelcomeMessage(app);
registerAppUninstalledEvent(app);
registerWebhookEndpoint(expressReceiver);
registerRootEndpoint(expressReceiver);

Expand Down
20 changes: 20 additions & 0 deletions src/events/app-uninstalled.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { App } from '@slack/bolt';
import BlockfrostInstallationStore from '../installation-store/index.js';
import { logger } from '../utils/logger.js';
import { StringIndexed } from '@slack/bolt/dist/types/helpers.js';

export const registerAppUninstalledEvent = (app: App<StringIndexed>) => {
app.event('app_uninstalled', async ({ context }) => {
try {
const store = new BlockfrostInstallationStore({ logger: logger });

await store.deleteInstallation({
teamId: context.teamId,
enterpriseId: context.enterpriseId,
isEnterpriseInstall: context.isEnterpriseInstall,
});
} catch (error) {
logger.error(error);
}
});
};

0 comments on commit 02f2460

Please sign in to comment.