-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Message Metadata Support to Bolt JS (#1508)
* adding message metadata support * adding deleted_ts to MessageMetadataDeletedEvent * adding missing prop deleted_ts to support message_metadata_deleted payload * adding message metadata simple example * bumping @slack\types in top-level package.json
- Loading branch information
1 parent
2e6e6c0
commit fef721f
Showing
9 changed files
with
283 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# node / npm | ||
node_modules/ | ||
package-lock.json | ||
.env |
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,44 @@ | ||
# Bolt for JavaScript Message Metadata | ||
|
||
This is a quick example app to test [Message Metadata](https://api.slack.com/metadata) with Bolt for JavaScript. | ||
|
||
Before we get started, make sure you have a development workspace where you have permissions to install apps. If you don’t have one setup, go ahead and [create one](https://slack.com/create). You also need to [create a new app](https://api.slack.com/apps?new_app=1) if you haven’t already. You will need to enable Socket Mode and generate an App Level Token. | ||
|
||
## Install Dependencies | ||
|
||
``` | ||
npm install | ||
``` | ||
|
||
## Subscribe to Message Metadata events | ||
|
||
Go to the Events Subscription page from your app configuration, and subcribe to `message_metadata_deleted`, `message_metadata_posted`, and `message_metadata_updated` bot events. Additionally, go to the App Manifest page and update the `metadata subscriptions` like the following: | ||
|
||
``` | ||
settings: | ||
event_subscriptions: | ||
bot_events: | ||
- message_metadata_deleted | ||
- message_metadata_posted | ||
- message_metadata_updated | ||
metadata_subscriptions: | ||
- app_id: YOUR_APP_ID | ||
event_type: my_event | ||
``` | ||
|
||
## Setup Environment Variables | ||
|
||
This app requires you setup a few environment variables. You can find these values in your [app configuration](https://api.slack.com/apps). | ||
|
||
```bash | ||
export SLACK_BOT_TOKEN=YOUR_SLACK_BOT_TOKEN | ||
export SLACK_APP_TOKEN=YOUR_SLACK_APP_TOKEN | ||
``` | ||
|
||
## Run the App | ||
|
||
Start the app with the following command: | ||
|
||
``` | ||
npm start | ||
``` |
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,51 @@ | ||
{ | ||
"display_information": { | ||
"name": "Message Metadata Example" | ||
}, | ||
"features": { | ||
"bot_user": { | ||
"display_name": "Message Metadata Bot", | ||
"always_online": false | ||
}, | ||
"slash_commands": [ | ||
{ | ||
"command": "/post", | ||
"description": "Post Message Metadata", | ||
"should_escape": false | ||
} | ||
] | ||
}, | ||
"oauth_config": { | ||
"redirect_urls": [ | ||
"https://localhost" | ||
], | ||
"scopes": { | ||
"bot": [ | ||
"metadata.message:read", | ||
"chat:write", | ||
"commands" | ||
] | ||
} | ||
}, | ||
"settings": { | ||
"event_subscriptions": { | ||
"bot_events": [ | ||
"message_metadata_deleted", | ||
"message_metadata_posted", | ||
"message_metadata_updated" | ||
], | ||
"metadata_subscriptions": [ | ||
{ | ||
"app_id": "[app id]", | ||
"event_type": "my_event" | ||
} | ||
] | ||
}, | ||
"interactivity": { | ||
"is_enabled": true | ||
}, | ||
"org_deploy_enabled": false, | ||
"socket_mode_enabled": true, | ||
"token_rotation_enabled": false | ||
} | ||
} |
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,55 @@ | ||
const { App, LogLevel } = require('@slack/bolt'); | ||
|
||
const app = new App({ | ||
token: process.env.SLACK_BOT_TOKEN, | ||
appToken: process.env.SLACK_APP_TOKEN, | ||
socketMode: true, | ||
logLevel: LogLevel.DEBUG | ||
}); | ||
|
||
(async () => { | ||
await app.start(); | ||
console.log('⚡️ Bolt app started'); | ||
})(); | ||
|
||
|
||
// Listen to slash command | ||
// Post a message with Message Metadata | ||
app.command('/post', async ({ ack, command, say }) => { | ||
await ack(); | ||
await say({ | ||
text: "Message Metadata Posting", | ||
metadata: { | ||
"event_type": "my_event", | ||
"event_payload": { | ||
"key": "value" | ||
} | ||
} | ||
}); | ||
}); | ||
|
||
app.event('message_metadata_posted', async ({ event, say }) => { | ||
const { message_ts: thread_ts } = event; | ||
await say({ | ||
text: "Message Metadata Posted", | ||
blocks: [ | ||
{ | ||
"type": "section", | ||
"text": { | ||
"type": "mrkdwn", | ||
"text": "Message Metadata Posted" | ||
} | ||
}, | ||
{ | ||
"type": "context", | ||
"elements": [ | ||
{ | ||
"type": "mrkdwn", | ||
"text": `${JSON.stringify(event.metadata)}` | ||
} | ||
] | ||
} | ||
], | ||
thread_ts | ||
}) | ||
}); |
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,15 @@ | ||
{ | ||
"name": "bolt-message-metadata-example", | ||
"version": "1.0.0", | ||
"description": "Example app to manage Message Metadata events.", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "node app.js", | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "Slack Technologies, LLC", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@slack/bolt": "^3.12.0" | ||
} | ||
} |
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
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