feat(telegram): add message chunking and update channel configuration
Implement message splitting for messages exceeding Telegram's 4096 character limit. Update header branding, increase max_tokens to 4000, adjust END_HOUR to 20, update default AI model, and revise documentation to reflect channel setup instead of groups.
This commit is contained in:
@@ -78,9 +78,12 @@ def generate_insight(topic):
|
||||
{"role": "user", "content": prompt},
|
||||
],
|
||||
temperature=0.7,
|
||||
max_tokens=1500,
|
||||
max_tokens=4000,
|
||||
)
|
||||
return response.choices[0].message.content.strip()
|
||||
content = response.choices[0].message.content
|
||||
if not content:
|
||||
return "[Erro ao gerar insight: resposta vazia da API]"
|
||||
return content.strip()
|
||||
except Exception as e:
|
||||
return f"[Erro ao gerar insight: {e}]"
|
||||
|
||||
@@ -88,9 +91,10 @@ def generate_insight(topic):
|
||||
def send_telegram_message(text, topic):
|
||||
now = datetime.now()
|
||||
header = (
|
||||
f"🤖 *ThorAgentIA*\n"
|
||||
f"🤖 *Syspanel Insights - by ThorAgentIA*\n"
|
||||
f"🤖 *https://syspanel.com.br*\n"
|
||||
f"🕒 {now.strftime('%d/%m/%Y %H:%M:%S')}\n"
|
||||
f"🧠 Modelo: `{DEFAULT_AI_MODEL}`\n"
|
||||
# f"🧠 Modelo: `{DEFAULT_AI_MODEL}`\n"
|
||||
f"📌 Assunto: {topic}\n\n"
|
||||
)
|
||||
message = header + text
|
||||
@@ -101,10 +105,35 @@ def send_telegram_message(text, topic):
|
||||
"text": message,
|
||||
"parse_mode": "Markdown",
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.post(url, json=payload, timeout=30)
|
||||
response.raise_for_status()
|
||||
print(f"[{now.strftime('%Y-%m-%d %H:%M:%S')}] Mensagem enviada com sucesso.")
|
||||
if len(message) <= 4096:
|
||||
response = requests.post(url, json=payload, timeout=30)
|
||||
response.raise_for_status()
|
||||
print(f"[{now.strftime('%Y-%m-%d %H:%M:%S')}] Mensagem enviada com sucesso.")
|
||||
else:
|
||||
chunks = []
|
||||
current = header
|
||||
parts = text.split("\n\n")
|
||||
for part in parts:
|
||||
candidate = current + part
|
||||
if len(candidate) <= 4096:
|
||||
current = candidate + "\n\n"
|
||||
else:
|
||||
chunks.append(current.strip())
|
||||
current = header + part + "\n\n"
|
||||
if current.strip():
|
||||
chunks.append(current.strip())
|
||||
|
||||
for idx, chunk in enumerate(chunks, start=1):
|
||||
chunk_payload = {
|
||||
"chat_id": TELEGRAM_CHAT_ID,
|
||||
"text": chunk,
|
||||
"parse_mode": "Markdown",
|
||||
}
|
||||
response = requests.post(url, json=chunk_payload, timeout=30)
|
||||
response.raise_for_status()
|
||||
print(f"[{now.strftime('%Y-%m-%d %H:%M:%S')}] Mensagem enviada em {len(chunks)} parte(s).")
|
||||
except Exception as e:
|
||||
print(f"[{now.strftime('%Y-%m-%d %H:%M:%S')}] Erro ao enviar mensagem: {e}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user