Coder Social home page Coder Social logo

Comments (4)

seratch avatar seratch commented on June 7, 2024 1

Hi @t6adev, thanks again. This is because your app subscribes both app_mention and message events. Regardless whether your app subscribes app_mention events, message events delivers all visible message events to your app endpoint. If you want to skip the bot mentioned message events, you can check message.text string if it does not have the mention.

Let me close this issue now, but if you have further to ask, feel free to write in!

from slack-edge.

t6adev avatar t6adev commented on June 7, 2024

Ok, thank you.
Since the app.use (= postAuthorizeMiddleware) runs before handling events, I believe we can mark the mentioned message inside Cloudflare worker's fetch (it's messyπŸ˜…)

export default {
  async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
    ...
    const current = { isAppMention: false };
    app.use(async ({ body }) => {
      const slackRequestBody = body as SlackRequestBody;
      if (slackRequestBody.type === PayloadType.EventsAPI) {
        if (slackRequestBody.event?.type === 'app_mention') {
          current.isAppMention = true;
        }
      }
    });
    ...
  }
}

slack-edge/src/app.ts

Lines 638 to 647 in 2785568

for (const middlware of this.postAuthorizeMiddleware) {
const response = await middlware(baseRequest);
if (response) {
return toCompleteResponse(response);
}
}
const payload = body as SlackRequestBody;
if (body.type === PayloadType.EventsAPI) {

from slack-edge.

seratch avatar seratch commented on June 7, 2024

Since the fetch handler can be invoked per request, your approach never works as you expect. In other words, your fetch function is always stateless (as long as you don't store the state in a database) so that your message listener never knows the current was set by a different app_mention request.

Alternatively, your message event listener can check if your app's bot user ID is mentioned in the message event. This is not specific to this slack-edge library. When you build a Slack app that subscribes both app_mention and message events, your code is responsible to handle these events.

If you need more assistance this, I am happy to help you in Japanese. Feel free to mention @seratch_ja (@seratch for English) on X. Since this is the issue tracker for managing this library's issues (bugs, enhancement ideas), I would like to stop discussing this here. It'd be appreciated if you could understand this.

from slack-edge.

t6adev avatar t6adev commented on June 7, 2024

Thank you, I respect your opinion on how you manage this repo. (I also prefer to discuss something on the GitHub discussion page.)

from slack-edge.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.