Skip to content

Commit

Permalink
feat: /blockfrost help command
Browse files Browse the repository at this point in the history
  • Loading branch information
slowbackspace committed Oct 30, 2023
1 parent 4016da4 commit fc68a56
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 96 deletions.
27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,58 +214,65 @@ To speed up your setup process, simply copy and paste the following JSON into th
"slash_commands": [
{
"command": "/tx",
"url": "<YOUR-DOMAIN>/slack/events",
"url": "https://slack-integration.blockfrost.io/slack/events",
"description": "Retrieves content of the requested transaction",
"usage_hint": "[hash]",
"should_escape": false
},
{
"command": "/link",
"url": "<YOUR-DOMAIN>/slack/events",
"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": "<YOUR-DOMAIN>/slack/events",
"url": "https://slack-integration.blockfrost.io/slack/events",
"description": "Retrieves information about a specific asset",
"usage_hint": "<hex>",
"should_escape": false
},
{
"command": "/block",
"url": "<YOUR-DOMAIN>/slack/events",
"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": "<YOUR-DOMAIN>/slack/events",
"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": "<YOUR-DOMAIN>/slack/events",
"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": "<YOUR-DOMAIN>/slack/events",
"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": [
"<YOUR-DOMAIN>/slack/oauth_redirect"
"https://slack-integration.blockfrost.io/slack/oauth_redirect"
],
"scopes": {
"bot": [
Expand All @@ -281,7 +288,7 @@ To speed up your setup process, simply copy and paste the following JSON into th
},
"settings": {
"event_subscriptions": {
"request_url": "<YOUR-DOMAIN>/slack/events",
"request_url": "https://slack-integration.blockfrost.io/slack/events",
"bot_events": [
"member_joined_channel",
"message.channels",
Expand All @@ -290,7 +297,7 @@ To speed up your setup process, simply copy and paste the following JSON into th
},
"interactivity": {
"is_enabled": true,
"request_url": "<YOUR-DOMAIN>/slack/events"
"request_url": "https://slack-integration.blockfrost.io/slack/events"
},
"org_deploy_enabled": false,
"socket_mode_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 @@ -13,6 +13,7 @@ import { registerWelcomeMessage } from './events/welcome-message.js';
import { registerWebhookEndpoint } from './events/webhook-endpoint.js';
import { registerAccountCommand } from './commands/account/account.js';
import { registerPoolCommand } from './commands/pool/pool.js';
import { registerBlockfrostHelpCommand } from './commands/blockfrost-help/blockfrost-help.js';
const { App, ExpressReceiver, LogLevel } = bolt;

if (!process.env.SLACK_SIGNING_SECRET) {
Expand Down Expand Up @@ -58,6 +59,7 @@ registerBlockCommand(app);
registerAddressCommand(app);
registerAccountCommand(app);
registerPoolCommand(app);
registerBlockfrostHelpCommand(app);

registerWelcomeMessage(app);
registerWebhookEndpoint(expressReceiver);
Expand Down
36 changes: 36 additions & 0 deletions src/commands/blockfrost-help/blockfrost-help.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { App } from '@slack/bolt';
import { StringIndexed } from '@slack/bolt/dist/types/helpers.js';
import messages from '../../messages.js';
import { BlockfrostClient } from '../../services/blockfrost/index.js';
import { parseCommand } from '../../utils/command.js';
import { getWelcomeMessage } from '../../events/welcome-message.js';

export const registerBlockfrostHelpCommand = (app: App<StringIndexed>) => {
app.command('/blockfrost', async ({ command, ack, client, say }) => {
// Acknowledge command request
await ack();
const { args } = parseCommand(command);
const subCommand = args[0]?.trim();

if (!subCommand) {
await say(messages.CMD_UNKNOWN_COMMAND);
return;
}

try {
await client.chat.postEphemeral({
channel: command.channel_id,
user: command.user_id,
blocks: getWelcomeMessage(),
});
} catch (error) {
const response = BlockfrostClient.handleError(error, command.text);

await client.chat.postEphemeral({
channel: command.channel_id,
user: command.user_id,
...response,
});
}
});
};
173 changes: 89 additions & 84 deletions src/events/welcome-message.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,96 @@
import { App } from '@slack/bolt';
import { ChatPostMessageArguments } from '@slack/web-api';
import { StringIndexed } from '@slack/bolt/dist/types/helpers.js';
import { dbStore } from '../services/db/index.js';
import { getInstallationId } from '../utils/slack.js';

export const getWelcomeMessage = (): ChatPostMessageArguments['blocks'] => {
return [
{
type: 'header',
text: {
type: 'plain_text',
text: ':wave: Welcome to Blockfrost for Slack!',
},
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: "This Slack app aims to provide you with seamless interactions and real-time updates from Blockfrost's blockchain services right here in Slack.",
},
},
{
type: 'divider',
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: "*Here's a quick rundown of what you can expect:*",
},
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: ':mag: *Query Blockchain Data*: Quickly fetch addresses, transactions, assets and more.\n:bell: *Real-time Alerts*: Set up webhooks to get real-time notifications for blockchain events.\n:gear: *Easy Configuration*: Link your Blockfrost projects and webhooks in just a few clicks.',
},
},
{
type: 'divider',
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: ':bulb: *Getting Started*',
},
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: '1. Link your Blockfrost project with `/link project`.\n2. Link your Blockfrost webhook for real-time updates `/link webhook`.\n3. Type `/blockfrost help` to view available commands.',
},
},
{
type: 'divider',
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: ':wrench: *Commands*',
},
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: '- To fetch a block: `/block [<hash-or-number>]`\n- To fetch a transaction: `/tx <hash>`\n- To fetch an asset: `/asset <hex-or-bech32>`\n- To fetch an address: `/address <bech32 address>`\n- To fetch an account: `/account <bech32 stake address>\n- To fetch a pool: `/pool <poolId>`\n\n*Additional Parameters:*\n- Use `--json` to get the output in JSON format.\n- Use `--network` to specify the blockchain network. For example, `/block <hash-or-number> --network testnet`.',
},
},
{
type: 'divider',
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: 'If you have any questions or run into any issues, feel free to reach out here or email us at <mailto:[email protected]|[email protected]>.',
},
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: ":rocket: Let's get started!",
},
},
];
};

