Skip to content

Instantly share code, notes, and snippets.

@TiagoDanin
Created June 18, 2018 21:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TiagoDanin/4ca7ab5fd5abbe033fe728279ca847dd to your computer and use it in GitHub Desktop.
Save TiagoDanin/4ca7ab5fd5abbe033fe728279ca847dd to your computer and use it in GitHub Desktop.
Exemplo de um Echo Bot usando Webhook. LIB: Telepot
import telepot
from telepot.loop import OrderedWebhook
from flask import Flask, request
app = Flask(__name__)
token = ''
#Test used Localtunnel
#Run: lt --port 8000 -s tergvffgs
url = 'https://tergvffgs.localtunnel.me'
url_path = '/secret-path'
port = 8000
bot = telepot.Bot(token)
@app.route(url_path, methods=['POST'])
def _():
webhook.feed(request.data)
return '{}'
def echo(msg):
bot.sendMessage(msg['chat']['id'], msg['text'])
bot.setWebhook(url + url_path)
webhook = OrderedWebhook(
bot,
{'chat': echo}
)
def main():
webhook.run_as_thread()
app.run(
host='0.0.0.0',
port=port,
debug=True
)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment