read tg_bot_updates from db
Deploy app frontend / app frontend (push) Successful in 2m34s
Deploy db-migrations / db-migrations (push) Successful in 1m12s
Deploy service message-delivery-method-web-push / service message-delivery-method-web-push (push) Successful in 1m38s
Deploy service tg-bot / service tg-bot (push) Failing after 2m11s

This commit is contained in:
2024-12-15 03:14:39 +02:00
parent c075c5f708
commit 0ac5e9ce62
31 changed files with 211 additions and 331 deletions
+2
View File
@@ -0,0 +1,2 @@
export * from "./updates/saveUpdate";
export type * from "./types";
+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"}
+23
View File
@@ -0,0 +1,23 @@
import type { BaseDocument } from "@hereconnect/types";
export interface TgBotUpdateWebhookDesignDocument extends BaseDocument {
_id: "_design/tg_bot_webhook";
type: "_design/tg_bot_webhook";
updated_at: BaseDocument["created_at"];
updates: {
saveUpdate: string;
};
constants: {
telegram_secret_token: string;
telegram_webhook_url?: string;
};
}
export interface TgBotUpdateDocument extends BaseDocument {
/**
* Тип документа для идентификации (фиксированное значение "tg_bot_update")
*/
type: "tg_bot_update";
/**
* Данные обновления Telegram
*/
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 { TgBotUpdateWebhookDesignDocument, TgBotUpdateDocument } from "../types";
export type { TgBotUpdateWebhookDesignDocument };
type CouchRequest = {
body: string;
headers: Record<string, string>;
method: string;
query: Record<string, string>;
userCtx: {
name: string | null;
roles: string[];
};
};
type CouchResponse = [
TgBotUpdateDocument | null,
{
code: number;
body: string;
} | string
];
type UpdateFunction = (doc: TgBotUpdateDocument | null, req: CouchRequest) => CouchResponse;
export declare const saveUpdate: UpdateFunction;
export declare const saveUpdateString: string;
@@ -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_bot_update:" + data.update_id.toString(),
type: "tg_bot_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":";;;AA4BO,IAAM,UAAU,GAAmB,UAExC,GAA+B,EAC/B,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,gBAAgB,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE;QACjD,IAAI,EAAE,eAAe;QACrB,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"}