forked from admin/zeropost-engine
feat: P7 polls + P8 hashtags
P7 — Опросы в Telegram: - routes/polls.js: POST /api/channels/:id/poll (sendPoll + schedule support) - DB: scheduled_posts.post_type + meta для отложенных опросов - scheduledPostsRunner: обработка post_type='poll' через sendPoll - index.js: роут /api/channels подключён P8 — Хештеги: - ai.js: generateHashtags() через Claude Haiku, JSON-массив тегов - routes/generate.js: POST /api/generate/hashtags
This commit is contained in:
@@ -290,6 +290,36 @@ async function generateArticle(channel, opts = {}) {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Генерация хештегов для поста.
|
||||
* Возвращает массив строк без # (добавляем в UI).
|
||||
*/
|
||||
async function generateHashtags(channel, { postText, count = 8 }) {
|
||||
const niche = channel?.niche || '';
|
||||
const platform = channel?.platform || 'telegram';
|
||||
const system = `Ты эксперт по SMM. Генерируй хештеги для постов.
|
||||
Платформа: ${platform}. Ниша: ${niche || 'общая'}.
|
||||
ПРАВИЛА:
|
||||
- Только релевантные хештеги на русском или английском (по контексту)
|
||||
- Без символа # — просто слова
|
||||
- Без пробелов внутри тега (используй_подчёркивание)
|
||||
- Популярные + нишевые, не слишком общие (не #жизнь, #фото)
|
||||
- Ответь ТОЛЬКО JSON-массивом строк, без пояснений`;
|
||||
|
||||
const userMsg = `Пост:\n${postText.slice(0, 1000)}\n\nДай ${count} хештегов.`;
|
||||
const result = await chat(config.ai.models.topics || 'claude-haiku-4-5-20251001', system, userMsg, 0.5, 300);
|
||||
|
||||
try {
|
||||
const clean = result.replace(/```json|```/g, '').trim();
|
||||
const tags = JSON.parse(clean);
|
||||
if (!Array.isArray(tags)) throw new Error('not array');
|
||||
return tags.slice(0, count).map(t => String(t).replace(/^#/, '').replace(/\s+/g, '_').toLowerCase());
|
||||
} catch {
|
||||
// Fallback — парсим вручную
|
||||
return result.match(/\b[a-zа-яё][a-zа-яё0-9_]{2,29}\b/gi)?.slice(0, count) || [];
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
chat,
|
||||
image,
|
||||
@@ -297,4 +327,5 @@ module.exports = {
|
||||
transformPost,
|
||||
generateTopics,
|
||||
generateArticle,
|
||||
generateHashtags,
|
||||
};
|
||||
|
||||
@@ -325,10 +325,26 @@ async function publishOne(scheduledPost) {
|
||||
// imgSource === 'none' → photoUrl остаётся null
|
||||
}
|
||||
|
||||
if (!text) throw new Error('Empty text and no article');
|
||||
if (!text && scheduledPost.post_type !== 'poll') throw new Error('Empty text and no article');
|
||||
|
||||
let messageId;
|
||||
if (channel.platform === 'telegram' || !channel.platform) {
|
||||
|
||||
// Опрос — отдельная ветка
|
||||
if (scheduledPost.post_type === 'poll') {
|
||||
if (channel.platform !== 'telegram') throw new Error('Опросы только в Telegram');
|
||||
const { sendPoll } = require('../routes/polls');
|
||||
const meta = scheduledPost.meta || {};
|
||||
messageId = await sendPoll({
|
||||
channel,
|
||||
question: meta.question || scheduledPost.text,
|
||||
options: meta.options || [],
|
||||
is_anonymous: meta.is_anonymous ?? true,
|
||||
allows_multiple_answers: meta.allows_multiple_answers ?? false,
|
||||
type: meta.type || 'regular',
|
||||
correct_option_id: meta.correct_option_id,
|
||||
explanation: meta.explanation,
|
||||
});
|
||||
} else if (channel.platform === 'telegram' || !channel.platform) {
|
||||
messageId = await publishToTelegram({ channel, text, photoUrl, article });
|
||||
} else if (channel.platform === 'vk') {
|
||||
messageId = await publishToVK({ channel, text, photoUrl, article });
|
||||
|
||||
Reference in New Issue
Block a user