-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4016da4
commit fc68a56
Showing
5 changed files
with
147 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
@@ -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); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |