-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.py
More file actions
executable file
·75 lines (59 loc) · 2.25 KB
/
main.py
File metadata and controls
executable file
·75 lines (59 loc) · 2.25 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import threading
import telebot
from telegram_bot_users import *
# Constants to indicate steps while user is entering password
TEAM_USER_LOGGING = 0
TEAM_USER_ACCEPTED = 1
# Data structure for list of bot`s users
team_users = TeamUserList()
# Insert your telegram bot`s token here
TOKEN = os.environ['TELEGRAM_TOKEN']
bot = telebot.TeleBot(TOKEN)
user_step = {}
user_active_dialog = {}
reply_data_db = {}
# Welcoming message
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
bot.reply_to(message, "Welcome to Support_Bot!")
# Custom command to add user to an operator`s team
@bot.message_handler(commands=['on'])
def subscribe_chat(message):
if message.chat.id in team_users:
bot.reply_to(message, "You are already an operator")
else:
user_step[message.chat.id] = TEAM_USER_LOGGING
bot.reply_to(message, "Enter team secret phrase:")
# Here we catch user message after '/on' command and
# interpret it as a password
@bot.message_handler(func=lambda message: user_step.get(message.chat.id) == TEAM_USER_LOGGING)
def team_user_login(message):
if message.text == 'password1':
team_users.add(TeamUser(message.chat.id))
user_step[message.chat.id] = TEAM_USER_ACCEPTED
bot.reply_to(message, "You`ve started receiving messages")
else:
bot.reply_to(message, "Wrong secrete phrase, try again")
# Custom command to remove user from an operator`s team
@bot.message_handler(commands=['off'])
def team_user_logout(message):
if message.chat.id not in team_users:
bot.reply_to(message, "You are not an operator anyway")
else:
team_users.remove_by_chat_id(message.chat.id)
bot.reply_to(message, "You`ve stopped receiving messages")
# Use this function when you need to send something
# to an operators team
def process(message):
text = '%s\n%s writes to %s\nReply: %s' %\
(message, 'Vasya', 'Super Support Team', '*reply_url*')
# Sending message to every operator in our list
for user in team_users:
bot.send_message(user.chat_id, text, disable_web_page_preview=True)
threading.Thread(target=bot.polling).start()
while True:
msg = input("Enter your message: ")
process(msg)