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
@@ -1 +1,2 @@
export * from "./updates/saveUpdate";
export type * from "./types";
+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;
}
@@ -1,5 +1,5 @@
import { TelegramWebhookDesignDocument, TgUpdateDocument } from "../types";
export type { TelegramWebhookDesignDocument };
import { TgBotUpdateWebhookDesignDocument, TgBotUpdateDocument } from "../types";
export type { TgBotUpdateWebhookDesignDocument };
type CouchRequest = {
body: string;
headers: Record<string, string>;
@@ -11,12 +11,12 @@ type CouchRequest = {
};
};
type CouchResponse = [
TgUpdateDocument | null,
TgBotUpdateDocument | null,
{
code: number;
body: string;
} | string
];
type UpdateFunction = (doc: TgUpdateDocument | null, req: CouchRequest) => CouchResponse;
type UpdateFunction = (doc: TgBotUpdateDocument | null, req: CouchRequest) => CouchResponse;
export declare const saveUpdate: UpdateFunction;
export declare const saveUpdateString: string;
@@ -11,8 +11,8 @@ var saveUpdate = function (doc, req) {
return [null, { code: 304, body: "Update already exists" }];
}
doc = {
_id: "tg_update:" + data.update_id.toString(),
type: "tg_update",
_id: "tg_bot_update:" + data.update_id.toString(),
type: "tg_bot_update",
data: data,
created_at: new Date().toISOString(),
};
@@ -1 +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"}
{"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"}
@@ -1,5 +1,5 @@
{
"name": "@hereconnect/tg-bot-webhook-ddoc",
"name": "@hereconnect/tg-bot-update-webhook-ddoc",
"version": "1.0.1",
"license": "@hereconnect/license",
"private": true,
@@ -1 +1,2 @@
export * from "./updates/saveUpdate";
export type * from "./types";
@@ -0,0 +1,28 @@
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;
}
@@ -1,6 +1,9 @@
import { TelegramWebhookDesignDocument, TgUpdateDocument } from "../types";
import {
TgBotUpdateWebhookDesignDocument,
TgBotUpdateDocument,
} from "../types";
export type { TelegramWebhookDesignDocument };
export type { TgBotUpdateWebhookDesignDocument };
type CouchRequest = {
body: string; // JSON-строка
@@ -14,18 +17,18 @@ type CouchRequest = {
};
type CouchResponse = [
TgUpdateDocument | null,
TgBotUpdateDocument | null,
{ code: number; body: string } | string,
];
type UpdateFunction = (
doc: TgUpdateDocument | null,
doc: TgBotUpdateDocument | null,
req: CouchRequest,
) => CouchResponse;
export const saveUpdate: UpdateFunction = function (
this: TelegramWebhookDesignDocument,
doc: TgUpdateDocument | null,
this: TgBotUpdateWebhookDesignDocument,
doc: TgBotUpdateDocument | null,
req: CouchRequest,
): CouchResponse {
const token = req.headers["X-Telegram-Bot-Api-Secret-Token"];
@@ -40,8 +43,8 @@ export const saveUpdate: UpdateFunction = function (
}
doc = {
_id: "tg_update:" + data.update_id.toString(),
type: "tg_update",
_id: "tg_bot_update:" + data.update_id.toString(),
type: "tg_bot_update",
data: data,
created_at: new Date().toISOString(),
};
-16
View File
@@ -1,16 +0,0 @@
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;
}
-19
View File
@@ -1,19 +0,0 @@
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;
}