Skip to content
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

Merged
merged 10 commits into from Jul 13, 2022
Merged

Adding Message Metadata Support to Bolt JS #1508

merged 10 commits into from Jul 13, 2022

Conversation

dannyhostetler
Copy link
Contributor

@dannyhostetler dannyhostetler commented Jun 30, 2022

Summary

The PR introduces support for Message Metadata events within the Bolt framework. This should be paired together with slackapi/node-slack-sdk#1504 as the "MessageMetadata" is defined within.

Support for MessageMetadataPostedEvent, MessageMetadataUpdated and MessageMetadataDeletedEvent are introduced within this PR.

Requirements (place an x in each [ ])

@dannyhostetler
Copy link
Contributor Author

Regarding Issue #1507

@seratch seratch added this to the 3.12.0 milestone Jul 1, 2022
@seratch seratch added the enhancement M-T: A feature request for new functionality label Jul 1, 2022
Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically looks great to me but I have one additional change request 🙇

bot_id?: string;
user_id: string;
team_id: string;
message_ts: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add deleted_ts: string too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another good catch, this is done 👍

@CLAassistant
Copy link

CLAassistant commented Jul 1, 2022

CLA assistant check
All committers have signed the CLA.

@seratch
Copy link
Member

seratch commented Jul 1, 2022

As the CI build failure shows, this pull request requires a new version release of @slack/types. Let me convert this PR to draft mode for now.

@seratch seratch marked this pull request as draft July 1, 2022 06:34
@dannyhostetler
Copy link
Contributor Author

I'm assuming we would wait for this milestone before consider merging this PR, right?

@seratch
Copy link
Member

seratch commented Jul 4, 2022

@dannyhostetler Thanks for checking the milestone. Since other tasks that were listed there need more time, I've moved them to other milestones. We will release a new package version shortly.

@seratch
Copy link
Member

seratch commented Jul 4, 2022

types v2.6.0 is now available https://github.com/slackapi/node-slack-sdk/releases/tag/%40slack%2Ftypes%402.6.0

@seratch seratch marked this pull request as ready for review July 4, 2022 05:09
@seratch
Copy link
Member

seratch commented Jul 4, 2022

Can you fix the test failure detected by GitHub Actions jobs?

TSError: ⨯ Unable to compile TypeScript:
Error: src/types/events/message-events.spec.ts(230,11): error TS2322: Type '{ type: "message_metadata_deleted"; channel_id: string; event_ts: string; previous_metadata: { event_type: string; event_payload: { key: string; }; }; app_id: string; bot_id: string; user_id: string; team_id: string; message_ts: string; }' is not assignable to type 'MessageMetadataEvent'.
  Property 'deleted_ts' is missing in type '{ type: "message_metadata_deleted"; channel_id: string; event_ts: string; previous_metadata: { event_type: string; event_payload: { key: string; }; }; app_id: string; bot_id: string; user_id: string; team_id: string; message_ts: string; }' but required in type 'MessageMetadataDeletedEvent'.

@codecov
Copy link

codecov bot commented Jul 5, 2022

Codecov Report

Merging #1508 (7a7c82b) into main (7eec438) will increase coverage by 0.06%.
The diff coverage is 100.00%.

❗ Current head 7a7c82b differs from pull request most recent head 43beefa. Consider uploading reports for the commit 43beefa to get more accurate results

@@            Coverage Diff             @@
##             main    #1508      +/-   ##
==========================================
+ Coverage   82.00%   82.07%   +0.06%     
==========================================
  Files          18       18              
  Lines        1495     1495              
  Branches      435      435              
==========================================
+ Hits         1226     1227       +1     
  Misses        172      172              
