Sorry if this is a stupid question, but every other forum discussing this had a different code from mine. I copied the text from the pythonanywhere tutorial: https://blog.pythonanywhere.com/148/. Here is the code:
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"
bot = telepot.Bot('token')
bot.setWebhook("https://username.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:
chat_id = update["message"]["chat"]["id"]
if "text" in update["message"]:
text = update["message"]["text"]
if text == "/start":
bot.sendMessage(chat_id, "Bot starting.")
else:
bot.sendMessage(chat_id, "From the web: sorry, I didn't understand that kind of message")
return "OK"
This code works well, but I don't know how to correctly add KeyboardButtons to this code, can someone please help?