Skip to content

welerson-industrycare/bot-repo

Repository files navigation

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:

Install Heroku
  • 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

$ 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

$ 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

Errors
  • 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

https://api.telegram.org/bot1672805913:AAE7_7ec26ZyAccPC8yh2KQ_-3qoFbSR-xg/setWebHook?url=https://secret-fjord-90623.herokuapp.com/event/

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 --------------------------------------

https://api.telegram.org/bot1672805913:AAE7_7ec26ZyAccPC8yh2KQ_-3qoFbSR-xg/setWebHook?url=https://industrycaretestbot.sa.ngrok.io/event

-------------------------------------- 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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages