class Questions(StatesGroup):
Q1 = State()
Q2 = State()
Q3 = State()
Q4 = State()
Q5 = State()
Q6 = State()
Q7 = State()
Q8 = State()
@dp.message_handler(commands=['start'])
async def start(message: types.Message):
await bot.send_message(message.chat.id, """
Welcome! \n
Enter comand '/chatid'.\n
After this - send your name, surname, chatid,
time for talk with bot and email to your manager.\n
Example: "John Doe; 756440856l; 20:00; John_Doe@gmail.com"
""")
@dp.message_handler(commands=['help'])
async def help(message: types.Message):
await bot.send_message(message.chat.id, """
Hello! \n
Enter comand '/chatid'.\n
After this - send your name, surname, chatid,
time for talk with bot and email to your manager.\n
Example: "John Doe; 756440856l; 20:00; John_Doe@gmail.com"
""")
@dp.message_handler(commands=['chatid'])
async def chat_id(message: types.Message):
await bot.send_message(message.chat.id, f'Your chat_id - {message.chat.id}')
async def sterka():
with open('proshli.txt', 'w', encoding='utf-8') as f:
f.write(f"\n")
async def opros():
agcm = gspread_asyncio.AsyncioGspreadClientManager(get_creds)
employers = await get_employers(agcm)
print('start')
proshli = []
for element in range(len(employers)):
hour = employers[element][2].split(':')[0]
print(datetime.now())
if len(hour.strip()) > 0:
if len(hour) < 2:
hour = f"0{hour}"
users_chat_id = employers[element][1]
name = employers[element][0]
last_time = (employers[element][3]).split(' ')[0]
current_date = datetime.now().strftime("%d.%m.%Y")
if datetime.now().strftime("%H") == hour and datetime.today().weekday() not in (5,6):
print('run')
try:
await bot.send_message(users_chat_id, f'Hi, {name}. How many calls today?')
@dp.message_handler(state='*', commands=['stop'])
@dp.message_handler(Text(equals='stop', ignore_case=True), state='*')
async def stop(message: types.Message, state: FSMContext):
await bot.send_message(str(message.chat.id), 'Bye')
current_state = await state.get_state()
await write_if_stop(agcm, message.chat.id, employers)
if current_state is None:
return
await state.finish()
except BotBlocked:
print('Bot blocked')
@dp.message_handler()
async def answer1(message: types.Message, state: FSMContext):
if await check_compleate(message.chat.id) :
print(f'принимаю ответ {message.chat.id} на первый вопрос')
await Questions.Q1.set()
async with state.proxy() as data:
data['answer1'] = message.text
await Questions.next()
await bot.send_message(message.chat.id, 'High Priority Leads')
@dp.message_handler(state=Questions.Q2)
async def answer2(message: types.Message, state: FSMContext):
if await check_compleate(message.chat.id) :
async with state.proxy() as data:
data['answer2'] = message.text
await Questions.next()
await bot.send_message(message.chat.id, 'Emails')
@dp.message_handler(state=Questions.Q3)
async def answer2(message: types.Message, state: FSMContext):
if await check_compleate(message.chat.id) :
async with state.proxy() as data:
data['answer3'] = message.text
await Questions.next()
await bot.send_message(message.chat.id, 'LI')
@dp.message_handler(state=Questions.Q4)
async def answer2(message: types.Message, state: FSMContext):
if await check_compleate(message.chat.id) :
async with state.proxy() as data:
data['answer4'] = message.text
await Questions.next()
await bot.send_message(message.chat.id, 'TG/WA/Signal msgs')
@dp.message_handler(state=Questions.Q5)
async def answer2(message: types.Message, state: FSMContext):
if await check_compleate(message.chat.id) :
async with state.proxy() as data:
data['answer5'] = message.text
await Questions.next()
await bot.send_message(message.chat.id, 'New Leads')
@dp.message_handler(state=Questions.Q6)
async def answer2(message: types.Message, state: FSMContext):
if await check_compleate(message.chat.id) :
async with state.proxy() as data:
data['answer6'] = message.text
await Questions.next()
await bot.send_message(message.chat.id, 'Biggest obstacle')
@dp.message_handler(state=Questions.Q7)
async def answer2(message: types.Message, state: FSMContext):
if await check_compleate(message.chat.id) :
async with state.proxy() as data:
data['answer7'] = message.text
await Questions.next()
await bot.send_message(message.chat.id, 'Action to resolve the obstacle')
@dp.message_handler(state=Questions.Q8)
async def answer2(message: types.Message, state: FSMContext):
if await check_compleate(message.chat.id) :
async with state.proxy() as data:
data['answer8'] = message.text
await state.finish()
await bot.send_message(message.chat.id, 'Thanks!')
calls = data['answer1']
High_Priority_Leads = data['answer2']
Emails = data['answer3']
LI = data['answer4']
TG_WA_Signal_msgs = data['answer5']
New_Leads = data['answer6']
Biggest_obstacle = data['answer7']
Action_to_resolve_the_obstacle = data['answer8']
chat_id = str(message.chat.id)
await write_data(agcm, chat_id, employers, calls, High_Priority_Leads, Emails, LI,
TG_WA_Signal_msgs, New_Leads, Biggest_obstacle, Action_to_resolve_the_obstacle)
with open('proshli.txt', 'a', encoding='utf-8') as f:
f.write(f"{message.chat.id}\n")
async def scheduler():
aioschedule.every().day.at("00:01").do(opros)
aioschedule.every().day.at("01:01").do(opros)
aioschedule.every().day.at("02:01").do(opros)
aioschedule.every().day.at("03:01").do(opros)
aioschedule.every().day.at("04:01").do(opros)
aioschedule.every().day.at("05:01").do(opros)
aioschedule.every().day.at("06:01").do(opros)
aioschedule.every().day.at("07:01").do(opros)
aioschedule.every().day.at("08:01").do(opros)
aioschedule.every().day.at("09:01").do(opros)
aioschedule.every().day.at("10:01").do(opros)
aioschedule.every().day.at("11:01").do(opros)
aioschedule.every().day.at("12:01").do(opros)
aioschedule.every().day.at("13:01").do(opros)
aioschedule.every().day.at("14:03").do(opros)
aioschedule.every().day.at("14:05").do(opros)
aioschedule.every().day.at("15:01").do(opros)
aioschedule.every().day.at("16:01").do(opros)
aioschedule.every().day.at("17:01").do(opros)
aioschedule.every().day.at("18:01").do(opros)
aioschedule.every().day.at("19:01").do(opros)
aioschedule.every().day.at("20:01").do(opros)
aioschedule.every().day.at("21:01").do(opros)
aioschedule.every().day.at("22:01").do(opros)
aioschedule.every().day.at("23:01").do(opros)
aioschedule.every().day.at("23:58").do(sterka)
while True:
await aioschedule.run_pending()
await asyncio.sleep(1)
async def on_startup(_):
await bot.delete_webhook()
await bot.set_webhook(
url = WEBHOOK_URL,
certificate = SSL_CERTIFICATE
)
asyncio.create_task(scheduler())
if __name__ == '__main__':
start_webhook(
dispatcher =dp,
webhook_path = WEBHOOK_PATH,
on_startup=on_startup,
host = WEBAPP_HOST,
port = WEBAPP_PORT,
ssl_context=sll_context)
if datetime.now().strftime("%H") == hour and datetime.today().weekday() not in (5,6):
try:
await bot.send_message(users_chat_id, f'Hi, {name}. How many calls today?')
@dp.message_handler(state='*', commands=['stop'])
@dp.message_handler(Text(equals='stop', ignore_case=True), state='*')
async def stop(message: types.Message, state: FSMContext):
await bot.send_message(str(message.chat.id), 'Bye')
current_state = await state.get_state()
await write_if_stop(agcm, message.chat.id, employers)
if current_state is None:
return
await state.finish()
except BotBlocked:
print('Bot blocked')
@dp.message_handler()
async def answer1(message: types.Message, state: FSMContext):
if await check_compleate(message.chat.id) :
print(f'принимаю ответ {message.chat.id} на первый вопрос')
await Questions.Q1.set()
async with state.proxy() as data:
data['answer1'] = message.text
await Questions.next()
await bot.send_message(message.chat.id, 'High Priority Leads')
@dp.message_handler(state=Questions.Q2)
async def answer2(message: types.Message, state: FSMContext):
if await check_compleate(message.chat.id) :
async with state.proxy() as data:
data['answer2'] = message.text
await Questions.next()
await bot.send_message(message.chat.id, 'Emails')
@dp.message_handler(state=Questions.Q3)
async def answer2(message: types.Message, state: FSMContext):
if await check_compleate(message.chat.id) :
async with state.proxy() as data:
data['answer3'] = message.text
await Questions.next()
await bot.send_message(message.chat.id, 'LI')
aioschedule.every().day.at("00:01").do(opros)
aioschedule.every().day.at("01:01").do(opros)
aioschedule.every().day.at("02:01").do(opros)
aioschedule.every().day.at("03:01").do(opros)
aioschedule.every().day.at("04:01").do(opros)
aioschedule.every().day.at("05:01").do(opros)
aioschedule.every().day.at("06:01").do(opros)
aioschedule.every().day.at("07:01").do(opros)
aioschedule.every().day.at("08:01").do(opros)
aioschedule.every().day.at("09:01").do(opros)
aioschedule.every().day.at("10:01").do(opros)
aioschedule.every().day.at("11:01").do(opros)
aioschedule.every().day.at("12:01").do(opros)
aioschedule.every().day.at("13:01").do(opros)
aioschedule.every().day.at("14:01").do(opros)
aioschedule.every().day.at("15:01").do(opros)
aioschedule.every().day.at("16:01").do(opros)
aioschedule.every().day.at("17:01").do(opros)
aioschedule.every().day.at("18:01").do(opros)
aioschedule.every().day.at("19:01").do(opros)
aioschedule.every().day.at("20:01").do(opros)
aioschedule.every().day.at("21:01").do(opros)
aioschedule.every().day.at("22:01").do(opros)
aioschedule.every().day.at("23:01").do(opros)