bolt-js icon indicating copy to clipboard operation
bolt-js copied to clipboard

`message_replied` event missing text property in typescript

Open stephenkalnoske-sans opened this issue 3 years ago • 1 comments

Description

The text property does not exist on MessageRepliedEvent interface in typescript

What type of issue is this? (place an x in one of the [ ])

  • [x] bug
  • [ ] enhancement (feature request)
  • [ ] question
  • [ ] documentation related
  • [ ] example code related
  • [ ] testing related
  • [ ] discussion

Requirements (place an x in each of the [ ])

  • [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [x] I've read and agree to the Code of Conduct.
  • [x] I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Reproducible in:

package version: 3.12.1

node version: 16.3.2

OS version(s): MacOS 12.4

Steps to reproduce:

slackApp.message(subtype("message_replied"), async ({ message }) => {
  if (message.subtype === "message_replied") {
    const messageThreadId = message.message.thread_ts;

    // Find the socket for the given thread ID
    for (const connection in openConnections) {
      const connectionProps = openConnections[connection];
      if (connectionProps.thread === messageThreadId) {
        connectionProps.socket.send(message.message.text); <---
      }
    }
  }
})

Expected result:

message.message.text is type string per event documentation:

https://api.slack.com/events/message/message_replied

Actual result:

Property 'text' does not exist on type 'MessageEvent & { thread_ts: string; reply_count: number; replies: MessageEvent[]; }'.
  Property 'text' does not exist on type 'MessageChangedEvent & { thread_ts: string; reply_count: number; replies: MessageEvent[]; }'

Attachments:

Screen Shot 2022-09-01 at 5 27 23 PM

stephenkalnoske-sans avatar Sep 01 '22 21:09 stephenkalnoske-sans

Hi @stephenkalnoske-sans, thanks for taking the time to report this issue!

Indeed, the type definition seems to be incorrect, and it should be fixed. However, as mentioned in the event data document page, the Slack Platform never sends this subtype event payload as of today:

Bug alert! This event is missing the subtype field when dispatched over the Events API. Until it is fixed, examine message events' thread_ts value. When present, it's a reply. To be doubly sure, compare a thread_ts to the top-level ts value, when they differ the latter is a reply to the former. https://api.slack.com/events/message/message_replied

Just in case, I've verified the behavior on my end and found that the bug still exists. You will receive only GenericMessageEvent for the replies in a thread. Thus, please go ahead with the following code instead:

app.message(async ({ message }) => {
  if (message.subtype === undefined && message.thread_ts !== undefined) {
    // do the stuff here
    message.text; // this line compiles
  }
});

I hope this was helpful to you.

seratch avatar Sep 02 '22 07:09 seratch