MAYIBOT / main.py
ZIPITN's picture
Update main.py
20d9d56 verified
Raw History Blame Contribute Delete
5.8 kB
import os, json, time
import requests
from groq import Groq
from telegram import Update
from telegram.ext import Application, CommandHandler, MessageHandler, filters, ContextTypes
BOT_TOKEN = os.environ.get("BOT_TOKEN")
GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
OWNER_ID = os.environ.get("OWNER_ID")
STATE_FILE = "maya_memory.json"
PRICE = 300
DEMO_LINK = "https://3d-rho-puce.vercel.app/"
CBE_ACCOUNT = "1000335488807"
client = Groq(api_key=GROQ_API_KEY)
def load_memory():
if os.path.exists(STATE_FILE):
with open(STATE_FILE, "r") as f: return json.load(f)
return {"leads": [], "sent_count": 0, "revenue": 0}
def save_memory(data):
with open(STATE_FILE, "w") as f: json.dump(data, f, indent=2)
memory = load_memory()
def ask_maya(prompt, system_prompt="You are MAYA, a sharp, professional sales agent. Keep replies under 3 sentences. No emojis unless asked. Act like a real business partner. You are in MANUAL DRAFT MODE."):
try:
response = client.chat.completions.create(
model="llama-3.3-70b-versatile",
messages=[{"role": "system", "content": system_prompt}, {"role": "user", "content": prompt}],
temperature=0.7, max_tokens=500
)
return response.choices[0].message.content.strip()
except Exception as e: return f"⚠️ AI Error: {str(e)}"
async def start_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text("👋 *MAYA is online and ready, Boss.*\n\n⚡ *Commands:*\n• `/draft email@domain.com`\n• `/add Name email@domain.com`\n• `/leads`\n• `/stats`\n• `/help`", parse_mode='Markdown')
async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text("📚 *MAYA COMMANDS*\n📧 `/draft email@domain.com`\n➕ `/add Name email@domain.com`\n📋 `/leads`\n📊 `/stats`\n🧹 `/reset`", parse_mode='Markdown')
async def add_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
global memory
args = context.args
if len(args) >= 2 and "@" in args[1]:
memory["leads"].append({"name": args[0], "email": args[1], "score": 5})
save_memory(memory)
await update.message.reply_text(f"✅ Saved: *{args[0]}* ({args[1]})", parse_mode='Markdown')
else:
await update.message.reply_text("Format: `/add Name email@domain.com`", parse_mode='Markdown')
async def leads_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
if not memory["leads"]:
await update.message.reply_text("📭 No leads saved yet.", parse_mode='Markdown')
else:
msg = "📋 *SAVED LEADS:*\n\n" + "\n".join([f"{i}. *{l['name']}* - `{l['email']}`" for i, l in enumerate(memory["leads"][-10:], 1)])
await update.message.reply_text(msg, parse_mode='Markdown')
async def draft_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
global memory
if not context.args:
await update.message.reply_text("⚠️ Please provide an email.\n*Example:* `/draft john@example.com`", parse_mode='Markdown')
return
email_target = context.args[0]
lead = next((l for l in memory["leads"] if l["email"].lower() == email_target.lower()), None)
if not lead:
await update.message.reply_text(f"⚠️ `{email_target}` not in memory. Add them first: `/add Name {email_target}`", parse_mode='Markdown')
return
await update.message.reply_text(f"🧠 *Drafting for {lead['name']}...*", parse_mode='Markdown')
prompt = f"Write a short cold email to {lead['name']} at {lead['email']}. Sell: Tour website template for ${PRICE}. Demo: {DEMO_LINK}. Payment: CBE {CBE_ACCOUNT}. Tone: Confident, warm, concise. Max 100 words. No emojis. Format exactly as:\nTO: {lead['email']}\nSUBJECT: [catchy subject]\nBODY:\n[email body, sign off as Mika]"
draft = ask_maya(prompt)
await update.message.reply_text(f"✉️ *DRAFT READY*\n\n`{draft}`\n\n💡 *Copy and paste this into your email app!*", parse_mode='Markdown')
async def stats_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text(f"📊 *MAYA STATS*\n• Leads: {len(memory['leads'])}\n• Sent: {memory['sent_count']}\n• Revenue: ${memory['revenue']}\n• Goal: $100", parse_mode='Markdown')
async def reset_command(update: Update, context: ContextTypes.DEFAULT_TYPE):
global memory
memory["sent_count"] = 0
save_memory(memory)
await update.message.reply_text("🧹 Daily counters reset.")
async def message_handler(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.reply_text("🧠 *Thinking...*", parse_mode='Markdown')
response = ask_maya(f"User said: '{update.message.text}'. Context: Leads: {len(memory['leads'])}, Revenue: ${memory['revenue']}. Reply helpfully as MAYA.")
await update.message.reply_text(response)
def main():
print("🚀 MAYA is waking up on Hugging Face...")
app = Application.builder().token(BOT_TOKEN).build()
app.add_handler(CommandHandler("start", start_command))
app.add_handler(CommandHandler("help", help_command))
app.add_handler(CommandHandler("add", add_command))
app.add_handler(CommandHandler("leads", leads_command))
app.add_handler(CommandHandler("draft", draft_command))
app.add_handler(CommandHandler("stats", stats_command))
app.add_handler(CommandHandler("reset", reset_command))
app.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, message_handler))
print("✅ MAYA is live! Open Telegram and type /start")
app.run_polling()
if __name__ == "__main__":
main()