https://api.telegram.org/bot<token>/setWebhook?url=http://username.pythonanywhere.com/
import telebot
from flask import Flask
import config
token = config.token
bot = telebot.TeleBot(token)
app = Flask(__name__)
@app.route('/')
#Я ЗНАЮ ЧТО ТУТ НЕ ХВАТАЕТ, НО КАК ЭТО ДЕЛО ДОПИСАТЬ??
@bot.message_handler(commands=['start'])
def handle_start(message):
bot.send_message(message.from_user.id, 'ПРИВЕТ!')
if __name__ == '__main__':
app.run()
from flask import Flask, request
import telebot
from telebot import types
import time
secret = "GUID"
bot = telebot.TeleBot('TOKEN_TELEGRAM', threaded=False)
bot.remove_webhook()
time.sleep(1)
bot.set_webhook(url="https://YOURNAME.pythonanywhere.com/{}".format(secret))
app = Flask(__name__)
@app.route('/{}'.format(secret), methods=["POST"])
def webhook():
bot.process_new_updates([telebot.types.Update.de_json(request.stream.read().decode("utf-8"))])
print("Message")
return "ok", 200
@bot.message_handler(commands=['start', 'help'])
def startCommand(message):
bot.send_message(message.chat.id, 'Hi *' + message.chat.first_name + '*!' , parse_mode='Markdown', reply_markup=types.ReplyKeyboardRemove())
# -*- coding: utf8 -*-
from flask import Flask, request
import telepot
import urllib3
proxy_url = "http://proxy.server:3128"
telepot.api._pools = {
'default': urllib3.ProxyManager(proxy_url=proxy_url, num_pools=3, maxsize=10, retries=False, timeout=30),
}
telepot.api._onetime_pool_spec = (urllib3.ProxyManager, dict(proxy_url=proxy_url, num_pools=1, maxsize=1, retries=False, timeout=30))
secret = "SECRET_KEY"
bot = telepot.Bot(TOKEN)
bot.setWebhook("https://USER_NAME.pythonanywhere.com/{}".format(secret), max_connections=1)
app = Flask(__name__)
@app.route('/{}'.format(secret), methods=["POST"])
def telegram_webhook():
update = request.get_json()
if "message" in update:
text = update["message"]["text"]
chat_id = update["message"]["chat"]["id"]
if text == "/start":
bot.sendMessage(chat_id, 'Ты вызвал команду Тест')
else:
bot.sendMessage(chat_id, 'Ты пишешь какие то буквы')
return "OK"
update = telebot.types.Update.de_json(json_string) bot.process_new_updates([update])