Browse Source

Skip twitter bot service without credentials

pull/8434/head
Thomas Kaul 2 weeks ago
parent
commit
7fd84e75e8
  1. 8
      apps/api/src/services/configuration/configuration.service.ts
  2. 40
      apps/api/src/services/twitter-bot/twitter-bot.service.ts

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

@ -148,10 +148,10 @@ export class ConfigurationService {
}),
STRIPE_SECRET_KEY: str({ default: '' }),
TRUST_PROXY: trustProxy({ default: '' }),
TWITTER_ACCESS_TOKEN: str({ default: 'dummyAccessToken' }),
TWITTER_ACCESS_TOKEN_SECRET: str({ default: 'dummyAccessTokenSecret' }),
TWITTER_API_KEY: str({ default: 'dummyApiKey' }),
TWITTER_API_SECRET: str({ default: 'dummyApiSecret' })
TWITTER_ACCESS_TOKEN: str({ default: '' }),
TWITTER_ACCESS_TOKEN_SECRET: str({ default: '' }),
TWITTER_API_KEY: str({ default: '' }),
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 {
private readonly logger = new Logger(TwitterBotService.name);
private twitterClient: TwitterApiReadWrite;
private twitterClient?: TwitterApiReadWrite;
public constructor(
private readonly benchmarkService: BenchmarkService,
@ -27,18 +27,40 @@ export class TwitterBotService implements OnModuleInit {
) {}
public onModuleInit() {
this.twitterClient = new TwitterApi({
accessSecret: this.configurationService.get(
'TWITTER_ACCESS_TOKEN_SECRET'
),
accessToken: this.configurationService.get('TWITTER_ACCESS_TOKEN'),
appKey: this.configurationService.get('TWITTER_API_KEY'),
appSecret: this.configurationService.get('TWITTER_API_SECRET')
}).readWrite;
const accessSecret = this.configurationService.get(
'TWITTER_ACCESS_TOKEN_SECRET'
);
const accessToken = this.configurationService.get('TWITTER_ACCESS_TOKEN');
const appKey = this.configurationService.get('TWITTER_API_KEY');
const appSecret = this.configurationService.get('TWITTER_API_SECRET');
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() {
if (
!this.twitterClient ||
!this.configurationService.get('ENABLE_FEATURE_FEAR_AND_GREED_INDEX') ||
isWeekend(new Date())
) {

Loading…
Cancel
Save