export const registerWelcomeMessage = (app: App<StringIndexed>) => {
app.event('member_joined_channel', async ({ event, client, body }) => {
const installationId = getInstallationId(body);
Expand All @@ -19,90 +107,7 @@ export const registerWelcomeMessage = (app: App<StringIndexed>) => {
// Send a welcome message to the channel
await client.chat.postMessage({
channel: event.channel,
blocks: [
{
type: 'header',
text: {
type: 'plain_text',
text: ':wave: Welcome to Blockfrost for Slack!',
},
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: "This Slack app aims to provide you with seamless interactions and real-time updates from Blockfrost's blockchain services right here in Slack.",
},
},
{
type: 'divider',
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: "*Here's a quick rundown of what you can expect:*",
},
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: ':mag: *Query Blockchain Data*: Quickly fetch addresses, transactions, assets and more.\n:bell: *Real-time Alerts*: Set up webhooks to get real-time notifications for blockchain events.\n:gear: *Easy Configuration*: Link your Blockfrost projects and webhooks in just a few clicks.',
},
},
{
type: 'divider',
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: ':bulb: *Getting Started*',
},
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: '1. Link your Blockfrost project with `/link project`.\n2. Link your Blockfrost webhook for real-time updates `/link webhook`.\n3. Type `/blockfrost help` to view available commands.',
},
},
{
type: 'divider',
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: ':wrench: *Commands*',
},
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: '- To fetch a block: `/block [<hash-or-number>]`\n- To fetch a transaction: `/tx <hash>`\n- To fetch an asset: `/asset <hex-or-bech32>`\n- To fetch an address: `/address <bech32 address>`\n- To fetch an account: `/account <bech32 stake address>\n- To fetch a pool: `/pool <poolId>`\n\n*Additional Parameters:*\n- Use `--json` to get the output in JSON format.\n- Use `--network` to specify the blockchain network. For example, `/block <hash-or-number> --network testnet`.',
},
},
{
type: 'divider',
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: 'If you have any questions or run into any issues, feel free to reach out here or email us at <mailto:[email protected]|[email protected]>.',
},
},
{
type: 'section',
text: {
type: 'mrkdwn',
text: ":rocket: Let's get started!",
},
},
],
blocks: getWelcomeMessage(),
});
} catch (error) {
console.error(error);
Expand Down
5 changes: 3 additions & 2 deletions src/messages.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export default {
CMD_LINK_PROJECT: 'To link project type /link project <SECRET>',
CMD_UNKNOWN_COMMAND: 'Unknown command. Use `/blockfrost help` for list of available commands.',
CMD_LINK_PROJECT: 'To link project type `/link project <SECRET>`',
CMD_LINK_HELP:
'To link Blockfrost project or webhook type /link project <SECRET> or /link webhook',
'To link Blockfrost project or webhook type `/link project <SECRET>` or `/link webhook`',
} as const;

0 comments on commit fc68a56

Please sign in to comment.