create qr-codes by tg bot
Deploy app frontend / app frontend (push) Failing after 48s
Deploy db-migrations / db-migrations (push) Failing after 35s
Deploy service message-delivery-method-web-push / service message-delivery-method-web-push (push) Failing after 53s

This commit is contained in:
2024-12-10 13:21:38 +02:00
parent e9b3df38fe
commit 1810c550ba
91 changed files with 3317 additions and 1909 deletions
+1
View File
@@ -0,0 +1 @@
export * from "./updates/saveUpdate";
+18
View File
@@ -0,0 +1,18 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./updates/saveUpdate"), exports);
//# sourceMappingURL=index.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC"}
+16
View File
@@ -0,0 +1,16 @@
import type { BaseDocument } from "@hereconnect/types";
export interface TelegramWebhookDesignDocument extends BaseDocument {
_id: "_design/webhook";
type: "_design/webhook";
updated_at: BaseDocument["created_at"];
updates: {
saveUpdate: string;
};
constants: {
telegram_secret_token: string;
telegram_webhook_url?: string;
};
}
export interface TgUpdateDocument extends BaseDocument {
data: unknown;
}
+3
View File
@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=types.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,22 @@
import { TelegramWebhookDesignDocument, TgUpdateDocument } from "../types";
export type { TelegramWebhookDesignDocument };
type CouchRequest = {
body: string;
headers: Record<string, string>;
method: string;
query: Record<string, string>;
userCtx: {
name: string | null;
roles: string[];
};
};
type CouchResponse = [
TgUpdateDocument | null,
{
code: number;
body: string;
} | string
];
type UpdateFunction = (doc: TgUpdateDocument | null, req: CouchRequest) => CouchResponse;
export declare const saveUpdate: UpdateFunction;
export declare const saveUpdateString: string;
+23
View File
@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.saveUpdateString = exports.saveUpdate = void 0;
var saveUpdate = function (doc, req) {
var token = req.headers["X-Telegram-Bot-Api-Secret-Token"];
if (token !== this.constants.telegram_secret_token) {
return [null, { code: 403, body: "Forbidden: Invalid token" }];
}
var data = JSON.parse(req.body);
if (doc) {
return [null, { code: 304, body: "Update already exists" }];
}
doc = {
_id: "tg_update:" + data.update_id.toString(),
type: "tg_update",
data: data,
created_at: new Date().toISOString(),
};
return [doc, "Message saved"];
};
exports.saveUpdate = saveUpdate;
exports.saveUpdateString = exports.saveUpdate.toString();
//# sourceMappingURL=saveUpdate.js.map
@@ -0,0 +1 @@
{"version":3,"file":"saveUpdate.js","sourceRoot":"","sources":["../../src/updates/saveUpdate.ts"],"names":[],"mappings":";;;AAyBO,IAAM,UAAU,GAAmB,UAExC,GAA4B,EAC5B,GAAiB;IAEjB,IAAM,KAAK,GAAG,GAAG,CAAC,OAAO,CAAC,iCAAiC,CAAC,CAAC;IAC7D,IAAI,KAAK,KAAK,IAAI,CAAC,SAAS,CAAC,qBAAqB,EAAE,CAAC;QACnD,OAAO,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,0BAA0B,EAAE,CAAC,CAAC;IACjE,CAAC;IAED,IAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAElC,IAAI,GAAG,EAAE,CAAC;QACR,OAAO,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,uBAAuB,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED,GAAG,GAAG;QACJ,GAAG,EAAE,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE;QAC7C,IAAI,EAAE,WAAW;QACjB,IAAI,EAAE,IAAI;QACV,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;KACrC,CAAC;IAEF,OAAO,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC;AAChC,CAAC,CAAC;AAxBW,QAAA,UAAU,cAwBrB;AAEW,QAAA,gBAAgB,GAAG,kBAAU,CAAC,QAAQ,EAAE,CAAC"}
@@ -0,0 +1,25 @@
// eslint.config.mjs
import typescriptPlugin from "@typescript-eslint/eslint-plugin";
import parser from "@typescript-eslint/parser";
export default [
{
ignores: ["dist", "node_modules"], // Исключаем папки из проверки
},
{
files: ["src/**/*.ts"], // Проверяем только TypeScript файлы
languageOptions: {
parser, // Используем парсер TypeScript
ecmaVersion: "latest", // Последняя версия ECMAScript
sourceType: "module", // Модули ES
},
plugins: {
"@typescript-eslint": typescriptPlugin, // Используем плагин TypeScript
},
rules: {
"@typescript-eslint/no-unused-vars": ["error"], // Ошибка для неиспользуемых переменных
semi: ["error", "always"], // Всегда требовать точку с запятой
quotes: ["error", "double"], // Использовать двойные кавычки
},
},
];
+36
View File
@@ -0,0 +1,36 @@
{
"name": "@hereconnect/tg-bot-webhook-ddoc",
"version": "1.0.1",
"license": "@hereconnect/license",
"private": true,
"engines": {
"node": ">=v20.10.0",
"pnpm": ">=8.15.0"
},
"contributors": [],
"scripts": {
"build": "tsc",
"type-check": "tsc --noEmit",
"clean": "rm -rf dist",
"lint": "eslint src",
"lint:fix": "eslint src --fix",
"validate": "npm run type-check && npm run lint"
},
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.js",
"types": "./dist/index.d.ts",
"require": "./dist/index.js"
}
},
"files": ["dist/**/*"],
"devDependencies": {
"@hereconnect/types": "workspace:^",
"@typescript-eslint/eslint-plugin": "^8.18.0",
"@typescript-eslint/parser": "^8.18.0",
"eslint": "^9.16.0"
}
}
@@ -0,0 +1 @@
export * from "./updates/saveUpdate";
+19
View File
@@ -0,0 +1,19 @@
import type { BaseDocument } from "@hereconnect/types";
export interface TelegramWebhookDesignDocument extends BaseDocument {
_id: "_design/webhook";
type: "_design/webhook";
updated_at: BaseDocument["created_at"];
updates: {
saveUpdate: string;
};
constants: {
telegram_secret_token: string;
telegram_webhook_url?: string;
};
}
export interface TgUpdateDocument extends BaseDocument {
data: unknown;
}
@@ -0,0 +1,52 @@
import { TelegramWebhookDesignDocument, TgUpdateDocument } from "../types";
export type { TelegramWebhookDesignDocument };
type CouchRequest = {
body: string; // JSON-строка
headers: Record<string, string>; // Заголовки запроса
method: string; // HTTP-метод (обычно POST для update handlers)
query: Record<string, string>; // Параметры запроса (например, ?key=value)
userCtx: {
name: string | null; // Имя пользователя, если используется аутентификация
roles: string[]; // Роли пользователя
};
};
type CouchResponse = [
TgUpdateDocument | null,
{ code: number; body: string } | string,
];
type UpdateFunction = (
doc: TgUpdateDocument | null,
req: CouchRequest,
) => CouchResponse;
export const saveUpdate: UpdateFunction = function (
this: TelegramWebhookDesignDocument,
doc: TgUpdateDocument | null,
req: CouchRequest,
): CouchResponse {
const token = req.headers["X-Telegram-Bot-Api-Secret-Token"];
if (token !== this.constants.telegram_secret_token) {
return [null, { code: 403, body: "Forbidden: Invalid token" }];
}
const data = JSON.parse(req.body);
if (doc) {
return [null, { code: 304, body: "Update already exists" }];
}
doc = {
_id: "tg_update:" + data.update_id.toString(),
type: "tg_update",
data: data,
created_at: new Date().toISOString(),
};
return [doc, "Message saved"];
};
export const saveUpdateString = saveUpdate.toString();
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"target": "ES5",
"module": "CommonJS",
"outDir": "dist",
"strict": true,
"moduleResolution": "node",
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"sourceMap": true,
"declaration": true
},
"files": ["src/index.ts"],
}