Skip to content

Commit

Permalink
feat(back): Twitter first reaction: post a tweet
Browse files Browse the repository at this point in the history
  • Loading branch information
EdenComp authored and RezaRahemtola committed Nov 4, 2023
1 parent 0cca709 commit bbdf6c9
Show file tree
Hide file tree
Showing 23 changed files with 2,869 additions and 47 deletions.
46 changes: 0 additions & 46 deletions backend/back/1699107944021-CreateAirtableDeleteRecordReaction.ts

This file was deleted.

4 changes: 3 additions & 1 deletion backend/back/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ import { AddActivityLogEntity1698986590525 } from "./migrations/1698986590525-Ad
import { CreateRiotGamesService1698964479750 } from "./services/seed/1698964479750-CreateRiotGamesService";
import { CreateRiotGamesActions1698964479850 } from "./workflows/seed/1698964479850-CreateRiotGamesActions";
import { CreateTodoistCreateTaskReaction1699101589099 } from "./workflows/seed/1699101589099-CreateTodoistCreateTaskReaction";
import { CreateAirtableDeleteRecordReaction1699107944021 } from "../1699107944021-CreateAirtableDeleteRecordReaction";
import { CreateAirtableDeleteRecordReaction1699107944021 } from "./workflows/seed/1699107944021-CreateAirtableDeleteRecordReaction";
import { CreateTwitterCreateTweetReaction1699115775099 } from "./workflows/seed/1699115775099-CreateTwitterCreateTweetReaction";

dotenv.config();

Expand Down Expand Up @@ -157,6 +158,7 @@ export const DATA_SOURCE_OPTIONS: DataSourceOptions = {
CreateRiotGamesActions1698964479850,
CreateTodoistCreateTaskReaction1699101589099,
CreateAirtableDeleteRecordReaction1699107944021,
CreateTwitterCreateTweetReaction1699115775099,
],
synchronize: process.env.NODE_ENV === "development",
};
Expand Down
1 change: 1 addition & 0 deletions backend/back/src/types/jobIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,5 @@ export const JobsIdentifiers: JobsIdentifiers = {
"riot-lol-on-level-up": ({ region, summoner }) => `riot-lol-on-level-up-${region}-${summoner}`,
"timer-seconds-interval": ({ workflowStepId }) => uniqueJobId("timer-seconds-interval", workflowStepId),
"todoist-create-task": ({ workflowStepId }) => uniqueJobId("todoist-create-task", workflowStepId),
"twitter-create-tweet": ({ workflowStepId }) => uniqueJobId("twitter-create-tweet", workflowStepId),
};
5 changes: 5 additions & 0 deletions backend/back/src/types/jobParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,3 +289,8 @@ export class AirtableDeleteRecordParams extends UniqueJobParams {
@IsString()
recordId: string;
}

export class TwitterCreateTweetParams extends UniqueJobParams {
@IsString()
text: string;
}
4 changes: 4 additions & 0 deletions backend/back/src/types/jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
TimerSecondIntervalParams,
TitleParams,
TodoistCreateTaskParams,
TwitterCreateTweetParams,
YoutubeChannelParams,
} from "./jobParams";

Expand Down Expand Up @@ -80,6 +81,7 @@ export enum Jobs {
"riot-lol-on-level-up" = "riot-lol-on-level-up",
"timer-seconds-interval" = "timer-seconds-interval",
"todoist-create-task" = "todoist-create-task",
"twitter-create-tweet" = "twitter-create-tweet",
}

export type JobsType = keyof typeof Jobs;
Expand Down Expand Up @@ -138,6 +140,7 @@ export const JobParamsClasses = {
"riot-lol-on-level-up": RiotActionsParams,
"timer-seconds-interval": TimerSecondIntervalParams,
"todoist-create-task": TodoistCreateTaskParams,
"twitter-create-tweet": TwitterCreateTweetParams,
};

