@ebowwa/channel-telegram 1.15.4 → 1.15.5

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/plugin.ts +39 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ebowwa/channel-telegram",
3
- "version": "1.15.4",
3
+ "version": "1.15.5",
4
4
  "description": "Pure Telegram protocol adapter implementing ChannelConnector",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
package/src/plugin.ts CHANGED
@@ -198,7 +198,25 @@ const createOutboundAdapter = (
198
198
  });
199
199
  }
200
200
  }
201
- } catch (error) {
201
+ } catch (error: any) {
202
+ // Handle entity parse errors by retrying without formatting
203
+ if (error?.message?.includes("can't parse entities")) {
204
+ console.log("[TelegramPlugin] Entity parse error in updateStream, retrying without formatting");
205
+ try {
206
+ if (!stream.messageId) {
207
+ const result = await bot.sendMessage(chatId, text);
208
+ stream.messageId = result.message_id;
209
+ } else {
210
+ await bot.editMessageText(text, {
211
+ chat_id: chatId,
212
+ message_id: stream.messageId,
213
+ });
214
+ }
215
+ } catch (retryError) {
216
+ console.error(`[TelegramPlugin] updateStream fallback failed: ${(retryError as Error).message}`);
217
+ }
218
+ return;
219
+ }
202
220
  console.error(`[TelegramOutbound] Stream update error: ${(error as Error).message}`);
203
221
  }
204
222
  },
@@ -231,8 +249,26 @@ const createOutboundAdapter = (
231
249
  parse_mode: options?.parseMode as "Markdown" | "HTML",
232
250
  });
233
251
  }
234
- } catch (error) {
235
- console.error(`[TelegramOutbound] Stream finalize error: ${(error as Error).message}`);
252
+ } catch (error: any) {
253
+ // Handle entity parse errors by retrying without formatting
254
+ if (error?.message?.includes("can't parse entities")) {
255
+ console.log("[TelegramPlugin] Entity parse error in finalizeStream, retrying without formatting");
256
+ try {
257
+ if (account.nativeStreaming) {
258
+ const result = await bot.sendMessage(chatId, finalText);
259
+ messageId = result.message_id;
260
+ } else if (stream.messageId) {
261
+ await bot.editMessageText(finalText, {
262
+ chat_id: chatId,
263
+ message_id: stream.messageId,
264
+ });
265
+ }
266
+ } catch (retryError) {
267
+ console.error(`[TelegramPlugin] finalizeStream fallback failed: ${(retryError as Error).message}`);
268
+ }
269
+ } else {
270
+ console.error(`[TelegramOutbound] Stream finalize error: ${(error as Error).message}`);
271
+ }
236
272
  } finally {
237
273
  activeStreams.delete(streamId);
238
274
  }