Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .deploy/lambda/bin/JProfByBotStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ if (process.env.TOKEN_YOUTUBE_API == null) {
throw new Error('Undefined TOKEN_YOUTUBE_API')
}

if (process.env.EMAIL_DAILY_URBAN_DICTIONARY == null) {
throw new Error('Undefined EMAIL_DAILY_URBAN_DICTIONARY')
}

const app = new cdk.App();
new JProfByBotStack(
app,
'JProfByBotStack',
{
telegramToken: process.env.TOKEN_TELEGRAM_BOT,
youtubeToken: process.env.TOKEN_YOUTUBE_API,
dailyUrbanDictionaryEmail: process.env.EMAIL_DAILY_URBAN_DICTIONARY,
env: {
region: 'us-east-1'
}
Expand Down
69 changes: 65 additions & 4 deletions .deploy/lambda/lib/JProfByBotStack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
import * as lambda from 'aws-cdk-lib/aws-lambda';
import * as sfn from 'aws-cdk-lib/aws-stepfunctions';
import * as tasks from 'aws-cdk-lib/aws-stepfunctions-tasks';
import * as ses from 'aws-cdk-lib/aws-ses';
import * as sesActions from 'aws-cdk-lib/aws-ses-actions';
import {JProfByBotStackProps} from "./JProfByBotStackProps";

export class JProfByBotStack extends cdk.Stack {
Expand Down Expand Up @@ -63,6 +65,18 @@ export class JProfByBotStack extends cdk.Stack {
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
removalPolicy: cdk.RemovalPolicy.DESTROY,
});
const languageRoomsTable = new dynamodb.Table(this, 'jprof-by-bot-table-language-rooms', {
tableName: 'jprof-by-bot-table-language-rooms',
partitionKey: {name: 'id', type: dynamodb.AttributeType.STRING},
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
removalPolicy: cdk.RemovalPolicy.DESTROY,
});
const urbanWordsOfTheDayTable = new dynamodb.Table(this, 'jprof-by-bot-table-urban-words-of-the-day', {
tableName: 'jprof-by-bot-table-urban-words-of-the-day',
partitionKey: {name: 'date', type: dynamodb.AttributeType.STRING},
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
removalPolicy: cdk.RemovalPolicy.DESTROY,
});

pinsTable.addGlobalSecondaryIndex({
indexName: 'chatId',
Expand Down Expand Up @@ -117,15 +131,18 @@ export class JProfByBotStack extends cdk.Stack {
compatibleRuntimes: [lambda.Runtime.JAVA_11],
});

const lambdaWebhookTimeout = cdk.Duration.seconds(29);
const lambdaWebhook = new lambda.Function(this, 'jprof-by-bot-lambda-webhook', {
functionName: 'jprof-by-bot-lambda-webhook',
runtime: lambda.Runtime.JAVA_11,
layers: [
layerLibGL,
layerLibfontconfig,
],
timeout: cdk.Duration.seconds(30),
memorySize: 1024,
timeout: lambdaWebhookTimeout,
maxEventAge: cdk.Duration.minutes(5),
retryAttempts: 0,
memorySize: 512,
code: lambda.Code.fromAsset('../../launchers/lambda/build/libs/jprof_by_bot-launchers-lambda-all.jar'),
handler: 'by.jprof.telegram.bot.launchers.lambda.JProf',
environment: {
Expand All @@ -138,12 +155,49 @@ export class JProfByBotStack extends cdk.Stack {
'TABLE_MONIES': moniesTable.tableName,
'TABLE_PINS': pinsTable.tableName,
'TABLE_TIMEZONES': timezonesTable.tableName,
'TABLE_LANGUAGE_ROOMS': languageRoomsTable.tableName,
'TABLE_URBAN_WORDS_OF_THE_DAY': urbanWordsOfTheDayTable.tableName,
'STATE_MACHINE_UNPINS': stateMachineUnpin.stateMachineArn,
'TOKEN_TELEGRAM_BOT': props.telegramToken,
'TOKEN_YOUTUBE_API': props.youtubeToken,
'TIMEOUT': lambdaWebhookTimeout.toMilliseconds().toString(),
},
});

(lambdaWebhook.node.defaultChild as lambda.CfnFunction).snapStart = {
applyOn: 'PublishedVersions'
};

const lambdaDailyUrbanDictionary = new lambda.Function(this, 'jprof-by-bot-lambda-daily-urban-dictionary', {
functionName: 'jprof-by-bot-lambda-daily-urban-dictionary',
runtime: lambda.Runtime.JAVA_11,
timeout: cdk.Duration.seconds(30),
retryAttempts: 0,
memorySize: 512,
code: lambda.Code.fromAsset('../../english/urban-dictionary-daily/build/libs/jprof_by_bot-english-urban-dictionary-daily-all.jar'),
handler: 'by.jprof.telegram.bot.english.urban_dictionary_daily.Handler',
environment: {
'LOG_THRESHOLD': 'DEBUG',
'TABLE_URBAN_WORDS_OF_THE_DAY': urbanWordsOfTheDayTable.tableName,
'TABLE_LANGUAGE_ROOMS': languageRoomsTable.tableName,
'TOKEN_TELEGRAM_BOT': props.telegramToken,
'STATE_MACHINE_UNPINS': stateMachineUnpin.stateMachineArn,
}
});

new ses.ReceiptRuleSet(this, 'jprof-by-bot-receipt-rule-set-daily-urbandictionary', {
receiptRuleSetName: 'jprof-by-bot-receipt-rule-set-daily-urbandictionary',
rules: [
{
receiptRuleName: 'jprof-by-bot-receipt-rule-daily-urbandictionary',
recipients: [props.dailyUrbanDictionaryEmail],
actions: [
new sesActions.Lambda({function: lambdaDailyUrbanDictionary})
]
}
],
});

votesTable.grantReadWriteData(lambdaWebhook);

youtubeChannelsWhitelistTable.grantReadData(lambdaWebhook);
Expand All @@ -161,7 +215,14 @@ export class JProfByBotStack extends cdk.Stack {

timezonesTable.grantReadWriteData(lambdaWebhook);

stateMachineUnpin.grantStartExecution(lambdaWebhook)
languageRoomsTable.grantReadWriteData(lambdaWebhook);
languageRoomsTable.grantReadData(lambdaDailyUrbanDictionary);

urbanWordsOfTheDayTable.grantWriteData(lambdaDailyUrbanDictionary);
urbanWordsOfTheDayTable.grantReadData(lambdaWebhook);

stateMachineUnpin.grantStartExecution(lambdaWebhook);
stateMachineUnpin.grantStartExecution(lambdaDailyUrbanDictionary);

const api = new apigateway.RestApi(this, 'jprof-by-bot-api', {
restApiName: 'jprof-by-bot-api',
Expand All @@ -177,7 +238,7 @@ export class JProfByBotStack extends cdk.Stack {

api.root
.addResource(props.telegramToken.replace(':', '_'))
.addMethod('POST', new apigateway.LambdaIntegration(lambdaWebhook));
.addMethod('POST', new apigateway.LambdaIntegration(lambdaWebhook.currentVersion));

new cdk.CfnOutput(this, 'URL', {
value: api.deploymentStage.urlForPath()
Expand Down
1 change: 1 addition & 0 deletions .deploy/lambda/lib/JProfByBotStackProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import * as cdk from 'aws-cdk-lib';
export interface JProfByBotStackProps extends cdk.StackProps {
readonly telegramToken: string;
readonly youtubeToken: string;
readonly dailyUrbanDictionaryEmail: string;
}
64 changes: 50 additions & 14 deletions .deploy/lambda/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .deploy/lambda/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
"@types/prettier": "2.6.0",
"jest": "^27.5.1",
"ts-jest": "^27.1.4",
"aws-cdk": "2.49.0",
"aws-cdk": "2.53.0",
"ts-node": "^10.9.1",
"typescript": "~3.9.7",
"jest-junit": "^14.0.1"
},
"dependencies": {
"aws-cdk-lib": "2.49.0",
"aws-cdk-lib": "2.53.0",
"constructs": "^10.0.0",
"source-map-support": "^0.5.21"
}
Expand Down
1 change: 1 addition & 0 deletions .deploy/lambda/test/JProfByBotStack.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ describe('JProfByBotStack', () => {
const stack = new JProfByBotStack(app, 'JProfByBotStack', {
telegramToken: 'TOKEN_TELEGRAM_BOT',
youtubeToken: 'TOKEN_YOUTUBE_API',
dailyUrbanDictionaryEmail: 'EMAIL_DAILY_URBAN_DICTIONARY',
env: {region: 'us-east-1'}
});
const template = Template.fromStack(stack);
Expand Down
26 changes: 26 additions & 0 deletions .github/workflows/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ jobs:
- run: monies/dynamodb/src/test/resources/seed.sh
- run: pins/dynamodb/src/test/resources/seed.sh
- run: times/timezones/dynamodb/src/test/resources/seed.sh
- run: english/language-rooms/dynamodb/src/test/resources/seed.sh
- run: english/urban-word-of-the-day/dynamodb/src/test/resources/seed.sh
- uses: gradle/gradle-build-action@v2
with:
arguments: clean dbTest
Expand All @@ -69,6 +71,27 @@ jobs:
**/build/test-results
**/build/reports

integration-test:
name: Integration test
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: 11
distribution: adopt
- uses: gradle/gradle-build-action@v2
with:
arguments: clean integrationTest
cache-read-only: ${{ github.ref != 'refs/heads/master' }}
- uses: actions/upload-artifact@v3
if: always()
with:
name: test-results
path: |
**/build/test-results
**/build/reports

cdk-test:
name: CDK test
runs-on: ubuntu-20.04
Expand Down Expand Up @@ -105,6 +128,7 @@ jobs:
needs:
- test
- db-test
- integration-test
- cdk-test
if: always()
steps:
Expand All @@ -116,10 +140,12 @@ jobs:
report_paths: |-
**/test-results/test/TEST-*.xml
**/test-results/dbTest/TEST-*.xml
**/test-results/integrationTest/TEST-*.xml
**/junit.xml
check_name: |-
Test reports
DB test reports
Integration test reports
CDK test reports
include_passed: true
github_token: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ build
.idea

*.private.env.json

.env
Binary file added .idea/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .idea/icon_dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion LICENSE.adoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright ⓒ 2021 mailto:jug@jprof.by[Java Professionals BY community].
Copyright ⓒ 2023 mailto:jug@jprof.by[Java Professionals BY community].

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
3 changes: 2 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Official Telegram bot of Java Professionals BY community.
* Allows users to create polls with reply buttons (just like https://t.me/like[`@like`] bot)
* Converts some currencies to EUR and USD
* Posts scheduled messages from this repo's `posts` branch
* Expand LeetCode links
* Expands LeetCode links
* Regulates our English Rooms & teaches us new English words

So, it just brings some fun and interactivity in our chat.

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ subprojects {
}
withType<Test> {
useJUnitPlatform {
excludeTags("db")
excludeTags("db", "it")
}
testLogging {
showStandardStreams = true
Expand Down
Loading