export type JobsParams = Mapper<{
Expand Down Expand Up @@ -190,4 +193,5 @@ export type JobsParams = Mapper<{
"riot-lol-on-level-up": RiotActionsParams;
"timer-seconds-interval": TimerSecondIntervalParams;
"todoist-create-task": TodoistCreateTaskParams;
"twitter-create-tweet": TwitterCreateTweetParams;
}>;
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { MigrationInterface, QueryRunner } from "typeorm";
import { ParametersFormFlowFieldDto } from "../../services/dto/area.dto";

export class CreateAirtableDeleteRecordReaction1699107944021 implements MigrationInterface {
private readonly airtableDeleteRecordParametersFormFlow: ParametersFormFlowFieldDto[] = [
{
name: "baseId",
type: "short-text",
required: true,
},
{
name: "tableId",
type: "short-text",
required: true,
},
{
name: "recordId",
type: "short-text",
required: true,
},
];

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`INSERT INTO "area" ("id", "service_id", "is_action", "description", "parameters_form_flow", "parameters_return_flow")
VALUES ('delete-record', 'airtable', false, 'Delete a record from an Airtable base table', $1, '{}')`,
[JSON.stringify(this.airtableDeleteRecordParametersFormFlow)],
);

await queryRunner.query(
`INSERT INTO "area_service_scopes_needed_service_scope" ("area_id", "area_service_id", "service_scope_id", "service_scope_service_id")
VALUES ('delete-record', 'airtable', 'data.records:write', 'airtable')`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DELETE FROM "area"
WHERE service_id = 'airtable'
AND id IN ('delete-record');
`,
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { MigrationInterface, QueryRunner } from "typeorm";
import { ParametersFormFlowFieldDto } from "../../services/dto/area.dto";

export class CreateTwitterCreateTweetReaction1699115775099 implements MigrationInterface {
private readonly twitterCreateTweetParametersFormFlow: ParametersFormFlowFieldDto[] = [
{
name: "text",
type: "long-text",
required: true,
},
];

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`INSERT INTO "area" ("id", "service_id", "is_action", "description", "parameters_form_flow", "parameters_return_flow")
VALUES ('create-tweet', 'twitter', false, 'Post a tweet on Twitter (X)', $1, '{}')`,
[JSON.stringify(this.twitterCreateTweetParametersFormFlow)],
);

await queryRunner.query(
`INSERT INTO "area_service_scopes_needed_service_scope" ("area_id", "area_service_id", "service_scope_id", "service_scope_service_id")
VALUES ('create-tweet', 'twitter', 'tweet.read', 'twitter'),
('create-tweet', 'twitter', 'tweet.write', 'twitter'),
('create-tweet', 'twitter', 'users.read', 'twitter')`,
);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`DELETE FROM "area"
WHERE service_id = 'twitter'
AND id IN ('create-tweet');
`,
);
}
}
4 changes: 4 additions & 0 deletions backend/supervisor/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,7 @@ services:
todoist:
container_name: todoist
build: ../workers/todoist

twitter:
container_name: twitter
build: ../workers/twitter
2 changes: 2 additions & 0 deletions backend/supervisor/jobs/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var JobToImage = map[string]string{
"riot-lol-on-level-up": "supervisor-riot",
"timer-seconds-interval": "supervisor-seconds-interval",
"todoist-create-task": "supervisor-todoist",
"twitter-create-tweet": "supervisor-twitter",
}

var OptArgument = map[string]string{
Expand Down Expand Up @@ -99,6 +100,7 @@ var OptArgument = map[string]string{
"riot-lol-on-level-up": "lol-on-level-up",
"timer-seconds-interval": "",
"todoist-create-task": "create-task",
"twitter-create-tweet": "create-tweet",
}

func GetImages() []string {
Expand Down
4 changes: 4 additions & 0 deletions backend/workers/twitter/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dist/
node_modules/
proto/
.env
21 changes: 21 additions & 0 deletions backend/workers/twitter/.eslintrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
env:
browser: true
es2022: true

extends:
- airbnb-base
- airbnb-typescript/base
- plugin:@typescript-eslint/recommended
- plugin:prettier/recommended

parser: '@typescript-eslint/parser'

parserOptions:
project: tsconfig.json
ecmaVersion: latest
sourceType: module

rules:
no-plusplus: ["error", { "allowForLoopAfterthoughts": true }]
no-console: off
"@typescript-eslint/no-non-null-assertion": off
104 changes: 104 additions & 0 deletions backend/workers/twitter/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
6 changes: 6 additions & 0 deletions backend/workers/twitter/.prettierrc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
printWidth: 120 # Specify the line length that the printer will wrap on
tabWidth: 2 # Specify the number of spaces per indentation-level
useTabs: true # Indent lines with tabs instead of spaces
semi: true # Print semicolons at the ends of statements
bracketSpacing: true # Print spaces between brackets in object literals
parser: typescript # Specify which parser to use
37 changes: 37 additions & 0 deletions backend/workers/twitter/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
FROM node:18.18.0-alpine3.18 AS builder

# Create app directory
WORKDIR /app

# Copy dependencies files
COPY package.json yarn.lock ./

# Install dependencies
RUN yarn install --frozen-lockfile --ignore-scripts

# Get protobuf files
RUN apk add git protobuf protobuf-dev
RUN git clone https://github.com/RezaRahemtola/area-proto.git proto
RUN mkdir -p ./src/proto ; protoc --plugin=$(npm root)/.bin/protoc-gen-ts_proto --ts_proto_out=src/proto --ts_proto_opt=outputServices=grpc-js --ts_proto_opt=esModuleInterop=true -I=proto/ proto/area_back.proto proto/area_types.proto

# Copy source (see .dockerignore)
COPY . .

# Build
RUN yarn build

FROM node:18.18.0-alpine3.18 AS runner

WORKDIR /app

# Non-root user
RUN addgroup -S user \
&& adduser -S user -G user
RUN chown -R user:user /app
USER user

COPY --from=builder /app/dist ./
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json

ENTRYPOINT ["node", "--experimental-specifier-resolution=node", "main.js"]
Loading

0 comments on commit bbdf6c9

Please sign in to comment.