Update app.py
Browse files
app.py
CHANGED
@@ -96,6 +96,63 @@ app = flask.Flask(__name__, template_folder="./")
|
|
96 |
app.config['DEBUG'] = True
|
97 |
|
98 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
# Функция сохранения в базу пользователей TG
|
100 |
def save_user(chat_id, db_name="your_database.db"):
|
101 |
conn = sqlite3.connect(db_name)
|
|
|
96 |
app.config['DEBUG'] = True
|
97 |
|
98 |
|
99 |
+
|
100 |
+
|
101 |
+
|
102 |
+
|
103 |
+
|
104 |
+
|
105 |
+
# Прямо здесь передаем данные
|
106 |
+
bot_token = 'YOUR_BOT_TOKEN'
|
107 |
+
bot_user_name = 'YOUR_BOT_USER_NAME'
|
108 |
+
URL = 'YOUR_WEBHOOK_URL'
|
109 |
+
|
110 |
+
bot = telegram.Bot(token=bot_token)
|
111 |
+
|
112 |
+
|
113 |
+
|
114 |
+
@app.route('/{}'.format(bot_token), methods=['POST'])
|
115 |
+
def respond():
|
116 |
+
update = telegram.Update.de_json(request.get_json(force=True), bot)
|
117 |
+
|
118 |
+
chat_id = update.message.chat.id
|
119 |
+
msg_id = update.message.message_id
|
120 |
+
|
121 |
+
text = update.message.text.encode('utf-8').decode()
|
122 |
+
|
123 |
+
response = 'Your response' # Замени на свою логику для ответа
|
124 |
+
bot.sendMessage(chat_id=chat_id, text=response, reply_to_message_id=msg_id)
|
125 |
+
|
126 |
+
return 'ok'
|
127 |
+
|
128 |
+
@app.route('/set_webhook', methods=['GET', 'POST'])
|
129 |
+
def set_webhook():
|
130 |
+
s = bot.setWebhook('{URL}{HOOK}'.format(URL=URL, HOOK=bot_token))
|
131 |
+
if s:
|
132 |
+
return "webhook setup ok"
|
133 |
+
else:
|
134 |
+
return "webhook setup failed"
|
135 |
+
|
136 |
+
@app.route('/')
|
137 |
+
def index():
|
138 |
+
return '.'
|
139 |
+
|
140 |
+
|
141 |
+
|
142 |
+
|
143 |
+
|
144 |
+
|
145 |
+
|
146 |
+
|
147 |
+
|
148 |
+
|
149 |
+
|
150 |
+
|
151 |
+
|
152 |
+
|
153 |
+
|
154 |
+
|
155 |
+
|
156 |
# Функция сохранения в базу пользователей TG
|
157 |
def save_user(chat_id, db_name="your_database.db"):
|
158 |
conn = sqlite3.connect(db_name)
|