blun-king-cli 9.1.230 → 9.1.231

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blun-king-cli",
3
- "version": "9.1.230",
3
+ "version": "9.1.231",
4
4
  "description": "BLUN CLI - your own AI agent with a Telegram channel. Get it done. With BLUN.",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -9814,6 +9814,29 @@ function isRecentDuplicate(chatId, text) {
9814
9814
  } catch {}
9815
9815
  return false;
9816
9816
  }
9817
+ function telegramErrorMessage(error) {
9818
+ return error instanceof Error ? error.message : String(error);
9819
+ }
9820
+ function isTelegramEntityParseError(error) {
9821
+ return /bad request: can't parse entities:/iu.test(telegramErrorMessage(error));
9822
+ }
9823
+ async function sendTelegramTextChunk(api, chatId, text, options, parseMode) {
9824
+ try {
9825
+ return {
9826
+ sent: await api.sendMessage(chatId, text, {
9827
+ ...options,
9828
+ ...parseMode !== void 0 ? { parse_mode: parseMode } : {}
9829
+ }),
9830
+ plainTextFallback: false
9831
+ };
9832
+ } catch (error) {
9833
+ if (parseMode === void 0 || !isTelegramEntityParseError(error)) throw error;
9834
+ return {
9835
+ sent: await api.sendMessage(chatId, text, options),
9836
+ plainTextFallback: true
9837
+ };
9838
+ }
9839
+ }
9817
9840
  async function runReply(api, args) {
9818
9841
  const chatId = resolveAllowedChatId(args.chat_id);
9819
9842
  const text = args.text;
@@ -9849,13 +9872,15 @@ async function runReply(api, args) {
9849
9872
  const replyMode = access.replyToMode ?? "first";
9850
9873
  const chunks = chunk(text, limit, mode);
9851
9874
  const sentIds = [];
9875
+ let plainTextFallbacks = 0;
9852
9876
  try {
9853
9877
  for (let i = 0; i < chunks.length; i++) {
9854
9878
  const shouldReplyTo = replyTo !== void 0 && replyMode !== "off" && (replyMode === "all" || i === 0);
9855
- const sent = await api.sendMessage(chatId, chunks[i], {
9856
- ...shouldReplyTo ? { reply_parameters: { message_id: replyTo } } : {},
9857
- ...parseMode !== void 0 ? { parse_mode: parseMode } : {}
9858
- });
9879
+ const result = await sendTelegramTextChunk(api, chatId, chunks[i], {
9880
+ ...shouldReplyTo ? { reply_parameters: { message_id: replyTo } } : {}
9881
+ }, parseMode);
9882
+ const sent = result.sent;
9883
+ if (result.plainTextFallback) plainTextFallbacks += 1;
9859
9884
  sentIds.push(sent.message_id);
9860
9885
  }
9861
9886
  } catch (err) {
@@ -9875,6 +9900,7 @@ async function runReply(api, args) {
9875
9900
  chat_id: chatId,
9876
9901
  message_ids: sentIds,
9877
9902
  text,
9903
+ ...plainTextFallbacks > 0 ? { plain_text_fallbacks: plainTextFallbacks } : {},
9878
9904
  ...files.length > 0 ? { files } : {}
9879
9905
  });
9880
9906
  return sentIds.length === 1 ? `sent (id: ${sentIds[0]})` : `sent ${sentIds.length} parts (ids: ${sentIds.join(", ")})`;