+ Partials       97       96       -1     
Impacted Files Coverage Δ
src/types/middleware.ts 100.00% <ø> (ø)
src/App.ts 84.11% <100.00%> (+0.23%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7eec438...43beefa. Read the comment docs.

Copy link
Contributor

@filmaj filmaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, this looks good to me!

I did have one question and one suggestion.

Suggestion: what about adding a very simple example to the examples/ directory that includes showing an app listening to metadata events as well as using these types? I think that would be helpful to a lot of people, as well as for us the maintainers, whom have to quickly reproduce different scenarios for how people build apps. I always use the examples a lot to help with triaging new incoming issues.

Question: do we need to take these metadata events into account in the event / middleware processing chain in bolt? In particular, the conversation ID extraction logic. This method has different logic to pull out the conversation ID based on the kind of event being received. Do we need to add some more logic to take into account the message metadata event structure here?

Thanks a lot for taking the time to send these pull requests, it is very much appreciated 🙏

@seratch
Copy link
Member

seratch commented Jul 5, 2022

@filmaj

Question: do we need to take these metadata events into account in the event / middleware processing chain in bolt? In particular, the conversation ID extraction logic. This method has different logic to pull out the conversation ID based on the kind of event being received. Do we need to add some more logic to take into account the message metadata event structure here?

No, I don't think so. The conversation ID is supposed to be used only by https://slack.dev/bolt-js/concepts#conversation-store and the convo store feature is associated with message-type events. If a developer intentionally use metadata events only, I am sure that the developer does not expect convo store to work with convo store well.

Also, in reality, I think that the convo store is not used a lot. The feature was added to provide an alternative for hubot's brain: https://slack.dev/bolt-js/tutorial/hubot-migration#migrating-the-brain-to-the-conversation-store There is no downside to keep the feature so far but, in future major versions, we may consider deprecating the feature or removing the feature from the core module.

@dannyhostetler
Copy link
Contributor Author

@filmaj

Suggestion: what about adding a very simple example to the examples/ directory that includes showing an app listening to metadata events as well as using these types? I think that would be helpful to a lot of people, as well as for us the maintainers, whom have to quickly reproduce different scenarios for how people build apps. I always use the examples a lot to help with triaging new incoming issues.

Fantastic suggestion, and thanks for the feedback! Agreed, I myself am always referring to these examples. I'm working on mocking up a simple example RE: Message Metadata events and I'll get it pushed within the next day or so.

@filmaj
Copy link
Contributor

filmaj commented Jul 6, 2022

Ah, thanks for educating me on that @seratch !


app.event('message_metadata_posted', async ({ event, say }) => {
const { message_ts: thread_ts } = event;
say({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
say({
await say({

Copy link
Contributor Author

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.

// Post a message with Message Metadata
app.command('/post', async ({ ack, command, say }) => {
await ack();
say({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
say({
await say({

Copy link
Contributor Author

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.

@filmaj
Copy link
Contributor

filmaj commented Jul 12, 2022

Hey @dannyhostetler ! One thing I noticed trying to get the example running by linking up the bolt-js root repo first is I get this error:

➜ npm link
npm ERR! code 2
npm ERR! path /Users/fmaj/src/bolt-js
npm ERR! command failed
npm ERR! command sh -c npm run build
npm ERR! > @slack/bolt@3.11.3 build
npm ERR! > tsc
npm ERR!
npm ERR! src/types/events/message-events.ts(1,48): error TS2305: Module '"@slack/types"' has no exported member 'MessageMetadata'.

I think that's because @slack/types didn't introduce support for MessageMetadata until v2.6.0. So I think we need to bump the @slack/types in package.json to be at least 2.6.0.

Odd that the CI didn't pick this up... I guess because the semver specifier for @slack/types in package.json is ^2.4.0, and CI installs a fresh copy of the types, so it gets the latest version just fine. But I guess on my system I had an earlier version installed locally and thus the error.

@dannyhostetler
Copy link
Contributor Author

Hey @dannyhostetler ! One thing I noticed trying to get the example running by linking up the bolt-js root repo first is I get this error:

➜ npm link
npm ERR! code 2
npm ERR! path /Users/fmaj/src/bolt-js
npm ERR! command failed
npm ERR! command sh -c npm run build
npm ERR! > @slack/bolt@3.11.3 build
npm ERR! > tsc
npm ERR!
npm ERR! src/types/events/message-events.ts(1,48): error TS2305: Module '"@slack/types"' has no exported member 'MessageMetadata'.

I think that's because @slack/types didn't introduce support for MessageMetadata until v2.6.0. So I think we need to bump the @slack/types in package.json to be at least 2.6.0.

Odd that the CI didn't pick this up... I guess because the semver specifier for @slack/types in package.json is ^2.4.0, and CI installs a fresh copy of the types, so it gets the latest version just fine. But I guess on my system I had an earlier version installed locally and thus the error.

@filmaj Think this should be good now. For what ever reason I explicitly removed that from the package.json because @slack\types is a dependency package of bolt and didn't think it was needed. Anywho, give it a try again and see if this works for you.

@filmaj
Copy link
Contributor

filmaj commented Jul 12, 2022

@dannyhostetler Oh, I meant in the top-level package.json in this repo!

@dannyhostetler
Copy link
Contributor Author

@dannyhostetler Oh, I meant in the top-level package.json in this repo!

Oh ok, gotcha. Bumped to ^2.7.0. Thanks for keeping me inline on this one 🤝

@filmaj
Copy link
Contributor

filmaj commented Jul 12, 2022

OK, got the package building! However, I can't seem to trigger the message_metadata_posted event in the app 🤔 I added the /post slash command to my app definition on api.slack.com/apps, as well as subscribed the app to the message_metadata_posted event. The /post works, and the bot answers "Message Metadata Posting", but can't seem to get the "Message Metadata Posted" event to trigger...

I'll try to dig in more tomorrow to see what's going on.

@dannyhostetler
Copy link
Contributor Author

@filmaj I'm willing to bet it's because you're missing metadata_subscriptions in your manifest.

"event_subscriptions": { "bot_events": [ "message_metadata_deleted", "message_metadata_posted", "message_metadata_updated" ], "metadata_subscriptions": [ { "app_id": "[your app id]", "event_type": "my_event" } ] },

@filmaj
Copy link
Contributor

filmaj commented Jul 13, 2022

You would have won that bet @dannyhostetler !

Last request for this PR: can we add a basic README.md to the example directory that details the setup instructions for this app? Maybe as simple as "create an app on api.slack.com/apps from scratch, note down the App ID, open up the manifest editor on api.slack.com/apps/, paste in the contents of app-manifest.json, update the reference to your App ID in there, save it. Install to a workspace. Export the your app and bot tokens as env vars. Run the app with node app.js. In your workspace run the /post slash command. Voila!'. Just something along the lines of the examples/oauth/README.md, maybe?

@dannyhostetler
Copy link
Contributor Author

dannyhostetler commented Jul 13, 2022

@filmaj Yeah, the metadata subscription is a bit tricky (and I don't personally like how you have to specify the app id, I think should it be able to dynamically determine 🤷). No biggie on the README, I should have actually added one earlier (probably just being lazy). I'm traveling over the next day or so, so I'll get this pushed sometime this week.

@filmaj
Copy link
Contributor

filmaj commented Jul 13, 2022

Yes I agree with you re: entering the App ID, seems like us-at-Slack should be able to infer that 🤨 I'll raise that internally to see if that can be improved.

And thank you for following up on all my requests 🙏 really appreciate your collaboration on this 🙇

@dannyhostetler
Copy link
Contributor Author

@filmaj Actually just went ahead and did this now. Added a basic README, hope this looks good

Copy link
Contributor

@filmaj filmaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes!!! 🎉 Thanks a lot, looks great, dropping an approval here, as soon as the CI passes will merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement M-T: A feature request for new functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants