diff --git a/src/new-proposals-monitoring.service.ts b/src/new-proposals-monitoring.service.ts index 1de6414..0cdcc3d 100644 --- a/src/new-proposals-monitoring.service.ts +++ b/src/new-proposals-monitoring.service.ts @@ -4,6 +4,7 @@ import { DialectSdkNotification, Monitor, Monitors, + NotificationSink, Pipelines, } from '@dialectlabs/monitor'; import { Duration } from 'luxon'; @@ -18,11 +19,15 @@ import { import { ConsoleNotificationSink } from './console-notification-sink'; import { OnEvent } from '@nestjs/event-emitter'; import { CachingEventType } from './realms-cache'; +import { + TwitterNotification, + TwitterNotificationsSink, +} from './twitter-notifications-sink'; @Injectable() export class NewProposalsMonitoringService { - // private readonly twitterNotificationsSink: NotificationSink = - // new TwitterNotificationsSink(); + private readonly twitterNotificationsSink: NotificationSink = + new TwitterNotificationsSink(); private readonly logger = new Logger(NewProposalsMonitoringService.name); @@ -61,30 +66,7 @@ export class NewProposalsMonitoringService { id: NOTIF_TYPE_ID_PROPOSALS, }, }) - .custom( - ({ value, context }) => { - const realmName: string = context.origin.realm.account.name; - const realmId: string = context.origin.realm.pubkey.toBase58(); - const message: string = this.constructMessage( - realmName, - realmId, - value, - ); - this.logger.log( - `Sending message for ${context.origin.subscribers.length} subscribers of realm ${realmId} : ${message}`, - ); - return { - title: `New proposal for ${realmName}`, - message, - }; - }, - new ConsoleNotificationSink(), - { - dispatch: 'multicast', - to: (ctx) => ctx.origin.subscribers, - }, - ) - // .dialectSdk( + // .custom( // ({ value, context }) => { // const realmName: string = context.origin.realm.account.name; // const realmId: string = context.origin.realm.pubkey.toBase58(); @@ -101,23 +83,46 @@ export class NewProposalsMonitoringService { // message, // }; // }, - // { dispatch: 'multicast', to: ({ origin }) => origin.subscribers }, - // ) - // .custom( - // ({ value, context }) => { - // const realmName: string = context.origin.realm.account.name; - // const realmId: string = context.origin.realm.pubkey.toBase58(); - // const message = this.constructMessage(realmName, realmId, value); - // this.logger.log(`Sending tweet for ${realmName} : ${message}`); - // return { - // message, - // }; - // }, - // this.twitterNotificationsSink, + // new ConsoleNotificationSink(), // { - // dispatch: 'broadcast', + // dispatch: 'multicast', + // to: (ctx) => ctx.origin.subscribers, // }, // ) + .dialectSdk( + ({ value, context }) => { + const realmName: string = context.origin.realm.account.name; + const realmId: string = context.origin.realm.pubkey.toBase58(); + const message: string = this.constructMessage( + realmName, + realmId, + value, + ); + this.logger.log( + `Sending message for ${context.origin.subscribers.length} subscribers of realm ${realmId} : ${message}`, + ); + return { + title: `New proposal for ${realmName}`, + message, + }; + }, + { dispatch: 'multicast', to: ({ origin }) => origin.subscribers }, + ) + .custom( + ({ value, context }) => { + const realmName: string = context.origin.realm.account.name; + const realmId: string = context.origin.realm.pubkey.toBase58(); + const message = this.constructMessage(realmName, realmId, value); + this.logger.log(`Sending tweet for ${realmName} : ${message}`); + return { + message, + }; + }, + this.twitterNotificationsSink, + { + dispatch: 'broadcast', + }, + ) .and() .build() ); diff --git a/src/proposal-state-monitoring.service.ts b/src/proposal-state-monitoring.service.ts index 3571dd4..5f22b40 100644 --- a/src/proposal-state-monitoring.service.ts +++ b/src/proposal-state-monitoring.service.ts @@ -84,25 +84,7 @@ export class ProposalStateChangeMonitoringService { id: NOTIF_TYPE_ID_PROPOSALS, }, }) - // .dialectSdk( - // ({ value, context }) => { - // const realmId: string = context.origin.realm.pubkey.toBase58(); - // const notification = this.constructNotification( - // context.origin.realm.account, - // realmId, - // value, - // ); - // this.logger.log( - // `Sending message for ${context.origin.realmSubscribers.length} subscribers of realm ${realmId} - // ${notification.title} - // ${notification.message} - // `, - // ); - // return notification; - // }, - // { dispatch: 'multicast', to: ({ origin }) => origin.realmSubscribers }, - // ) - .custom( + .dialectSdk( ({ value, context }) => { const realmId: string = context.origin.realm.pubkey.toBase58(); const notification = this.constructNotification( @@ -112,18 +94,39 @@ export class ProposalStateChangeMonitoringService { ); this.logger.log( `Sending message for ${context.origin.realmSubscribers.length} subscribers of realm ${realmId} - ${notification.title} - ${notification.message} - `, + ${notification.title} + ${notification.message} + `, ); return notification; }, - new ConsoleNotificationSink(), { dispatch: 'multicast', to: ({ origin }) => origin.realmSubscribers, }, ) + // .custom( + // ({ value, context }) => { + // const realmId: string = context.origin.realm.pubkey.toBase58(); + // const notification = this.constructNotification( + // context.origin.realm.account, + // realmId, + // value, + // ); + // this.logger.log( + // `Sending message for ${context.origin.realmSubscribers.length} subscribers of realm ${realmId} + // ${notification.title} + // ${notification.message} + // `, + // ); + // return notification; + // }, + // new ConsoleNotificationSink(), + // { + // dispatch: 'multicast', + // to: ({ origin }) => origin.realmSubscribers, + // }, + // ) .and() .build() );