Skip to content

Commit

Permalink
save info about posts in db
Browse files Browse the repository at this point in the history
  • Loading branch information
KacperKoza343 committed Jan 23, 2025
1 parent 3876920 commit b1e9ce1
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions packages/client-instagram/src/services/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,36 @@ export class InstagramPostService {
const randomMinutes = Math.floor(Math.random() * (maxMinutes - minMinutes + 1)) + minMinutes;
const delay = randomMinutes * 60 * 1000;

if (Date.now() > lastPostTimestamp + delay) {
const shouldPost = Date.now() > lastPostTimestamp + delay;


if (shouldPost) {
await this.generateNewPost();
await this.runtime.messageManager.createMemory({
id: stringToUuid(`instagram-post-${new Date(Date.now()).toISOString()}`),
userId: this.runtime.agentId,
agentId: this.runtime.agentId,
content: {
text: '',
postPublished: `Post published at ${new Date(Date.now()).toISOString()}`,
},
roomId: stringToUuid("instagram_generate_room-" + this.state.profile?.username),
embedding: getEmbeddingZeroVector(),
createdAt: Date.now(),
});
} else {
await this.runtime.messageManager.createMemory({
id: stringToUuid(`instagram-post-${new Date(Date.now()).toISOString()}`),
userId: this.runtime.agentId,
agentId: this.runtime.agentId,
content: {
text: '',
postRejected: `Post rejected at ${new Date(Date.now()).toISOString()}`,
},
roomId: stringToUuid("instagram_generate_room-" + this.state.profile?.username),
embedding: getEmbeddingZeroVector(),
createdAt: Date.now(),
});
}

if (!this.stopProcessing) {
Expand Down Expand Up @@ -325,4 +353,4 @@ export class InstagramPostService {
throw error;
}
}
}
}

0 comments on commit b1e9ce1

Please sign in to comment.