-
Notifications
You must be signed in to change notification settings - Fork 380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Message Metadata Support to Bolt JS #1508
Changes from 5 commits
86f1ee8
e2d1229
5ff4e3d
a2b8f64
48de091
8279b5f
2fea552
8bdc8f9
cd68b23
43beefa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# node / npm | ||
node_modules/ | ||
package-lock.json | ||
.env |
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 | ||
} | ||
} |
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(); | ||||||
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; | ||||||
say({ | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My mistake, thanks for catching. This is fixed. |
||||||
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 | ||||||
}) | ||||||
}); |
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" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { MessageAttachment, KnownBlock, Block } from '@slack/types'; | ||
import { MessageAttachment, KnownBlock, Block, MessageMetadata } from '@slack/types'; | ||
|
||
export type MessageEvent = | ||
| GenericMessageEvent | ||
|
@@ -19,6 +19,11 @@ export type MessageEvent = | |
| MessageRepliedEvent | ||
| ThreadBroadcastMessageEvent; | ||
|
||
export type MessageMetadataEvent = | ||
| MessageMetadataPostedEvent | ||
| MessageMetadataUpdatedEvent | ||
| MessageMetadataDeletedEvent; | ||
|
||
export interface GenericMessageEvent { | ||
type: 'message'; | ||
subtype: undefined; | ||
|
@@ -281,6 +286,44 @@ export interface ThreadBroadcastMessageEvent { | |
channel_type: channelTypes; | ||
} | ||
|
||
export interface MessageMetadataPostedEvent { | ||
type: 'message_metadata_posted'; | ||
app_id: string; | ||
bot_id?: string; | ||
user_id: string; | ||
team_id: string; | ||
channel_id: string; | ||
metadata: MessageMetadata; | ||
message_ts: string; | ||
event_ts: string; | ||
} | ||
|
||
export interface MessageMetadataUpdatedEvent { | ||
type: 'message_metadata_updated'; | ||
channel_id: string; | ||
event_ts: string; | ||
previous_metadata: MessageMetadata; | ||
app_id: string; | ||
bot_id?: string; | ||
user_id: string; | ||
team_id: string; | ||
message_ts: string; | ||
metadata: MessageMetadata; | ||
} | ||
|
||
export interface MessageMetadataDeletedEvent { | ||
type: 'message_metadata_deleted'; | ||
channel_id: string; | ||
event_ts: string; | ||
previous_metadata: MessageMetadata; | ||
app_id: string; | ||
bot_id?: string; | ||
user_id: string; | ||
team_id: string; | ||
message_ts: string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another good catch, this is done 👍 |
||
deleted_ts: string; | ||
} | ||
|
||
export type channelTypes = 'channel' | 'group' | 'im' | 'mpim' | 'app_home'; | ||
|
||
interface BotProfile { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My mistake, thanks for catching. This is fixed.