Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: TG Informer services and clients #47

Draft
wants to merge 30 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
b5bb2e8
feat(campaign): create campaign action message
netpoe Mar 1, 2023
f8c14da
chore(campaign): removes CampaignUser model
netpoe Mar 1, 2023
a0b40b3
refactor(user): exports with tsconfig-build.json file
netpoe Mar 1, 2023
3d448af
feat(bot): stores campaign action messages async
netpoe Mar 1, 2023
1c6164e
feat(campaign): getCampaignActionMessages
netpoe Mar 1, 2023
837c02b
feat(campaign): getCampaignActionMessagesByUserId
netpoe Mar 1, 2023
76cbcc0
feat(bot): checks if user has started a campaign
netpoe Mar 1, 2023
8d4f5e3
feat: web service
netpoe Mar 4, 2023
e617140
feat(web): tgi home WIP
netpoe Mar 4, 2023
92ef20d
feat(web): navbar and display webfont
netpoe Mar 6, 2023
4712ad7
feat(web): navbar icon interval
netpoe Mar 6, 2023
7f3d032
feat(web): usecases and faqs content
netpoe Mar 6, 2023
1c79cfe
feat(web): telegram login button and navbar stats
netpoe Mar 6, 2023
48acc73
feat(user): create user location model
netpoe Mar 6, 2023
cd4fea3
feat(bot): stores user coordinates on /start command
netpoe Mar 6, 2023
5a83012
feat(web): graphql server & createCampaignAction resolver
netpoe Mar 8, 2023
807952f
refactor(campaign): returns full object
netpoe Mar 8, 2023
9341c25
feat(bot): creates campaign
netpoe Mar 8, 2023
a83e8a8
feat(bot): runs campaign session with info from db
netpoe Mar 8, 2023
bb107e9
feat(web): renders campaign actions
netpoe Mar 9, 2023
57da97e
feat(bot/web): jsonwebtoken auth WIP
netpoe Mar 10, 2023
1e97756
feat(EdtiCampaign): creates PolygonBounds modal map
netpoe Mar 17, 2023
6f308d5
feat(workflows): creates TODO to Issue
netpoe Mar 17, 2023
53d50a8
chore(PolygonBounds): sets @TODO comments
netpoe Mar 17, 2023
8467815
feat(user/web): getUsersCoordinates
netpoe Mar 17, 2023
89feddc
refactor(PolygonBounds): map features helpers
netpoe Mar 18, 2023
b1d852a
feat(campaign/web): sets campaign bounds
netpoe Mar 19, 2023
141445e
feat(user): getUsersByLocationBounds
netpoe Mar 19, 2023
6f13eb8
feat(web): displays estimate users by location bounds count
netpoe Mar 19, 2023
5a30584
feat(web): btcpayserver invoice-settled webhook
netpoe Mar 23, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 13 additions & 0 deletions .github/workflows/todo-to-issue.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: "Run TODO to Issue"
on: ["push"]
jobs:
build:
runs-on: "ubuntu-latest"
steps:
- uses: "actions/checkout@v3"
- name: "TODO to Issue"
uses: "alstr/todo-to-issue-action@v4"
with:
PROJECTS_SECRET: ${{ secrets.TODO_TO_ISSUE }}
INPUT_GITHUB_URL: "https://github.com/"
IDENTIFIERS: '[{"name": "@TODO", "labels": []}]'
7 changes: 7 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

localPath=$(echo $PATH)
export PATH=$localPath

yarn lint-staged
9 changes: 9 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@
"port": 9227,
"skipFiles": ["${workspaceRoot}/node_modules/**/*", "<node_internals>/**/*.js"]
},
{
"type": "node",
"request": "attach",
"name": "WEB: Attach by Process ID",
"cwd": "${workspaceRoot}/web/src",
"trace": true,
"port": 9229,
"skipFiles": ["${workspaceRoot}/node_modules/**/*", "<node_internals>/**/*.js"]
},
{
"type": "node",
"request": "launch",
Expand Down
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
{
"python.pythonPath": "infra/.venv/bin/python"
"editor.codeActionsOnSave": {
"source.organizeImports": false,
"source.fixAll": true,
"source.fixAll.stylelint": true
}
}
1 change: 1 addition & 0 deletions bot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"@grpc/grpc-js": "^1.8.9",
"express": "^4.18.2",
"i18next": "^22.4.10",
"jsonwebtoken": "^9.0.0",
"moment": "^2.29.4",
"node-telegram-bot-api": "^0.61.0",
"stream-chat": "^8.4.0",
Expand Down
62 changes: 62 additions & 0 deletions bot/src/commands/campaign/create.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { findUserByTelegramUserId } from "@rapydbot/user";
import { createCampaign } from "@rapydbot/campaign";
import jwt from "jsonwebtoken";

import { IBotCommand } from "../types";
import { TGInformerBot } from "../../tg-informer";
import { CustomMessage } from "../../types";
import { translationKeys } from "../../i18n";

export class CreateCampaignCommand implements IBotCommand {
private bot: TGInformerBot;

constructor(bot: TGInformerBot) {
this.bot = bot;
}

async onText(msg: CustomMessage) {
await this.createCampaign(msg);
}

private async createCampaign(msg: CustomMessage): Promise<void> {
try {
const { userId } = await findUserByTelegramUserId(this.bot.clients.user, {
telegramFromUserId: msg.from.id,
});

const { campaignId } = await createCampaign(this.bot.clients.campaign, {
issuerId: userId,
});

const token = jwt.sign(
{
userId,
},
process.env.JWT_SECRET,
);

// @TODO i18n
this.bot.reply(msg, `¡Campaña creada!`, {
reply_markup: {
inline_keyboard: [
[
{
text: `Editar Campaña`,
url: `http://tgi.com:3004/campaign/edit/${campaignId}?token=${token}`,
},
],
],
},
});
} catch (error) {
console.log(error);

this.handleErrorReply(error, msg);
}
}

private handleErrorReply(error: Error, msg: CustomMessage) {
// @TODO handle error codes switch
return this.bot.replyWithTranslation(msg, translationKeys.start_command_error);
}
}
45 changes: 19 additions & 26 deletions bot/src/commands/start.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,41 @@
import { CreateUserRequest } from "@rapydbot/user/client";
import { findUserByTelegramUserIdOrCreateUser } from "@rapydbot/user";

import { Bot } from "../Bot";
import { TGInformerBot } from "../tg-informer";
import { translationKeys } from "../i18n";
import { CustomMessage } from "../types";

import { IBotCommand } from "./types";

export class StartCommand implements IBotCommand {
private bot: Bot;
private bot: TGInformerBot;

constructor(bot: Bot) {
constructor(bot: TGInformerBot) {
this.bot = bot;
}

async onText(msg: CustomMessage) {
try {
await this.findUserByTelegramUserIdOrCreateUser(msg);
await this.createUser(msg);
} catch (error) {
this.handleErrorReply(error, msg);
}
}

private async findUserByTelegramUserIdOrCreateUser(msg: CustomMessage): Promise<void> {
return new Promise((resolve, reject) => {
const createUserRequest = new CreateUserRequest();

createUserRequest.setTelegramFromUserId(msg.from.id);
createUserRequest.setTelegramUsername(msg.from.username);

if (msg.chat.type === "private") {
createUserRequest.setTelegramPrivateChatId(msg.chat.id);
}

this.bot.clients.user.findUserByTelegramUserIdOrCreateUser(
createUserRequest,
(err, _reply) => {
if (Boolean(err)) {
return reject(err);
}

resolve();
},
);
private async createUser(msg: CustomMessage): Promise<void> {
await findUserByTelegramUserIdOrCreateUser(this.bot.clients.user, {
telegramFromUserId: msg.from.id,
telegramUsername: msg.from.username,
telegramPrivateChatId: msg.chat.type === "private" ? msg.chat.id : undefined,
});

// @TODO i18n
this.bot.reply(
msg,
`Guardamos tus coordenadas periódicamente para asignarte campañas de manera eficiente.`,
{
reply_markup: { keyboard: [[{ text: `Compartir Coordenadas`, request_location: true }]] },
},
);
}

private handleErrorReply(error: Error, msg: CustomMessage) {
Expand Down
Loading