Created
June 18, 2018 21:11
-
-
Save TiagoDanin/4ca7ab5fd5abbe033fe728279ca847dd to your computer and use it in GitHub Desktop.
Exemplo de um Echo Bot usando Webhook. LIB: Telepot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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