Skip to content

Commit

Permalink
Small fixes (#272)
Browse files Browse the repository at this point in the history
* chore: Add support for hiding deprecations

* feat: Add message truncation for long messages in notifier

The code changes in `notifier.ts` add support for truncating long messages before sending them via the Telegram API. If a message exceeds 4096 characters, it will be truncated and a warning message will be sent before sending the truncated message. This change improves the reliability of message delivery and prevents errors caused by exceeding the maximum message length.
  • Loading branch information
daniel-hauser authored May 14, 2024
1 parent a81b95d commit 78301eb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ Example:
| `TZ` | `'Asia/Jerusalem'` | A timezone for the process - used for the formatting of the timestamp |
| `FUTURE_MONTHS` | `1` | The amount of months that will be scrapped in the future, starting from the day calculated using `DAYS_BACK` |
| `TRANSACTION_HASH_TYPE` | `` | The hash type to use for the transaction hash. Can be `moneyman` or empty. The default will be changed to `moneyman` in the upcoming versions |
| `HIDDEN_DEPRECATIONS` | '' | A comma separated list of deprecations to hide |

### Get notified in telegram

Expand Down
13 changes: 12 additions & 1 deletion src/notifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ logToPublicLog(

export async function send(message: string) {
logger(message);
if (message.length > 4096) {
send(`Next message is too long (${message.length} characters), truncating`);
return await bot?.telegram.sendMessage(
TELEGRAM_CHAT_ID,
message.slice(0, 4096),
);
}
return await bot?.telegram.sendMessage(TELEGRAM_CHAT_ID, message);
}

Expand Down Expand Up @@ -65,7 +72,11 @@ export function sendError(message: any, caller: string = "") {
const deprecationMessages = {
["hashFiledChange"]: `This run is using the old transaction hash field, please update to the new one (it might require manual de-duping of some transactions). See https://github.com/daniel-hauser/moneyman/issues/268 for more details.`,
} as const;
const sentDeprecationMessages = new Set<string>();
const { HIDDEN_DEPRECATIONS = "" } = process.env;
logger(`Hidden deprecations: ${HIDDEN_DEPRECATIONS}`);

const sentDeprecationMessages = new Set<string>(HIDDEN_DEPRECATIONS.split(","));

export function sendDeprecationMessage(
messageId: keyof typeof deprecationMessages,
) {
Expand Down

0 comments on commit 78301eb

Please sign in to comment.