I'm kinda new in Telepot but I'm trying to learn something very basic. I am just trying to build up a pot that repeats what you just have said:
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))
TOKEN = 'xxxxxxxxxx'
secret = 'xxxxxxxxxx'
bot = telepot.Bot(TOKEN)
bot.setWebhook("https://sarfo.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:
msg = update["message"]
if "text" in update:
text = msg["text"]
chat_id = msg["chat"]["id"]
bot.sendMessage(chat_id, "You said '{}'".format(text))
return "OK"
Someone try to send a sticker and now telegram keeps sending error messages ( KeyError: 'text' ), I thought that the ' if "text" in update ' was enough. How can I resolve this? How can I avoid this flow of errors in the future with something like try and except?
[edited by admin: formatting]