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

How to create a bot reply without spamming user #3457

Open
thathurtabit opened this issue Jan 24, 2025 · 2 comments
Open

How to create a bot reply without spamming user #3457

thathurtabit opened this issue Jan 24, 2025 · 2 comments

Comments

@thathurtabit
Copy link

Is your feature request related to a problem? Please describe.

I've been making a simple bot with @atproto/api - the bot awaits for interactions and generates a reply and sends it.

The bot runs from a cron task every hour (currently), but each time the cron task runs, it creates a new message to the same post it found previously, creating new reply (to the same thread) every hour, until (I think) I manually view the post via the Bluesky app which then makes the post as read.

Example code:

    const notificationsResponse = await agent.listNotifications();
    const notificationsData = notificationsResponse.data;
    const { notifications } = notificationsData;

    for (const { cid, uri, isRead, reason } of notifications) {
      if (!["reply", "mention"].includes(reason)) return
      if (isRead) return; // --> how do I set `isRead` to true? Seems it's always false every cron tick

      await agent.like(uri, cid);
      await agent.post({
        text: getDarkSoulsWisdom(),
        reply: {
          root: { cid, uri },
          parent: { cid, uri }
        },
      })
      await agent.updateSeenNotifications(); // --> would this be a way to mark the notification as read? The args say `seenAt: string` - where would I get that value? How would it apply to the current notification?
    }

Describe the solution you'd like

A way of setting a notification as viewed/read/seen so isRead is true, and the bot does not reply to the same notification multiple times

Describe alternatives you've considered

My bot runs in a serverless environment, so storing local files won't work as they're ephemeral. Setting up a database for this seems overkill, perhaps.

Additional context

I'm almost certainly missing something from docs somewhere - but I'm not able to find what I'm looking for.

@thathurtabit
Copy link
Author

Update!
I've just spotted that const notificationsResponse = await agent.listNotifications();
returns a notifications and seenAt value... (listNotifications)

I'll try using the seenAt value like this (after I've replied to the notifications):
await agent.updateSeenNotifications(seenAt);

I'll see if this works...

@thathurtabit
Copy link
Author

Another update! This didn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant