fix: telegram not get message because beyond int i use string solve this problem
Browse files
src/services/telegram/TelegramService.ts
CHANGED
|
@@ -235,19 +235,20 @@ class TelegramService {
|
|
| 235 |
throw new Error('Telegram service is not running')
|
| 236 |
}
|
| 237 |
|
| 238 |
-
|
| 239 |
-
|
|
|
|
| 240 |
logTelegramDebug(`[telegram] allowedUserIds: ${JSON.stringify(this.config.allowedUserIds)}`)
|
| 241 |
|
| 242 |
let lastMessageId: number | undefined
|
| 243 |
|
| 244 |
for (const chunk of chunkTelegramMessage(text)) {
|
| 245 |
-
logTelegramDebug(`[telegram] sending chunk to chat_id: ${
|
| 246 |
const response = await this.callTelegram<TelegramSendMessageResponse>(
|
| 247 |
this.config,
|
| 248 |
'sendMessage',
|
| 249 |
{
|
| 250 |
-
chat_id:
|
| 251 |
text: chunk,
|
| 252 |
...(replyMarkup ? { reply_markup: replyMarkup } : {}),
|
| 253 |
},
|
|
@@ -268,11 +269,13 @@ class TelegramService {
|
|
| 268 |
throw new Error('Telegram service is not running')
|
| 269 |
}
|
| 270 |
|
|
|
|
|
|
|
| 271 |
await this.callTelegram<TelegramEditMessageResponse>(
|
| 272 |
this.config,
|
| 273 |
'editMessageText',
|
| 274 |
{
|
| 275 |
-
chat_id:
|
| 276 |
message_id: messageId,
|
| 277 |
text,
|
| 278 |
...(replyMarkup ? { reply_markup: replyMarkup } : {}),
|
|
@@ -513,6 +516,9 @@ class TelegramService {
|
|
| 513 |
: timeoutController.signal
|
| 514 |
|
| 515 |
try {
|
|
|
|
|
|
|
|
|
|
| 516 |
const response = await fetch(
|
| 517 |
`${TELEGRAM_API_BASE}/bot${config.botToken}/${method}`,
|
| 518 |
{
|
|
@@ -520,7 +526,7 @@ class TelegramService {
|
|
| 520 |
headers: {
|
| 521 |
'content-type': 'application/json',
|
| 522 |
},
|
| 523 |
-
body
|
| 524 |
signal: combinedSignal,
|
| 525 |
},
|
| 526 |
)
|
|
|
|
| 235 |
throw new Error('Telegram service is not running')
|
| 236 |
}
|
| 237 |
|
| 238 |
+
// Telegram API 支持 chat_id 为字符串格式(特别是对于超出安全整数范围的 ID)
|
| 239 |
+
// 直接使用字符串格式,避免整数溢出问题
|
| 240 |
+
logTelegramDebug(`[telegram] sendMessage called: chatId=${chatId} (type: ${typeof chatId}), text length=${text.length}`)
|
| 241 |
logTelegramDebug(`[telegram] allowedUserIds: ${JSON.stringify(this.config.allowedUserIds)}`)
|
| 242 |
|
| 243 |
let lastMessageId: number | undefined
|
| 244 |
|
| 245 |
for (const chunk of chunkTelegramMessage(text)) {
|
| 246 |
+
logTelegramDebug(`[telegram] sending chunk to chat_id: ${chatId}`)
|
| 247 |
const response = await this.callTelegram<TelegramSendMessageResponse>(
|
| 248 |
this.config,
|
| 249 |
'sendMessage',
|
| 250 |
{
|
| 251 |
+
chat_id: chatId,
|
| 252 |
text: chunk,
|
| 253 |
...(replyMarkup ? { reply_markup: replyMarkup } : {}),
|
| 254 |
},
|
|
|
|
| 269 |
throw new Error('Telegram service is not running')
|
| 270 |
}
|
| 271 |
|
| 272 |
+
// Telegram API 支持 chat_id 为字符串格式(特别是对于超出安全整数范围的 ID)
|
| 273 |
+
// 直接使用字符串格式,避免整数溢出问题
|
| 274 |
await this.callTelegram<TelegramEditMessageResponse>(
|
| 275 |
this.config,
|
| 276 |
'editMessageText',
|
| 277 |
{
|
| 278 |
+
chat_id: chatId,
|
| 279 |
message_id: messageId,
|
| 280 |
text,
|
| 281 |
...(replyMarkup ? { reply_markup: replyMarkup } : {}),
|
|
|
|
| 516 |
: timeoutController.signal
|
| 517 |
|
| 518 |
try {
|
| 519 |
+
const body = JSON.stringify(payload)
|
| 520 |
+
logTelegramDebug(`[telegram] API request body: ${body}`)
|
| 521 |
+
|
| 522 |
const response = await fetch(
|
| 523 |
`${TELEGRAM_API_BASE}/bot${config.botToken}/${method}`,
|
| 524 |
{
|
|
|
|
| 526 |
headers: {
|
| 527 |
'content-type': 'application/json',
|
| 528 |
},
|
| 529 |
+
body,
|
| 530 |
signal: combinedSignal,
|
| 531 |
},
|
| 532 |
)
|