-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
167 lines (137 loc) Β· 5.76 KB
/
bot.py
File metadata and controls
167 lines (137 loc) Β· 5.76 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
from telegram import Update, ReplyKeyboardMarkup
from telegram.constants import ChatAction
from telegram.ext import (
ApplicationBuilder, ContextTypes, CommandHandler,
MessageHandler, filters, ConversationHandler
)
import os
TOKEN = os.getenv("BOT_TOKEN")
ADMIN_CHAT_ID = int(os.getenv("ADMIN_CHAT_ID"))
# Replace with your Telegram user ID
# === STATES ===
CHOOSE_SERVICE, SCHEDULE_SESSION, AWAIT_PAYMENT_DETAILS = range(3)
# === SERVICES ===
services = [
["π Makeup Session - β¦20,000", "πΈ Studio Photography - β¦40,000"],
["π Both (Makeup + Photo) - β¦60,000"]
]
deposit_percent = 0.25
# === TEMP DATA STORE ===
user_bookings = {}
# === /start ===
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.chat.send_action(ChatAction.TYPING)
await update.message.reply_text(
"β¨ Welcome to *Precys_Glow* β where beauty meets perfection! β¨\n\n"
"Please choose a service to get started:",
reply_markup=ReplyKeyboardMarkup(services, resize_keyboard=True),
parse_mode="Markdown"
)
return CHOOSE_SERVICE
# === CHOOSE SERVICE ===
async def choose_service(update: Update, context: ContextTypes.DEFAULT_TYPE):
await update.message.chat.send_action(ChatAction.TYPING)
selected = update.message.text
if "β¦" not in selected:
await update.message.reply_text("β Please select a valid service from the options.")
return CHOOSE_SERVICE
try:
price_text = selected.split(" - β¦")[-1].replace(',', '')
price = int(price_text)
except ValueError:
await update.message.reply_text("β Could not extract price. Please choose a valid service.")
return CHOOSE_SERVICE
deposit = int(price * deposit_percent)
context.user_data.update({
"service": selected,
"price": price,
"deposit": deposit
})
await update.message.reply_text(
f"Great choice! π₯° You've selected: {selected}\n\n"
f"The full price is β¦{price:,}.\n"
f"To confirm your booking, please pay a 25% deposit of β¦{deposit:,}.\n\n"
"Now, please tell us your preferred *date and time* for the session.\n"
"_Example: 25th July, 2 PM_",
parse_mode="Markdown"
)
return SCHEDULE_SESSION
# === SCHEDULE SESSION ===
async def schedule_session(update: Update, context: ContextTypes.DEFAULT_TYPE):
context.user_data["schedule"] = update.message.text
account_details = (
"π³ *Payment Details:*\n"
"`Account Name:` PRECIOS UZOMA OBI\n"
"`Account Number:` 7052184296\n"
"`Bank:` OPAY\n\n"
"Please transfer the deposit and then reply with the *Account Name used* and *Amount Paid*.\n\n"
"_Example: Jane Doe, β¦5,000_"
)
await update.message.reply_text(account_details, parse_mode="Markdown")
return AWAIT_PAYMENT_DETAILS
# === AWAIT PAYMENT DETAILS ===
async def receive_payment_details(update: Update, context: ContextTypes.DEFAULT_TYPE):
user = update.effective_user
context.user_data["payment_details"] = update.message.text
user_bookings[user.id] = context.user_data.copy()
await update.message.reply_text("β³ *Give us a moment...*", parse_mode="Markdown")
await context.bot.send_message(
chat_id=ADMIN_CHAT_ID,
text=(
f"π© *New Booking Pending Confirmation*\n\n"
f"π€ Name: {user.full_name}\n"
f"π User ID: `{user.id}`\n"
f"πΌ Service: {context.user_data['service']}\n"
f"π
Schedule: {context.user_data['schedule']}\n"
f"π΅ Deposit Expected: β¦{context.user_data['deposit']:,}\n"
f"π₯ Payment Info Provided: {context.user_data['payment_details']}\n\n"
f"β
*To confirm, reply with:* `/confirm {user.id}`"
),
parse_mode="Markdown"
)
await update.message.reply_text(
"β
Thank you! Your booking request has been received.\n"
"We'll confirm once your payment is verified. π"
)
return ConversationHandler.END
# === ADMIN CONFIRMATION ===
async def confirm_booking(update: Update, context: ContextTypes.DEFAULT_TYPE):
if update.effective_user.id != ADMIN_CHAT_ID:
await update.message.reply_text("β You are not authorized to confirm bookings.")
return
if len(context.args) != 1 or not context.args[0].isdigit():
await update.message.reply_text("β οΈ Usage: /confirm <user_id>")
return
user_id = int(context.args[0])
booking = user_bookings.get(user_id)
if not booking:
await update.message.reply_text("β Booking not found for that user ID.")
return
await context.bot.send_message(
chat_id=user_id,
text=(
"π *Your booking has been successfully confirmed!*\n\n"
"We look forward to serving you at *Precys_Glow Beauty Hub*.\n"
"Please be punctual for your scheduled session. ππΈ",
),
parse_mode="Markdown"
)
await update.message.reply_text(f"β
Booking confirmed for user ID: {user_id}")
# === HANDLERS SETUP ===
def main():
app = ApplicationBuilder().token(TOKEN).build()
conv_handler = ConversationHandler(
entry_points=[CommandHandler("start", start)],
states={
CHOOSE_SERVICE: [MessageHandler(filters.TEXT & ~filters.COMMAND, choose_service)],
SCHEDULE_SESSION: [MessageHandler(filters.TEXT & ~filters.COMMAND, schedule_session)],
AWAIT_PAYMENT_DETAILS: [MessageHandler(filters.TEXT & ~filters.COMMAND, receive_payment_details)],
},
fallbacks=[]
)
app.add_handler(conv_handler)
app.add_handler(CommandHandler("confirm", confirm_booking))
print("π€ Bot is running...")
app.run_polling()
if __name__ == "__main__":
main()