Browse Source

Bugfix/twitter bot service without credentials (#8434)

* Skip twitter bot service without credentials

* Update changelog
pull/1946/merge
Thomas Kaul 18 hours ago
committed by GitHub
parent
commit
618e6c9d27
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 1
      CHANGELOG.md
  2. 8
      apps/api/src/services/configuration/configuration.service.ts
  3. 40
      apps/api/src/services/twitter-bot/twitter-bot.service.ts

1
CHANGELOG.md

@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed ### Fixed
- Fixed the duplicate data point of today in the chart of the holding detail dialog - Fixed the duplicate data point of today in the chart of the holding detail dialog
- Fixed the requests of the twitter bot service with dummy credentials
## 3.100.0 - 2026-11-15 ## 3.100.0 - 2026-11-15

8
apps/api/src/services/configuration/configuration.service.ts

@ -148,10 +148,10 @@ export class ConfigurationService {
}), }),
STRIPE_SECRET_KEY: str({ default: '' }), STRIPE_SECRET_KEY: str({ default: '' }),
TRUST_PROXY: trustProxy({ default: '' }), TRUST_PROXY: trustProxy({ default: '' }),
TWITTER_ACCESS_TOKEN: str({ default: 'dummyAccessToken' }), TWITTER_ACCESS_TOKEN: str({ default: '' }),
TWITTER_ACCESS_TOKEN_SECRET: str({ default: 'dummyAccessTokenSecret' }), TWITTER_ACCESS_TOKEN_SECRET: str({ default: '' }),
TWITTER_API_KEY: str({ default: 'dummyApiKey' }), TWITTER_API_KEY: str({ default: '' }),
TWITTER_API_SECRET: str({ default: 'dummyApiSecret' }) TWITTER_API_SECRET: str({ default: '' })
}); });
} }

40
apps/api/src/services/twitter-bot/twitter-bot.service.ts

@ -17,7 +17,7 @@ import { TwitterApi, TwitterApiReadWrite } from 'twitter-api-v2';
export class TwitterBotService implements OnModuleInit { export class TwitterBotService implements OnModuleInit {
private readonly logger = new Logger(TwitterBotService.name); private readonly logger = new Logger(TwitterBotService.name);
private twitterClient: TwitterApiReadWrite; private twitterClient?: TwitterApiReadWrite;
public constructor( public constructor(
private readonly benchmarkService: BenchmarkService, private readonly benchmarkService: BenchmarkService,
@ -27,18 +27,40 @@ export class TwitterBotService implements OnModuleInit {
) {} ) {}
public onModuleInit() { public onModuleInit() {
this.twitterClient = new TwitterApi({ const accessSecret = this.configurationService.get(
accessSecret: this.configurationService.get( 'TWITTER_ACCESS_TOKEN_SECRET'
'TWITTER_ACCESS_TOKEN_SECRET' );
), const accessToken = this.configurationService.get('TWITTER_ACCESS_TOKEN');
accessToken: this.configurationService.get('TWITTER_ACCESS_TOKEN'), const appKey = this.configurationService.get('TWITTER_API_KEY');
appKey: this.configurationService.get('TWITTER_API_KEY'), const appSecret = this.configurationService.get('TWITTER_API_SECRET');
appSecret: this.configurationService.get('TWITTER_API_SECRET')
}).readWrite; const areCredentialsSet = !!(
accessSecret &&
accessToken &&
appKey &&
appSecret
);
if (areCredentialsSet) {
this.twitterClient = new TwitterApi({
accessSecret,
accessToken,
appKey,
appSecret
}).readWrite;
} else if (
this.configurationService.get('ENABLE_FEATURE_FEAR_AND_GREED_INDEX') &&
this.configurationService.get('ENABLE_FEATURE_SUBSCRIPTION')
) {
this.logger.warn(
'ENABLE_FEATURE_FEAR_AND_GREED_INDEX and ENABLE_FEATURE_SUBSCRIPTION are enabled, but not all TWITTER_* credentials are set. The twitter bot service does not post the Fear & Greed Index.'
);
}
} }
public async tweetFearAndGreedIndex() { public async tweetFearAndGreedIndex() {
if ( if (
!this.twitterClient ||
!this.configurationService.get('ENABLE_FEATURE_FEAR_AND_GREED_INDEX') || !this.configurationService.get('ENABLE_FEATURE_FEAR_AND_GREED_INDEX') ||
isWeekend(new Date()) isWeekend(new Date())
) { ) {

Loading…
Cancel
Save