/
dev116
/
max-adapter
Обзор
Документация
Войти
/
dev116
/
max-adapter
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
maxApi.js
36 строк
1006 B
Dmitry Pozdnyakov
Fix editMaxMessage: use raw fetch instead of library (matches d24-postgres approach)
24 мар 2026, 17:15
24 мар 2026, 17:15
678d013
Код
Авторство
О чём код?
import { Bot } from '@maxhub/max-bot-api' const MAX_API = 'https://platform-api.max.ru' const bot = new Bot(process.env.MAX_TOKEN) export async function sendMaxMessage({ userId, chatId, text }) { if (userId) { return await bot.api.sendMessageToUser(Number(userId), text) } else if (chatId) { return await bot.api.sendMessageToChat(Number(chatId), text) } else { throw new Error('sendMaxMessage: userId or chatId is required') } } export async function editMaxMessage({ messageId, text }) { const resp = await fetch(`${MAX_API}/messages?message_id=${messageId}`, { method: 'PUT', headers: { Authorization: process.env.MAX_TOKEN, 'Content-Type': 'application/json', }, body: JSON.stringify({ text }), }) const raw = await resp.text() if (!resp.ok) { throw new Error(`MAX edit failed: ${resp.status} ${raw}`) } } export function extractMessageId(data) { if (!data || typeof data !== 'object') return null return data.body?.mid ?? null }