mirror of
https://github.com/eternnoir/pyTelegramBotAPI.git
synced 2023-08-10 21:12:57 +03:00
7957bc45a8
Rename telebot package to pytelegrambotapi becouse lib named telebot exists and it raising many errors Add methods: | register_for_reply_by_message_id, | register_next_step_handler_by_chat_id, | clear_reply_handlers, | clear_reply_handlers_by_message_id
36 lines
903 B
Python
36 lines
903 B
Python
import os
|
|
|
|
import pytelegrambotapi
|
|
from flask import Flask, request
|
|
|
|
TOKEN = '<api_token>'
|
|
bot = pytelegrambotapi.TeleBot(TOKEN)
|
|
server = Flask(__name__)
|
|
|
|
|
|
@bot.message_handler(commands=['start'])
|
|
def start(message):
|
|
bot.reply_to(message, 'Hello, ' + message.from_user.first_name)
|
|
|
|
|
|
@bot.message_handler(func=lambda message: True, content_types=['text'])
|
|
def echo_message(message):
|
|
bot.reply_to(message, message.text)
|
|
|
|
|
|
@server.route('/' + TOKEN, methods=['POST'])
|
|
def getMessage():
|
|
bot.process_new_updates([pytelegrambotapi.types.Update.de_json(request.stream.read().decode("utf-8"))])
|
|
return "!", 200
|
|
|
|
|
|
@server.route("/")
|
|
def webhook():
|
|
bot.remove_webhook()
|
|
bot.set_webhook(url='https://your_heroku_project.com/' + TOKEN)
|
|
return "!", 200
|
|
|
|
|
|
if __name__ == "__main__":
|
|
server.run(host="0.0.0.0", port=int(os.environ.get('PORT', 5000)))
|