| import requests | |
| from telegram import Update | |
| from telegram.ext import ApplicationBuilder, MessageHandler, filters, ContextTypes | |
| TELEGRAM_TOKEN = "8271190956:AAEWohbxwfJGTSsoKiKHsPjpaXVTLsW4Zwk" | |
| OLLAMA_URL = "http://localhost:11434/api/generate" | |
| MODEL = "clawdbot" | |
| async def handle_message(update: Update, context: ContextTypes.DEFAULT_TYPE): | |
| user_text = update.message.text | |
| payload = { | |
| "model": MODEL, | |
| "prompt": user_text, | |
| "stream": False | |
| } | |
| try: | |
| response = requests.post(OLLAMA_URL, json=payload) | |
| data = response.json() | |
| reply = data.get("response", "Erro ao contactar o Clawdbot.") | |
| except Exception as e: | |
| reply = f"Erro interno: {e}" | |
| await update.message.reply_text(reply) | |
| def main(): | |
| app = ApplicationBuilder().token(TELEGRAM_TOKEN).build() | |
| app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, handle_message)) | |
| app.run_polling() | |
| if __name__ == "__main__": | |
| main() | |