Skip to content

Commit d84aa79

Browse files
author
Dmitry
committed
Add files via upload
1 parent 747f142 commit d84aa79

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import telebot
2+
import os
3+
from flask import Flask, request
4+
5+
bot = telebot.TeleBot('token')
6+
7+
server = Flask(__name__)
8+
9+
@bot.message_handler(commands=['start'])
10+
def start(message):
11+
bot.reply_to(message, 'Hello, ' + message.from_user.first_name)
12+
13+
@bot.message_handler(func=lambda message: True, content_types=['text'])
14+
def echo_message(message):
15+
bot.reply_to(message, message.text)
16+
17+
@server.route("/bot", methods=['POST'])
18+
def getMessage():
19+
bot.process_new_messages(
20+
[telebot.types.Update.de_json(request.stream.read().decode("utf-8")).message
21+
])
22+
return "!", 200
23+
24+
@server.route("/")
25+
def webhook():
26+
bot.remove_webhook()
27+
bot.set_webhook(url="https://herokuProject_url/bot")
28+
return "!", 200
29+
30+
server.run(host="0.0.0.0", port=os.environ.get('PORT', 5000))
31+
32+
server = Flask(__name__)

0 commit comments

Comments
 (0)