Note that unless you’re a Lemmy instance admin, this doesn’t have much use to you.

Until this package came along, if you wanted a bot that responds to events, you had to manually traverse all comments/posts/whatever at a fixed interval. With this package you can actually react to events directly from the database. It’s implemented in a very efficient way by connecting the package directly to the Lemmy database and using native Postgres features to get the events (LISTEN/NOTIFY if you want to get technical).

The webhooks themselves are inserted into a separate SQLite database (API is coming) and allow for both simple and complex filtering of the incoming data. The system is already in use by two of my bots, @ChatGPT@lemmings.world and @DallE@lemmings.world who now both receive the information about being tagged in a comment in seconds (the actual reply takes a little longer, but that’s because of the nature of the bot).

Currently you can be notified about a post or a comment, other types are trivial to include as well.

Let me know what you think!

    • Rikudou_Sage@lemmings.worldOP
      link
      fedilink
      English
      arrow-up
      2
      ·
      6 months ago

      Yep, it uses pushing from the postgres to the webhook processor instead of polling for data periodically by an app. So after every insert, an event is pushed using the native postgres listen/notify mechanism and then the webhook processor doesn’t interact with the database at all.

      • originalucifer@moist.catsweat.com
        link
        fedilink
        arrow-up
        2
        ·
        6 months ago

        yeah, but im seeing a reference to the doubling of my standing-processing as now i have an insert-after-event that didnt exist before… is that right?

        i mean i get that youre pushing the processing to a different, functional mechanism, but its still additive processing on the server that needs accounting… and seems expanded.

        • Rikudou_Sage@lemmings.worldOP
          link
          fedilink
          English
          arrow-up
          1
          ·
          6 months ago

          Yeah, everything you do takes processing power. This is done in a way that minimises the impact. There’s no insert-after-event that I’m aware of. Also I’m not sure what you mean by expanded.

          • originalucifer@moist.catsweat.com
            link
            fedilink
            arrow-up
            1
            ·
            6 months ago

            Yeah, everything you do takes processing power. So after every insert, an event is pushed using the native postgres listen/notify mechanism

            right, i was just curious how much processing this is. it gets expensive quick on a large instance, efficiency matters. might be negligible, but i watch my services like a hawk.

  • Asudox@lemmy.world
    link
    fedilink
    English
    arrow-up
    2
    ·
    6 months ago

    This is awesome. I really like that. Hope it becomes an official optional setting you can turn on or off in the instance config.

  • solrize@lemmy.world
    link
    fedilink
    English
    arrow-up
    1
    ·
    6 months ago

    I’d rather have fewer bots on Lemmy, but from an implementation pov I wonder whether a pub-sub interface could keep up better with fast updates. Do webhooks make a new outgoing tls connection on every event?

    • Rikudou_Sage@lemmings.worldOP
      link
      fedilink
      English
      arrow-up
      2
      ·
      6 months ago

      Pub-sub might work for some use cases, but it wouldn’t work at all for mine. I host my bots on AWS Lambda so I don’t pay for anything, unless the code is actually running. So the webhook essentially wakes the virtual machine up and after processing is done, it goes back to sleep.

      Yeah, they make a new ongoing tls connection on every https webhook. Which doesn’t necessarily mean all db events, there’s quite powerful filtering available and everyone should use it, sending a ping for db events you don’t need to seems quite wasteful.

      • solrize@lemmy.world
        link
        fedilink
        English
        arrow-up
        1
        ·
        edit-2
        6 months ago

        If we maintain the fantasy (and we may as well) of Lemmy someday overtaking Reddit, that can mean 100s of new posts per second that bots might want to inspect. So that’s quite a lot of vm restarts as well as load on the side sending out the webhook queries. I guess this stuff will have been redesigned a few more times by then though, so it is ok. Lemmy at the moment isn’t ready for such volume for many other reasons too.

        • Rikudou_Sage@lemmings.worldOP
          link
          fedilink
          English
          arrow-up
          1
          ·
          6 months ago

          Well, it stays warmed up some 15 seconds or so, but the important part is you don’t pay for that uptime. And if my bots ever get to 100s of requests per second, I’m gonna have to shut them down, I’m not that rich.