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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import logging
from aiogram import Bot, Dispatcher, executor, types
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from aiogram.dispatcher import FSMContext
from aiogram.dispatcher.filters.state import State, StatesGroup
from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton, ReplyKeyboardMarkup, KeyboardButton, ContentType
# Configure logging
logging.basicConfig(level=logging.INFO)
# Initialize bot and dispatcher
API_TOKEN = "YOUR_BOT_TOKEN" # Replace with your actual bot token
PAYMENT_TOKEN = "YOUR_PAYMENT_TOKEN" # Replace with your payment provider token
bot = Bot(token=API_TOKEN)
storage = MemoryStorage()
dp = Dispatcher(bot, storage=storage)
# Define states
class BotStates(StatesGroup):
start = State()
language_selection = State()
registration_name = State()
registration_phone = State()
singer_selection = State()
singer_info = State()
payment = State()
content_access = State()
# Available languages
languages = ["English", "Spanish", "French", "German", "Russian"]
# Sample singers data
singers = {
"Taylor Swift": {
"info": "Taylor Swift is an American singer-songwriter known for narrative songs about her personal life.",
"price": 5.99,
"songs": ["Love Story", "Blank Space", "Shake It Off", "Anti-Hero", "Cruel Summer"]
},
"Ed Sheeran": {
"info": "Ed Sheeran is an English singer-songwriter known for his acoustic pop songs.",
"price": 4.99,
"songs": ["Shape of You", "Perfect", "Thinking Out Loud", "Photograph", "Castle on the Hill"]
},
"Beyoncé": {
"info": "Beyoncé is an American singer, songwriter and actress known for her powerful vocals and stage presence.",
"price": 6.99,
"songs": ["Halo", "Single Ladies", "Crazy in Love", "Formation", "Run the World (Girls)"]
},
"The Weeknd": {
"info": "The Weeknd is a Canadian singer-songwriter known for his distinctive sound and enigmatic image.",
"price": 5.49,
"songs": ["Blinding Lights", "Starboy", "The Hills", "Save Your Tears", "Die For You"]
}
}
# Start command handler
@dp.message_handler(commands=['start'], state='*')
async def cmd_start(message: types.Message):
welcome_text = "🎵 Welcome to Music Discovery Bot! 🎵\n\n" \
"This bot allows you to discover and listen to new songs from your favorite artists.\n\n" \
"Features:\n" \
"• Browse famous singers\n" \
"• Get updates on new releases\n" \
"• Listen to songs after subscription\n\n" \
"Press 'Start' to begin your musical journey!"
start_button = InlineKeyboardMarkup().add(
InlineKeyboardButton("Start", callback_data="start_registration")
)
await message.answer(welcome_text, reply_markup=start_button)
await BotStates.start.set()
# Start registration process
@dp.callback_query_handler(lambda c: c.data == "start_registration", state=BotStates.start)
async def process_start_registration(callback_query: types.CallbackQuery, state: FSMContext):
await bot.answer_callback_query(callback_query.id)
language_markup = InlineKeyboardMarkup(row_width=2)
for lang in languages:
language_markup.add(InlineKeyboardButton(lang, callback_data=f"language_{lang}"))
await bot.send_message(
callback_query.from_user.id,
"Please select your preferred language:",
reply_markup=language_markup
)
await BotStates.language_selection.set()
# Process language selection
@dp.callback_query_handler(lambda c: c.data.startswith("language_"), state=BotStates.language_selection)
async def process_language_selection(callback_query: types.CallbackQuery, state: FSMContext):
language = callback_query.data.split("_")[1]
await bot.answer_callback_query(callback_query.id)
# Save the selected language
await state.update_data(language=language)
await bot.send_message(
callback_query.from_user.id,
f"Language set to {language}. Now, please enter your full name:"
)
await BotStates.registration_name.set()
# Process name input
@dp.message_handler(state=BotStates.registration_name)
async def process_name(message: types.Message, state: FSMContext):
# Save the name
await state.update_data(full_name=message.text)
# Request phone number with a special button
keyboard = ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=True)
keyboard.add(KeyboardButton("Share Contact", request_contact=True))
await message.answer(
"Thank you! Now please share your phone number by clicking the button below:",
reply_markup=keyboard
)
await BotStates.registration_phone.set()
# Process phone number
@dp.message_handler(content_types=ContentType.CONTACT, state=BotStates.registration_phone)
async def process_phone(message: types.Message, state: FSMContext):
# Save the phone number
await state.update_data(phone=message.contact.phone_number)
# Create singer selection keyboard
singer_markup = InlineKeyboardMarkup(row_width=2)
for singer in singers.keys():
singer_markup.add(InlineKeyboardButton(singer, callback_data=f"singer_{singer}"))
await message.answer(
"Registration complete! Now, please select a singer from the list:",
reply_markup=singer_markup
)
await BotStates.singer_selection.set()
# Process singer selection
@dp.callback_query_handler(lambda c: c.data.startswith("singer_"), state=BotStates.singer_selection)
async def process_singer_selection(callback_query: types.CallbackQuery, state: FSMContext):
singer_name = callback_query.data.replace("singer_", "")
await bot.answer_callback_query(callback_query.id)
# Save the selected singer
await state.update_data(selected_singer=singer_name)
singer_info = singers[singer_name]["info"]
price = singers[singer_name]["price"]
# Create payment button
payment_button = InlineKeyboardMarkup().add(
InlineKeyboardButton(f"Subscribe for ${price:.2f}", callback_data="start_payment")
)
await bot.send_message(
callback_query.from_user.id,
f"🎤 {singer_name} 🎤\n\n{singer_info}\n\nSubscribe to access {singer_name}'s songs for ${price:.2f} per month.",
reply_markup=payment_button
)
await BotStates.singer_info.set()
# Start payment process
@dp.callback_query_handler(lambda c: c.data == "start_payment", state=BotStates.singer_info)
async def process_payment_start(callback_query: types.CallbackQuery, state: FSMContext):
await bot.answer_callback_query(callback_query.id)
# Get user data and selected singer
user_data = await state.get_data()
singer_name = user_data.get("selected_singer")
price = singers[singer_name]["price"]
# In a real application, you would use Telegram's payment API here
# For demonstration purposes, we'll simulate the payment process
await bot.send_message(
callback_query.from_user.id,
f"Redirecting to payment system for ${price:.2f} subscription to {singer_name}'s content..."
)
# Simulate payment process with a confirmation button
confirm_payment = InlineKeyboardMarkup().add(
InlineKeyboardButton("Confirm Payment (Demo)", callback_data="confirm_payment")
)
await bot.send_message(
callback_query.from_user.id,
"This is a demonstration of the payment flow. In a real application, you would be redirected to a secure payment provider.",
reply_markup=confirm_payment
)
await BotStates.payment.set()
# Process payment confirmation (demo)
@dp.callback_query_handler(lambda c: c.data == "confirm_payment", state=BotStates.payment)
async def process_payment_confirmation(callback_query: types.CallbackQuery, state: FSMContext):
await bot.answer_callback_query(callback_query.id)
# Get user data and selected singer
user_data = await state.get_data()
singer_name = user_data.get("selected_singer")
await bot.send_message(
callback_query.from_user.id,
f"🎉 Payment successful! You now have access to {singer_name}'s songs."
)
# Display available songs
songs_text = f"🎵 {singer_name}'s Songs 🎵\n\n"
for i, song in enumerate(singers[singer_name]["songs"], 1):
songs_text += f"{i}. {song}\n"
songs_text += "\nClick on a song to listen:"
# Create song selection buttons
songs_markup = InlineKeyboardMarkup(row_width=1)
for song in singers[singer_name]["songs"]:
songs_markup.add(InlineKeyboardButton(song, callback_data=f"play_{song}"))
await bot.send_message(
callback_query.from_user.id,
songs_text,
reply_markup=songs_markup
)
await BotStates.content_access.set()
# Process song selection
@dp.callback_query_handler(lambda c: c.data.startswith("play_"), state=BotStates.content_access)
async def process_song_selection(callback_query: types.CallbackQuery, state: FSMContext):
song_name = callback_query.data.replace("play_", "")
await bot.answer_callback_query(callback_query.id)
# In a real application, you would stream or provide a link to the actual song
await bot.send_message(
callback_query.from_user.id,
f"🎧 Now playing: {song_name} 🎧\n\nIn a real application, the song would start playing or a download link would be provided."
)
# Main entry point
if __name__ == '__main__':
print("Starting Music Discovery Bot...")
executor.start_polling(dp, skip_updates=True)No Output
Run the code to generate an output.