для передачи текста в другую функцию используйте bot.register_next_step_handler().
например этот код сначала запросит домен, после ФИО должность и номер телефона, и в итоге создаст корпоративный email с указанными параметрами
@bot.message_handler(commands=['emailcreate'])
def email_create_request_domain(message):
if message.text.lower() == 'отмена':
bot.send_message(message.from_user.id, 'На нетъ и суда нетъ')
return
send = bot.send_message(message.chat.id, 'Зьдати емейлъ\nПочтовый ящикъ:\n'
'example.ru, example1.ru, example2.ru, example3.ru, example4.ru ')
bot.register_next_step_handler(send, email_create_request_data)
def email_create_request_data(message):
global domain_uis
domain_uis = message.text.lower()
if message.text.lower() == 'отмена':
bot.send_message(message.from_user.id, 'На нетъ и суда нетъ')
return
send = bot.send_message(message.chat.id, 'Введите: ФИО должность нумеръ')
bot.register_next_step_handler(send, email_create)
def email_create(message):
first = message.text.split()[1]
last = message.text.split()[0]
middle = message.text.split()[2]
phone = message.text.split()[4]
position = message.text.split()[3]
uis_login = create_nickname(first, last, middle, 'email_create')
bot.send_message(message.chat.id, '✅ логинъ')
uis_password = create_password()
bot.send_message(message.chat.id, '✅ шифръ')
id_yc = create_email(first, last, middle, phone, position, uis_password, uis_login, domain_uis)
if 'Response' in str(id_yc):
bot.send_message(message.chat.id, '❌ емейлъ' + '\n' + id_yc)
return
else:
bot.send_message(message.chat.id, '✅ емейлъ')
bot.send_message(message.chat.id, uis_login + '@' + domain_uis + '\n' + uis_password)
# Ограничение доступа к боту по ID
@bot.message_handler(func=lambda message: message.chat.id not in users)
def some(message):
bot.send_message(message.chat.id, 'Не дозволено общаться с незнакомцами')
# Ограничение выполнение команды start
@bot.message_handler(func=lambda message: message.chat.id not in users, commands=['start'])
def some(message):
bot.send_message(message.chat.id, 'Не дозволено')
# Ограничение выполнение команд
@bot.message_handler(func=lambda message: message.chat.id not in users_command,
commands=['command1', 'command2', 'command3', 'command4'])
def some(message):
bot.send_message(message.chat.id, 'Не дозволено')
@bot.message_handler(commands=['emailcreate'])
def email_create_request_domain(message):
if message.text.lower() == 'отмена':
bot.send_message(message.from_user.id, 'На нетъ и суда нетъ')
return
send = bot.send_message(message.chat.id, 'Зьдати емейлъ\nПочтовый ящикъ:\n'
'example.ru, example1.ru, example2.ru, example3.ru, example4.ru ')
bot.register_next_step_handler(send, email_create_request_data)
def email_create_request_data(message):
global domain_uis
domain_uis = message.text.lower()
if message.text.lower() == 'отмена':
bot.send_message(message.from_user.id, 'На нетъ и суда нетъ')
return
send = bot.send_message(message.chat.id, 'Введите: ФИО должность нумеръ')
bot.register_next_step_handler(send, email_create)
def email_create(message):
first = message.text.split()[1]
last = message.text.split()[0]
middle = message.text.split()[2]
phone = message.text.split()[4]
position = message.text.split()[3]
uis_login = create_nickname(first, last, middle, 'email_create')
bot.send_message(message.chat.id, '✅ логинъ')
uis_password = create_password()
bot.send_message(message.chat.id, '✅ шифръ')
id_yc = create_email(first, last, middle, phone, position, uis_password, uis_login, domain_uis)
if 'Response' in str(id_yc):
bot.send_message(message.chat.id, '❌ емейлъ' + '\n' + id_yc)
return
else:
bot.send_message(message.chat.id, '✅ емейлъ')
bot.send_message(message.chat.id, uis_login + '@' + domain_uis + '\n' + uis_password)
from pyrogram import Client
app = Client(
session_name="pyro",
proxy=dict(
hostname="",
port=1080,
username="",
password=""),
api_id='',
api_hash='')
app.start()
app.send_message(chat_id=1, text='Hi, Pavel')
@bot.message_handler(commands=['start'])
def cmd_start(message):
start_keyboard = types.InlineKeyboardMarkup()
start_service = types.InlineKeyboardButton(text='Службы', callback_data='service')
start_system = types.InlineKeyboardButton(text='Система', callback_data='system')
start_check = types.InlineKeyboardButton(text='Чек', callback_data='check')
start_other = types.InlineKeyboardButton(text='Другое', callback_data='other')
start_keyboard.add(start_service, start_system)
start_keyboard.add(start_check, start_other)
bot.send_message(message.chat.id, '', reply_markup=start_keyboard)
start = telebot.types.ReplyKeyboardMarkup(True, False)
start.row('Wunderlist')
start.row('Telegraph')
start.row('Погода')
start.row('Контакты')
bot.send_message(message.from_user.id, 'Выбери сервис', reply_markup=start)
def send_responsible(tlgrm_id_responsible, title, director, d_line, id_task, t_url):
msg = {'chat_id': tlgrm_id_responsible,
'text': ' ' + title + '\n\n' + '✍ ' + director + '\n' + '⏰ ' + d_line + '\n' + ' '
+ '[Задача № ' + id_task + ']' + '(' + t_url + ')', 'parse_mode': 'Markdown'}
requests.post(const.tlgrm_url, data=msg, proxies=const.proxy)
<a href="URL">...</a>
def log(message):
print("<!------!>")
print(datetime.now())
print("Сообщение от {0} {1} (id = {2}) \n {3}".format(message.from_user.first_name,
message.from_user.last_name,
str(message.from_user.id), message.text))
@bot.message_handler(commands=['create'])
def cmd_create(message):
send = bot.send_message(message.chat.id, 'Введи название задачи')
bot.register_next_step_handler(send, create)
log(message)
@bot.message_handler(commands=['start'])
def cmd_start(message):
start_keyboard = types.InlineKeyboardMarkup()
start_service = types.InlineKeyboardButton(text='Службы', callback_data='service')
start_system = types.InlineKeyboardButton(text='Система', callback_data='system')
start_check = types.InlineKeyboardButton(text='Чек', callback_data='check')
start_other = types.InlineKeyboardButton(text='Другое', callback_data='other')
start_keyboard.add(start_service, start_system)
start_keyboard.add(start_check, start_other)
bot.send_message(message.chat.id, '', reply_markup=start_keyboard)
start = telebot.types.ReplyKeyboardMarkup(True, False)
start.row('Wunderlist')
start.row('Telegraph')
start.row('Погода')
start.row('Контакты')
bot.send_message(message.from_user.id, 'Выбери сервис', reply_markup=start)
import telebot
from telebot import apihelper
bot = telebot.TeleBot(TOKEN)
apihelper.proxy = {'https': 'socks5h://user:password@IP:1080'}
If you want to use socket5 proxy you need install dependency pip install requests[socks] and make sure, that you have the latest version of gunicorn, PySocks, pyTelegramBotAPI, requests and urllib3
@bot.message_handler(commands=['subscribe'])
def send_welcome(message):
global sub
sub = [line.rstrip('\n') for line in open(subscribefile, 'rt')]
if str(message.text) not in sub:
with open(subscribefile, 'a') as f:
f.write(str(message.text) + "\n")
sub = [line.rstrip('\n') for line in open(subscribefile, 'rt')]
bot.send_message(message.chat.id, "чат айди записан")
@bot.message_handler(content_types=['document'])
def handle_file(message):
try:
chat_id = message.chat.id
file_info = bot.get_file(message.document.file_id)
downloaded_file = bot.download_file(file_info.file_path)
src = 'C:/Python/Project/tg_bot/files/received/' + message.document.file_name;
with open(src, 'wb') as new_file:
new_file.write(downloaded_file)
bot.reply_to(message, "Пожалуй, я сохраню это")
except Exception as e:
bot.reply_to(message, e
@bot.message_handler(commands=['start'])
def cmd_start(message):
start_keyboard = types.InlineKeyboardMarkup()
start_service = types.InlineKeyboardButton(text='Службы', callback_data='service')
start_other = types.InlineKeyboardButton(text='Другое', callback_data='other')
start_keyboard.add(start_service, start_other)
bot.send_message(message.chat.id, 'принята команда /start', reply_markup=start_keyboard)
if call.data == 'other':
service_keyboard = types.InlineKeyboardMarkup()
service_comproxy_k = types.InlineKeyboardButton(text='Comproxy', callback_data='comproxy')
service_back_k = types.InlineKeyboardButton(text='Назад', callback_data='back')
service_keyboard.add(service_comproxy_k, service_back_k)
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text='Выберите:',
reply_markup=service_keyboard)