Skip to content

Commit 80d1125

Browse files
committed
Voting for YouTube videos
1 parent c9880a8 commit 80d1125

File tree

26 files changed

+517
-10
lines changed

26 files changed

+517
-10
lines changed

.deploy/lambda/bin/JProfByBotStack.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@ import 'source-map-support/register';
33
import * as cdk from '@aws-cdk/core';
44
import { JProfByBotStack } from '../lib/JProfByBotStack';
55

6-
if (process.env.TELEGRAM_BOT_TOKEN == null) {
7-
throw new Error('Undefined TELEGRAM_BOT_TOKEN')
6+
if (process.env.TOKEN_TELEGRAM_BOT == null) {
7+
throw new Error('Undefined TOKEN_TELEGRAM_BOT')
8+
}
9+
10+
if (process.env.TOKEN_YOUTUBE_API == null) {
11+
throw new Error('Undefined TOKEN_YOUTUBE_API')
812
}
913

1014
const app = new cdk.App();
1115
new JProfByBotStack(
1216
app,
1317
'JProfByBotStack',
1418
{
15-
telegramToken: process.env.TELEGRAM_BOT_TOKEN,
19+
telegramToken: process.env.TOKEN_TELEGRAM_BOT,
20+
youtubeToken: process.env.TOKEN_YOUTUBE_API,
1621
env: {
1722
region: 'us-east-1'
1823
}

.deploy/lambda/lib/JProfByBotStack.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ export class JProfByBotStack extends cdk.Stack {
1515
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
1616
removalPolicy: RemovalPolicy.DESTROY,
1717
});
18+
const youtubeChannelsWhitelistTable = new dynamodb.Table(this, 'jprof-by-bot-table-youtube-channels-whitelist', {
19+
tableName: 'jprof-by-bot-table-youtube-channels-whitelist',
20+
partitionKey: { name: 'id', type: dynamodb.AttributeType.STRING },
21+
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
22+
});
1823

1924
const lambdaWebhook = new lambda.Function(this, 'jprof-by-bot-lambda-webhook', {
2025
functionName: 'jprof-by-bot-lambda-webhook',
@@ -26,11 +31,14 @@ export class JProfByBotStack extends cdk.Stack {
2631
environment: {
2732
'LOG_THRESHOLD': 'DEBUG',
2833
'TABLE_VOTES': votesTable.tableName,
29-
'TELEGRAM_BOT_TOKEN': props.telegramToken,
34+
'TABLE_YOUTUBE_CHANNELS_WHITELIST': youtubeChannelsWhitelistTable.tableName,
35+
'TOKEN_TELEGRAM_BOT': props.telegramToken,
36+
'TOKEN_YOUTUBE_API': props.youtubeToken,
3037
},
3138
});
3239

3340
votesTable.grantReadWriteData(lambdaWebhook);
41+
youtubeChannelsWhitelistTable.grantReadData(lambdaWebhook);
3442

3543
const api = new apigateway.RestApi(this, 'jprof-by-bot-api', {
3644
restApiName: 'jprof-by-bot-api',

.deploy/lambda/lib/JProfByBotStackProps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ import * as cdk from '@aws-cdk/core';
22

33
export interface JProfByBotStackProps extends cdk.StackProps {
44
readonly telegramToken: string;
5+
readonly youtubeToken: string;
56
}

.github/workflows/default.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ jobs:
5555
job-id: db-test
5656
read-only: ${{ github.ref != 'refs/heads/master' }}
5757
- run: votes/dynamodb/src/test/resources/seed.sh
58+
- run: youtube/dynamodb/src/test/resources/seed.sh
5859
- run: ./gradlew clean dbTest
5960
- uses: actions/upload-artifact@v2
6061
if: always()

.github/workflows/deploy.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ jobs:
3939
- run: npx cdk deploy --outputs-file=cdk.out/outputs.json --require-approval=never
4040
working-directory: .deploy/lambda
4141
env:
42-
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
42+
TOKEN_TELEGRAM_BOT: ${{ secrets.TOKEN_TELEGRAM_BOT }}
43+
TOKEN_YOUTUBE_API: ${{ secrets.TOKEN_YOUTUBE_API }}
4344
- id: URL
4445
run: echo "::set-output name=URL::$(jq -r '.JProfByBotStack.URL' cdk.out/outputs.json)"
4546
working-directory: .deploy/lambda

gradle/libs.versions.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ tgbotapi = "0.33.3"
1414

1515
jsoup = "1.13.1"
1616

17+
google-api-services-youtube = "v3-rev20210410-1.31.0"
18+
1719
log4j = "2.14.1"
1820

1921
junit5 = "5.7.1"
@@ -34,9 +36,12 @@ jackson-databind = { group = "com.fasterxml.jackson.core", name = "jackson-datab
3436

3537
tgbotapi-core = { group = "dev.inmo", name = "tgbotapi.core", version.ref = "tgbotapi" }
3638
tgbotapi-extensions-api = { group = "dev.inmo", name = "tgbotapi.extensions.api", version.ref = "tgbotapi" }
39+
tgbotapi-extensions-utils = { group = "dev.inmo", name = "tgbotapi.extensions.utils", version.ref = "tgbotapi" }
3740

3841
jsoup = { group = "org.jsoup", name = "jsoup", version.ref = "jsoup" }
3942

43+
google-api-services-youtube = { group = "com.google.apis", name = "google-api-services-youtube", version.ref = "google-api-services-youtube" }
44+
4045
log4j-api = { group = "org.apache.logging.log4j", name = "log4j-api", version.ref = "log4j" }
4146
log4j-core = { group = "org.apache.logging.log4j", name = "log4j-core", version.ref = "log4j" }
4247
log4j-slf4j-impl = { group = "org.apache.logging.log4j", name = "log4j-slf4j-impl", version.ref = "log4j" }

runners/lambda/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@ dependencies {
1111
implementation(project.projects.core)
1212
implementation(project.projects.votes.dynamodb)
1313
implementation(project.projects.jep)
14+
implementation(project.projects.youtube.dynamodb)
1415
}

runners/lambda/src/main/kotlin/by/jprof/telegram/bot/runners/lambda/JProf.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ class JProf : RequestHandler<APIGatewayV2HTTPEvent, APIGatewayV2HTTPResponse>, K
3636
databaseModule,
3737
jsonModule,
3838
telegramModule,
39-
pipelineModule
39+
youtubeModule,
40+
pipelineModule,
4041
)
4142
}
4243
}

runners/lambda/src/main/kotlin/by/jprof/telegram/bot/runners/lambda/config/database.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package by.jprof.telegram.bot.runners.lambda.config
22

33
import by.jprof.telegram.bot.votes.dao.VotesDAO
4+
import by.jprof.telegram.bot.youtube.dao.YouTubeChannelsWhitelistDAO
45
import org.koin.core.qualifier.named
56
import org.koin.dsl.module
67
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient
78
import by.jprof.telegram.bot.votes.dynamodb.dao.VotesDAO as DynamoDBVotesDAO
9+
import by.jprof.telegram.bot.youtube.dynamodb.dao.YouTubeChannelsWhitelistDAO as DynamoDBYouTubeChannelsWhitelistDAO
810

911
val databaseModule = module {
1012
single {
@@ -17,4 +19,11 @@ val databaseModule = module {
1719
get(named(TABLE_VOTES))
1820
)
1921
}
22+
23+
single<YouTubeChannelsWhitelistDAO> {
24+
DynamoDBYouTubeChannelsWhitelistDAO(
25+
get(),
26+
get(named(TABLE_YOUTUBE_CHANNELS_WHITELIST))
27+
)
28+
}
2029
}

runners/lambda/src/main/kotlin/by/jprof/telegram/bot/runners/lambda/config/env.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ package by.jprof.telegram.bot.runners.lambda.config
33
import org.koin.core.qualifier.named
44
import org.koin.dsl.module
55

6-
const val TELEGRAM_BOT_TOKEN = "TELEGRAM_BOT_TOKEN"
6+
const val TOKEN_TELEGRAM_BOT = "TOKEN_TELEGRAM_BOT"
7+
const val TOKEN_YOUTUBE_API = "TOKEN_YOUTUBE_API"
78
const val TABLE_VOTES = "TABLE_VOTES"
9+
const val TABLE_YOUTUBE_CHANNELS_WHITELIST = "TABLE_YOUTUBE_CHANNELS_WHITELIST"
810

911
val envModule = module {
1012
listOf(
11-
TELEGRAM_BOT_TOKEN,
13+
TOKEN_TELEGRAM_BOT,
14+
TOKEN_YOUTUBE_API,
1215
TABLE_VOTES,
16+
TABLE_YOUTUBE_CHANNELS_WHITELIST,
1317
).forEach { variable ->
1418
single(named(variable)) {
1519
System.getenv(variable)!!

0 commit comments

Comments
 (0)