Skip to content

Commit aa8d6f7

Browse files
authored
Merge pull request #49 from /issues/48
English Rooms
2 parents ea7b18d + efb975c commit aa8d6f7

File tree

101 files changed

+2196
-105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+2196
-105
lines changed

.deploy/lambda/bin/JProfByBotStack.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,18 @@ if (process.env.TOKEN_YOUTUBE_API == null) {
1111
throw new Error('Undefined TOKEN_YOUTUBE_API')
1212
}
1313

14+
if (process.env.EMAIL_DAILY_URBAN_DICTIONARY == null) {
15+
throw new Error('Undefined EMAIL_DAILY_URBAN_DICTIONARY')
16+
}
17+
1418
const app = new cdk.App();
1519
new JProfByBotStack(
1620
app,
1721
'JProfByBotStack',
1822
{
1923
telegramToken: process.env.TOKEN_TELEGRAM_BOT,
2024
youtubeToken: process.env.TOKEN_YOUTUBE_API,
25+
dailyUrbanDictionaryEmail: process.env.EMAIL_DAILY_URBAN_DICTIONARY,
2126
env: {
2227
region: 'us-east-1'
2328
}

.deploy/lambda/lib/JProfByBotStack.ts

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import * as dynamodb from 'aws-cdk-lib/aws-dynamodb';
55
import * as lambda from 'aws-cdk-lib/aws-lambda';
66
import * as sfn from 'aws-cdk-lib/aws-stepfunctions';
77
import * as tasks from 'aws-cdk-lib/aws-stepfunctions-tasks';
8+
import * as ses from 'aws-cdk-lib/aws-ses';
9+
import * as sesActions from 'aws-cdk-lib/aws-ses-actions';
810
import {JProfByBotStackProps} from "./JProfByBotStackProps";
911

1012
export class JProfByBotStack extends cdk.Stack {
@@ -63,6 +65,18 @@ export class JProfByBotStack extends cdk.Stack {
6365
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
6466
removalPolicy: cdk.RemovalPolicy.DESTROY,
6567
});
68+
const languageRoomsTable = new dynamodb.Table(this, 'jprof-by-bot-table-language-rooms', {
69+
tableName: 'jprof-by-bot-table-language-rooms',
70+
partitionKey: {name: 'id', type: dynamodb.AttributeType.STRING},
71+
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
72+
removalPolicy: cdk.RemovalPolicy.DESTROY,
73+
});
74+
const urbanWordsOfTheDayTable = new dynamodb.Table(this, 'jprof-by-bot-table-urban-words-of-the-day', {
75+
tableName: 'jprof-by-bot-table-urban-words-of-the-day',
76+
partitionKey: {name: 'date', type: dynamodb.AttributeType.STRING},
77+
billingMode: dynamodb.BillingMode.PAY_PER_REQUEST,
78+
removalPolicy: cdk.RemovalPolicy.DESTROY,
79+
});
6680

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

134+
const lambdaWebhookTimeout = cdk.Duration.seconds(29);
120135
const lambdaWebhook = new lambda.Function(this, 'jprof-by-bot-lambda-webhook', {
121136
functionName: 'jprof-by-bot-lambda-webhook',
122137
runtime: lambda.Runtime.JAVA_11,
123138
layers: [
124139
layerLibGL,
125140
layerLibfontconfig,
126141
],
127-
timeout: cdk.Duration.seconds(30),
128-
memorySize: 1024,
142+
timeout: lambdaWebhookTimeout,
143+
maxEventAge: cdk.Duration.minutes(5),
144+
retryAttempts: 0,
145+
memorySize: 512,
129146
code: lambda.Code.fromAsset('../../launchers/lambda/build/libs/jprof_by_bot-launchers-lambda-all.jar'),
130147
handler: 'by.jprof.telegram.bot.launchers.lambda.JProf',
131148
environment: {
@@ -138,12 +155,49 @@ export class JProfByBotStack extends cdk.Stack {
138155
'TABLE_MONIES': moniesTable.tableName,
139156
'TABLE_PINS': pinsTable.tableName,
140157
'TABLE_TIMEZONES': timezonesTable.tableName,
158+
'TABLE_LANGUAGE_ROOMS': languageRoomsTable.tableName,
159+
'TABLE_URBAN_WORDS_OF_THE_DAY': urbanWordsOfTheDayTable.tableName,
141160
'STATE_MACHINE_UNPINS': stateMachineUnpin.stateMachineArn,
142161
'TOKEN_TELEGRAM_BOT': props.telegramToken,
143162
'TOKEN_YOUTUBE_API': props.youtubeToken,
163+
'TIMEOUT': lambdaWebhookTimeout.toMilliseconds().toString(),
144164
},
145165
});
146166

167+
(lambdaWebhook.node.defaultChild as lambda.CfnFunction).snapStart = {
168+
applyOn: 'PublishedVersions'
169+
};
170+
171+
const lambdaDailyUrbanDictionary = new lambda.Function(this, 'jprof-by-bot-lambda-daily-urban-dictionary', {
172+
functionName: 'jprof-by-bot-lambda-daily-urban-dictionary',
173+
runtime: lambda.Runtime.JAVA_11,
174+
timeout: cdk.Duration.seconds(30),
175+
retryAttempts: 0,
176+
memorySize: 512,
177+
code: lambda.Code.fromAsset('../../english/urban-dictionary-daily/build/libs/jprof_by_bot-english-urban-dictionary-daily-all.jar'),
178+
handler: 'by.jprof.telegram.bot.english.urban_dictionary_daily.Handler',
179+
environment: {
180+
'LOG_THRESHOLD': 'DEBUG',
181+
'TABLE_URBAN_WORDS_OF_THE_DAY': urbanWordsOfTheDayTable.tableName,
182+
'TABLE_LANGUAGE_ROOMS': languageRoomsTable.tableName,
183+
'TOKEN_TELEGRAM_BOT': props.telegramToken,
184+
'STATE_MACHINE_UNPINS': stateMachineUnpin.stateMachineArn,
185+
}
186+
});
187+
188+
new ses.ReceiptRuleSet(this, 'jprof-by-bot-receipt-rule-set-daily-urbandictionary', {
189+
receiptRuleSetName: 'jprof-by-bot-receipt-rule-set-daily-urbandictionary',
190+
rules: [
191+
{
192+
receiptRuleName: 'jprof-by-bot-receipt-rule-daily-urbandictionary',
193+
recipients: [props.dailyUrbanDictionaryEmail],
194+
actions: [
195+
new sesActions.Lambda({function: lambdaDailyUrbanDictionary})
196+
]
197+
}
198+
],
199+
});
200+
147201
votesTable.grantReadWriteData(lambdaWebhook);
148202

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

162216
timezonesTable.grantReadWriteData(lambdaWebhook);
163217

164-
stateMachineUnpin.grantStartExecution(lambdaWebhook)
218+
languageRoomsTable.grantReadWriteData(lambdaWebhook);
219+
languageRoomsTable.grantReadData(lambdaDailyUrbanDictionary);
220+
221+
urbanWordsOfTheDayTable.grantWriteData(lambdaDailyUrbanDictionary);
222+
urbanWordsOfTheDayTable.grantReadData(lambdaWebhook);
223+
224+
stateMachineUnpin.grantStartExecution(lambdaWebhook);
225+
stateMachineUnpin.grantStartExecution(lambdaDailyUrbanDictionary);
165226

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

178239
api.root
179240
.addResource(props.telegramToken.replace(':', '_'))
180-
.addMethod('POST', new apigateway.LambdaIntegration(lambdaWebhook));
241+
.addMethod('POST', new apigateway.LambdaIntegration(lambdaWebhook.currentVersion));
181242

182243
new cdk.CfnOutput(this, 'URL', {
183244
value: api.deploymentStage.urlForPath()

.deploy/lambda/lib/JProfByBotStackProps.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ import * as cdk from 'aws-cdk-lib';
33
export interface JProfByBotStackProps extends cdk.StackProps {
44
readonly telegramToken: string;
55
readonly youtubeToken: string;
6+
readonly dailyUrbanDictionaryEmail: string;
67
}

.deploy/lambda/package-lock.json

Lines changed: 50 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.deploy/lambda/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
"@types/prettier": "2.6.0",
1717
"jest": "^27.5.1",
1818
"ts-jest": "^27.1.4",
19-
"aws-cdk": "2.49.0",
19+
"aws-cdk": "2.53.0",
2020
"ts-node": "^10.9.1",
2121
"typescript": "~3.9.7",
2222
"jest-junit": "^14.0.1"
2323
},
2424
"dependencies": {
25-
"aws-cdk-lib": "2.49.0",
25+
"aws-cdk-lib": "2.53.0",
2626
"constructs": "^10.0.0",
2727
"source-map-support": "^0.5.21"
2828
}

.deploy/lambda/test/JProfByBotStack.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ describe('JProfByBotStack', () => {
77
const stack = new JProfByBotStack(app, 'JProfByBotStack', {
88
telegramToken: 'TOKEN_TELEGRAM_BOT',
99
youtubeToken: 'TOKEN_YOUTUBE_API',
10+
dailyUrbanDictionaryEmail: 'EMAIL_DAILY_URBAN_DICTIONARY',
1011
env: {region: 'us-east-1'}
1112
});
1213
const template = Template.fromStack(stack);

.github/workflows/default.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ jobs:
5757
- run: monies/dynamodb/src/test/resources/seed.sh
5858
- run: pins/dynamodb/src/test/resources/seed.sh
5959
- run: times/timezones/dynamodb/src/test/resources/seed.sh
60+
- run: english/language-rooms/dynamodb/src/test/resources/seed.sh
61+
- run: english/urban-word-of-the-day/dynamodb/src/test/resources/seed.sh
6062
- uses: gradle/gradle-build-action@v2
6163
with:
6264
arguments: clean dbTest
@@ -69,6 +71,27 @@ jobs:
6971
**/build/test-results
7072
**/build/reports
7173
74+
integration-test:
75+
name: Integration test
76+
runs-on: ubuntu-20.04
77+
steps:
78+
- uses: actions/checkout@v3
79+
- uses: actions/setup-java@v3
80+
with:
81+
java-version: 11
82+
distribution: adopt
83+
- uses: gradle/gradle-build-action@v2
84+
with:
85+
arguments: clean integrationTest
86+
cache-read-only: ${{ github.ref != 'refs/heads/master' }}
87+
- uses: actions/upload-artifact@v3
88+
if: always()
89+
with:
90+
name: test-results
91+
path: |
92+
**/build/test-results
93+
**/build/reports
94+
7295
cdk-test:
7396
name: CDK test
7497
runs-on: ubuntu-20.04
@@ -105,6 +128,7 @@ jobs:
105128
needs:
106129
- test
107130
- db-test
131+
- integration-test
108132
- cdk-test
109133
if: always()
110134
steps:
@@ -116,10 +140,12 @@ jobs:
116140
report_paths: |-
117141
**/test-results/test/TEST-*.xml
118142
**/test-results/dbTest/TEST-*.xml
143+
**/test-results/integrationTest/TEST-*.xml
119144
**/junit.xml
120145
check_name: |-
121146
Test reports
122147
DB test reports
148+
Integration test reports
123149
CDK test reports
124150
include_passed: true
125151
github_token: ${{ secrets.GITHUB_TOKEN }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ build
44
.idea
55

66
*.private.env.json
7+
8+
.env

.idea/icon.png

5.66 KB
Loading

.idea/icon_dark.png

6.22 KB
Loading

0 commit comments

Comments
 (0)