BOT do Telegram responsável por gerar relatórios gerenciais do sistema Industry Care
Configuração do Webhook
Deploy: Heroku User Guide: https://devcenter.heroku.com/articles/getting-started-with-python
Setup:
- Run the folowing command from your terminal
$ sudo snap install heroku --classic
- Use the heroku login command to log in to the Heroku CLI:
$ heroku login
- Access local git repository by terminal create the app on Heroku
$ cd botservice $ heroku create --buildpack heroku/python
- Deploy your code
$ git push heroku main
- Use a Procfile, a text file in the root directory of your application, to explicitly declare what command should be executed to start your app. (https://devcenter.heroku.com/articles/http-routing)
$ web: gunicorn botservice.wsgi
- To scale the app, use the following command. When 1 is seted, at least one istance of the app will run. Set 0 to stop to serve requests
$ heroku ps:scale web=1
- Now visit the app at the URL generated by its app name
$ heroku open
- View information about your running app using one of the logging commands (https://devcenter.heroku.com/articles/logging)
$ heroku logs --tail To stop streaming logs $ Ctrl+C
- To avaible local assets to Django app
$ python manage.py collectstatic --noinput
- Runing local server
$ heroku local web To stop running $ Ctrl+C
- Start a Heroku Shell Console
$ heroku run python manage.py shell
- Start a Heroku Bash Console
$ heroku run bash
- Use the heroku pg:psql command to connect to the remote database and see all the rows
$ heroku pg:psql
- ERROR: Could not find a version that satisfies the requirement pkg-resources==0.0.0
$ pip uninstall pkg-resources==0.0.0 $ git add requirements.txt $ git commit $ git push $ git push heroku main
SETUP Webhook
Open the link bellow to receive message updates on browser
https://api.telegram.org/bot1672805913:AAE7_7ec26ZyAccPC8yh2KQ_-3qoFbSR-xg/getUpdates
Unzip to uninstall: unzip /path/to/ngrok.zip (ideal colocar na pasta raiz do software e adicioná-lo ao .gitignore) Connect your account: ./ngrok authtoken 1oWJRTXONGJINIZGyAosh8omM5Q_5yUXjAb8SYxh7KPTQwCm9 Start a HTTP Tunnel: ./ngrok http 80 (ideal abrir em um terminal fora do editor de texto)
-------------------------------------- Exemplo de interface ngrok --------------------------------------
Web Interface http://127.0.0.1:4040 Forwarding http://9876115b8c2d.ngrok.io -> http://localhost:80 Forwarding https://9876115b8c2d.ngrok.io -> http://localhost:80
A URL https deverá ser adicionada em seu Allowed Hosts (settings) sempre que for atualizada.
-------------------------------------- Exemplo de Allowed Hosts --------------------------------------
ALLOWED_HOSTS = ['industrycaretestbot.sa.ngrok.io']
Feito isto, agora é necessário setar o webhook junto a API do Telegram.
Em um navegador, digite:
https://api.telegram.org/bot{TOKEN}/setWebHook?url={URL WEBHOOK}/ Lembrando que a URL Webhook é a mesma gerada pelo ngrok e permitida em Settings.
-------------------------------------- Exemplo de Set Webhook --------------------------------------
-------------------------------------- Configuração ngrok -------------------------------------- authtoken: 1rrF09UbU592XHgoYt3gDIYkke2_3M3zBWqXNNLqRqzSmz7VS region: sa
tunnels: testbot: proto: http hostname: industrycaretestbot.sa.ngrok.io addr: 127.0.0.1:8500 inspect: true