-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
69 lines (60 loc) · 2.06 KB
/
app.py
File metadata and controls
69 lines (60 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
from bailey import Bailey
import logging
import os
from dotenv import load_dotenv
from messageHandler import handle_text_message, handle_attachment, handle_text_command
# Load environment variables
load_dotenv()
# Logging setup
logging.basicConfig(
format='%(asctime)s - %(levelname)s - %(message)s',
level=logging.INFO,
handlers=[logging.FileHandler("bot.log"), logging.StreamHandler()]
)
# Initialize WhatsApp bot
bot = Bailey(
port=int(os.getenv("PORT", 8000)),
host=os.getenv("HOST", "0.0.0.0"),
debug=os.getenv("DEBUG", "True") == "True"
)
logging.info("KORA AI WhatsApp Bot is now running...")
# Handle text messages
@bot.event
def on_message(message):
if message.type == "text":
logging.info(f"Received message from {message.chat_id}: {message.text}")
response = handle_text_message(message.text, [])
message.reply(response)
elif message.type in ["image", "file"]:
media_url = message.media_url
file_extension = message.file_extension
message_type = message.type
response = handle_attachment(media_url, message_type, file_extension)
message.reply(response)
# Handle commands using buttons (you'll customize CMD functions later)
@bot.command
def cmd_handler(command, args):
logging.info(f"Received command: /{command} {args}")
response = handle_text_command(command, args)
return response
# Example buttons
@bot.command
def menu():
buttons = [
{"id": "button1", "title": "📚 Get Info"},
{"id": "button2", "title": "📊 Stats"},
{"id": "button3", "title": "💡 Tips"}
]
return {"text": "Select an option:", "buttons": buttons}
@bot.button_handler
def on_button_click(button_id):
if button_id == "button1":
return "Here’s some information for you 📚."
elif button_id == "button2":
return "Here are your stats 📊."
elif button_id == "button3":
return "Here’s a useful tip 💡."
# Start the bot
if __name__ == "__main__":
logging.info("KORA AI Bot is ready. Scan the QR code to activate.")
bot.run()