feat: automate bounded image-sharing conversations
This commit is contained in:
1 parent
dcf57273e2
commit
3beb8aada2
15 files changed
+477
-19
No files matched your search
@@ -41,6 +41,7 @@ import {
|
||||
import { RecipientDeduplicator } from './recipient-deduplicator.js';
|
||||
import { ConfigStore } from '../config/persistence.js';
|
||||
import { createConfigBackedSubredditPollingControl } from './subreddit-polling-control.js';
|
||||
import { ConversationAutomationService } from './conversation-automation.js';
|
||||
|
||||
export interface ConcreteRuntimeFactoryOptions {
|
||||
config: Config;
|
||||
@@ -153,13 +154,21 @@ async function buildRuntime(
|
||||
sentMessageHistory: async (since) => messagesRepo.getSentTimestampsSince(since),
|
||||
});
|
||||
await rateLimiter.initialize();
|
||||
const conversationAutomation = new ConversationAutomationService(
|
||||
chatService,
|
||||
aiClient,
|
||||
conversationStateRepo,
|
||||
rateLimiter,
|
||||
logger,
|
||||
accountConfig.browser.dryRun,
|
||||
);
|
||||
|
||||
const resources: RedditAccountRuntimeResources = {
|
||||
browserProfileDir, browserClient, accountAuth, matrixClient, chatCache, redditApi,
|
||||
postsRepo, messagesRepo, successfulMessagesRepo, deliveryOutboxRepo,
|
||||
conversationStateRepo, conversationOutcomesRepo, redditUsersRepo, accountContentRepo,
|
||||
activityLogRepo,
|
||||
monitorService, processorService, responseChecker, chatService, mediaService,
|
||||
monitorService, processorService, responseChecker, conversationAutomation, chatService, mediaService,
|
||||
mediaSyncService, rateLimiter,
|
||||
};
|
||||
const lifecycle = new AccountRuntimeLoop(
|
||||
@@ -232,6 +241,20 @@ class AccountRuntimeLoop {
|
||||
if (Date.now() >= nextResponseCheckAt) {
|
||||
nextResponseCheckAt = Date.now() + responseInterval;
|
||||
await this.resources.responseChecker.checkForResponses();
|
||||
const automationResults = await this.resources.conversationAutomation.processUnreadConversations(signal);
|
||||
for (const result of automationResults) {
|
||||
if (result.kind === 'sent') continue;
|
||||
this.resources.activityLogRepo.insert({
|
||||
timestamp: Date.now(),
|
||||
type: 'response',
|
||||
message: result.kind === 'human-required'
|
||||
? `Human follow-up required for u/${result.username}`
|
||||
: result.kind === 'image-received'
|
||||
? `Image received from u/${result.username}`
|
||||
: `Automation stopped for u/${result.username} after a boundary`,
|
||||
recipient: result.username,
|
||||
});
|
||||
}
|
||||
}
|
||||
await delay(this.config.reddit.pollIntervalMs, signal);
|
||||
} catch (error) {
|
||||
|
||||
Reference in new issue
Block a user