Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
1773940
Changes requirements to rasa_core 13.x + sdk
guilacerda Apr 9, 2019
5fdf79b
Changes rasa_core imports to rasa_core_sdk
guilacerda Apr 9, 2019
528d5f9
Configures train and train telegram
guilacerda Apr 17, 2019
ce4d7b7
Moves files to action root
guilacerda Apr 17, 2019
5d6eeb5
Creates dockerfile to actions
guilacerda Apr 17, 2019
ee5ce3e
Changes Telegram conector
guilacerda Apr 17, 2019
998924a
creates start_dev script
vitorfhc Apr 18, 2019
53dbb01
Add elastic on docker
tayh Apr 23, 2019
95207c5
Add kibana on docker
tayh Apr 23, 2019
4f51aa5
Remove some comments and api key
tayh Apr 23, 2019
ac516fe
Changes Telegram conector
guilacerda Apr 17, 2019
66284f5
Redo script
vitorfhc Apr 25, 2019
ad44fd8
Remove old script
vitorfhc Apr 25, 2019
838c5df
Change README
vitorfhc Apr 25, 2019
4f3b74e
Changes dispatcher image method
guilacerda Apr 25, 2019
b520424
Create documents flow
tayh May 2, 2019
56f88f6
Add new documents flow images
tayh May 2, 2019
6f9e4d8
Create new flow tutoting proof to documents
tayh May 2, 2019
42d63e5
Add new flow to documents
tayh May 2, 2019
fe57ec5
Create tutoring proof flow
tayh May 2, 2019
74e127b
Create course period flow
tayh May 2, 2019
dba73b3
Create school history flow
tayh May 2, 2019
3234820
Merge pull request #28 from BotLino/5_kibana_elastic
guilacerda May 2, 2019
7783334
Merge pull request #29 from BotLino/3_documentos_academicos
guilacerda May 2, 2019
024b816
Changes method to send image
May 2, 2019
683034f
Rename actions.py file and fixes conflicts
guilacerda May 2, 2019
6ed66ac
Adds actions service to docker-compose
guilacerda May 2, 2019
70c5d9d
Updates facebook connector
May 7, 2019
60cc1fe
Updates readme to new era
guilacerda May 7, 2019
4094511
Corrects code style according to flake8
May 7, 2019
2fe24c3
Merge branch 'devel' of https://github.com/botlino/lino into updatesCore
guilacerda May 9, 2019
fd88216
Merge branch 'updatesCore' of https://github.com/botlino/lino into up…
guilacerda May 9, 2019
b8f8948
Removes spacy from requirements
guilacerda May 9, 2019
fafff04
Fix flake8
vitorfhc May 9, 2019
7729673
Merge pull request #25 from BotLino/updatesCore
brunapinos May 9, 2019
cb6e9ba
Merge branch 'devel' into dev-scripts
guilacerda May 14, 2019
096c2a1
Merge pull request #24 from BotLino/dev-scripts
guilacerda May 14, 2019
f1daccc
Remove all duplicated
vitorfhc May 15, 2019
caf4bf1
Add codeclimate configuration file
May 16, 2019
03316a2
Merge pull request #34 from BotLino/remove-redundant-intents
guilacerda May 16, 2019
83e5f26
Merge pull request #35 from BotLino/configCodeClimate
guilacerda May 16, 2019
5b37935
Add UnB Idiomas new interview to docs
luizguilherme5 May 16, 2019
2dffca5
Adds necessary requirements to new version of core and nlu
guilacerda May 22, 2019
f4ac104
Changes actions file addition to actions folder addition
guilacerda May 22, 2019
7cb9806
Merge pull request #40 from BotLino/20-unbidiomas-flux
guilacerda May 22, 2019
1e6a932
Merge pull request #42 from BotLino/fixesDevel
guiaugusto May 22, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: "2"

plugins:
duplication: # for duplication analysis
enabled: true
config:
languages:
python:
python_version: 3
pep8: # for code style analysis
enabled: true
config:
languages:
python:
python_version: 3
bandit: # for security analysis
enabled: true
config:
languages:
python:
python_version: 3
radon: # for complexity analysis
enabled: true
config:
languages:
python:
python_version: 3

5 changes: 2 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
FROM python:3.6

RUN pip install rasa_core==0.10.4
RUN pip install rasa_core==0.13.1

RUN pip install rasa_nlu[spacy] && \
python -m spacy download pt
RUN pip install rasa_nlu==0.14.0

RUN pip install rasa_nlu[tensorflow]

Expand Down
91 changes: 47 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
</p>
</p>

<a href="https://codeclimate.com/github/BotLino/Lino/maintainability"><img src="https://api.codeclimate.com/v1/badges/4796786426759c747eb4/maintainability" /></a>

### Sobre o projeto

<p align="justify"> &emsp;&emsp;
Expand Down Expand Up @@ -50,85 +52,86 @@ As políticas de _branches_, _commits_, _pull requests_ e _issues_ se encontram

#### Desenvolvimento

Para começar a desenvolver precisamos fazer algumas mudanças no código para que funcione localmente.
&emsp;**Dependências**
* Docker
* Docker-compose
* Ngrok

##### Setup do Telegram

Para começar a desenvolver precisamos fazer algumas alterações no código para que funcione localmente.

Todas as mudanças estão descritas no código onde deve ser alterado, só que você não vai precisar sair procurando, eu vou lhe dizer onde que é.
1. Crie um bot para teste conversando com o @BotFather.

1. Altere o banco que deseja utilizar no arquivo notifier.py e no notifications.py
2. Agora altere os valores das seguintes variáveis de ambiente no **docker-compose**, com as credenciais do seu bot.
```
# If you have your own database, changes to ('database', <PORT>)
client = MongoClient('mongodb://mongo-ru:27017/lino_ru')
# Para rodar no telegram altere as seguintes
# variáveis nos serviços Lino e Actions
- TELEGRAM_ACCESS_TOKEN=<TOKEN_GERADO_PELO_BOTFATHER>
- VERIFY=<@USUÁRIO_DO_BOT_NO_TELEGRAM>
- TELEGRAM_DB_URI=mongodb://mongo_lino:27010/lino_telegram

# Ou utilize o banco que desejar
- TELEGRAM_DB_URI=<BANCO_QUE_DESEJAR>
```
**OBS 1:** Altere as variáveis necessárias no serviço do cronjob.

2. Caso esteja trabalhando com o Telegram, adicione o token nos arquivos notifier e no notifications.py
3. Comente as linhas que dizem respeito à variáveis do serviço do **Messenger** em todos os serviços.
```
# If you want to use your own bot to development add the bot token as
# second parameters
TELEGRAM_ACCESS_TOKEN = os.getenv('TELEGRAM_ACCESS_TOKEN', '')
# - FACEBOOK_DB_URI
# - PSID
# - FACEBOOK_ACCESS_TOKEN
# - SECRET
```

3. Caso esteja rodando o webcrawler local, altere a URL no arquivo notifier e no menu.py
4. Para conectar com o Telegram, você vai precisar gerar uma URL com certificado. Para isso, nós utilizamos o **Ngrok** (necessário instalá-lo).

5. Agora rode o seguinte comando para expor a porta e gerar o certificado para nosso webhook.

```
# Change the url if you have your own webcrawler server
response = requests.get('http://<imagem_crawler>:<porta_crawler>/cardapio/{}'.format(day)).json()
# Gera a URL com certificado (https)
./ngrok http <PORTA_BOT>
```

4. Caso queira usar com os mensageiros o Lino, utilize o ngrok para expor para o mundo
6. Substitua o valor da variável no serviço Lino.
```
./ngrok http <porta_bot>
# Altere o valor da variável seguinte
- WEBHOOK_URL=<URL_HTTPS/webhooks/telegram/webhook
```

5. Adicione as credenciais do bot no train-messenger ou no train-telegram (Exemplo abaixo sobre o Telegram)
7. Rode o seguinte comando para finalizar e desfrutar do seu bot
```
# If you want to use your own bot to development
# add the bot credentials as second parameters
TELEGRAM_ACCESS_TOKEN = os.getenv('TELEGRAM_ACCESS_TOKEN', '')
VERIFY = os.getenv('VERIFY', '')
# the webhook URL is one that ngrok generates (https)
WEBHOOK_URL = os.getenv('WEBHOOK_URL', '')
sudo docker-compose up
```

5. Agora está tudo certinho pra você começar a desenvolver e testar o bot :)
8. Agora está tudo certinho pra você começar a desenvolver e testar o seu bot :)


#### Testando o Lino no Terminal
#### Script setup_env.py
Para facilitar a troca de variáveis no ambiente existe um script na pasta scripts/ que vai te ajudar.

Para testar as alterações feitas no Lino, execute os seguintes comandos no terminal:
Para utilizar basta usar o comando:

1. Crie a imagem do Lino:
```
sudo docker build -t lino .
```bash
python3 scripts/setup_env.py
```

2. Inicialize o _container_:
```
sudo docker run --rm -it -p 5002:5002 -v $PWD:/2018.2-Lino lino
```

3. Agora basta testar as novas alterações pelo terminal.
#### Setup para testar o Lino no terminal

#### Testando o Lino nos Mensageiros
Para testar as alterações feitas no Lino, execute os seguintes comandos no terminal:

1. Crie a imagem do Lino:
```
sudo docker build -t <imagem_nome> -f docker/<Mensageiro>.Dockerfile .
sudo docker build -t lino .
```

2. Inicialize o _container_:
```
sudo docker run --rm -it -v $PWD:/2018.2-Lino <imagem_nome>
sudo docker run --rm -it -p 5002:5002 -v $PWD:/2018.2-Lino lino
```

3. Agora basta testar as novas alterações pelo terminal.

#### Container pra Desenvolvimento

1. Caso queira inicilizar um ambiente de desenvolvimento com todos os serviços
```
# Altere a imagem que deseja (qual mensageiro ou terminal) dentro do docker-compose
sudo docker-compose up --build
```

### Licença

<p align="justify">&emsp;&emsp; Lino é distribuído sob a licença GPLv3. Consulte <a href="https://github.com/fga-eps-mds/2018.2-Lino/blob/master/LICENSE.md">LICENSE</a> para obter detalhes.</p>
151 changes: 97 additions & 54 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,60 +1,103 @@
version: '3'

services:
lino:
# If you want to development and use another image,
# change the image to the Dockerfile that corresponds to the one you want to use.
image: guila/lino:latest
ports:
- 5002:5002
volumes:
- .:/2018.2-Lino
stdin_open: true
tty: true
environment:
- TRAINING_EPOCHS: ${TRAINING_EPOCHS}
- TELEGRAM_ACCESS_TOKEN: ${TELEGRAM_ACCESS_TOKEN}
- VERIFY: ${VERIFY}
- PSID: ${PSID}
- FACEBOOK_ACCESS_TOKEN: ${FACEBOOK_ACCESS_TOKEN}
- SECRET: ${SECRET}
- WEBHOOK_URL: ${WEBHOOK_URL}
- TELEGRAM_DB_URI: ${TELEGRAM_DB_URI}
- FACEBOOK_DB_URI: ${FACEBOOK_DB_URI}
# bot credentials in train.py or another train file.
depends_on:
- cronjob
- mongo_telegram
- mongo_facebook
lino:
# If you want to development and use another image,
# change the image to the Dockerfile that corresponds to the one you want to use.
build:
context: .
dockerfile: docker/Telegram.Dockerfile
ports:
- 5002:5002
volumes:
- .:/2018.2-Lino
stdin_open: true
tty: true
environment:
- TRAINING_EPOCHS: ${TRAINING_EPOCHS}
- TELEGRAM_ACCESS_TOKEN: ${TELEGRAM_ACCESS_TOKEN}
- VERIFY: ${VERIFY}
- PSID: ${PSID}
- FACEBOOK_ACCESS_TOKEN: ${FACEBOOK_ACCESS_TOKEN}
- SECRET: ${SECRET}
- WEBHOOK_URL: ${WEBHOOK_URL}
- TELEGRAM_DB_URI: ${TELEGRAM_DB_URI}
- FACEBOOK_DB_URI: ${FACEBOOK_DB_URI}
# bot credentials in train.py or another train file.
depends_on:
- actions
- cronjob
- mongo_telegram
- mongo_facebook

mongo_telegram:
image: mongo:latest
command: mongod --port 27010
volumes:
- /l/mongo_telegram/mongo_telegram_db:/data/db
ports:
- 27010:27010
mongo_telegram:
image: mongo:latest
command: mongod --port 27010
volumes:
- /l/mongo_telegram/mongo_telegram_db:/data/db
ports:
- 27010:27010

mongo_facebook:
image: mongo:latest
command: mongod --port 27011
volumes:
- /l/mongo_facebook/mongo_facebook_db:/data/db
ports:
- 27011:27011
mongo_facebook:
image: mongo:latest
command: mongod --port 27011
volumes:
- /l/mongo_facebook/mongo_facebook_db:/data/db
ports:
- 27011:27011

cronjob:
image: guila/cronjob:latest
volumes:
- ./outputs:/home
stdin_open: true
tty: true
environment:
- URI_TELEGRAM: ${URI_TELEGRAM}
- URI_FACEBOOK: ${URI_FACEBOOK}
- TELEGRAM_ACCESS_TOKEN: ${TELEGRAM_ACCESS_TOKEN}
- FACEBOOK_ACCESS_TOKEN: ${FACEBOOK_ACCESS_TOKEN}
- PSID: ${PSID}
depends_on:
- mongo_telegram
- mongo_facebook
cronjob:
image: guila/cronjob:latest
volumes:
- ./outputs:/home
stdin_open: true
tty: true
environment:
- URI_TELEGRAM: ${URI_TELEGRAM}
- URI_FACEBOOK: ${URI_FACEBOOK}
- TELEGRAM_ACCESS_TOKEN: ${TELEGRAM_ACCESS_TOKEN}
- FACEBOOK_ACCESS_TOKEN: ${FACEBOOK_ACCESS_TOKEN}
- PSID: ${PSID}
depends_on:
- mongo_telegram
- mongo_facebook

actions:
build:
context: .
dockerfile: ./docker/Actions.Dockerfile
ports:
- 5055:5055
volumes:
- ./rasa/actions:/rasa/actions
- ./rasa/Makefile:/rasa/Makefile
command: "make run-actions"
environment:
- TELEGRAM_ACCESS_TOKEN: ${TELEGRAM_ACCESS_TOKEN}
- VERIFY: ${VERIFY}
- TELEGRAM_DB_URI: ${TELEGRAM_DB_URI}
- FACEBOOK_DB_URI: ${FACEBOOK_DB_URI}


elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:5.4.3
container_name: elasticsearch
ports:
- "9200:9200"
- "9300:9300"
networks:
- docker_elk
kibana:
image: docker.elastic.co/kibana/kibana:5.4.3
container_name: kibana
environment:
- "ELASTICSEARCH_URL=http://elasticsearch:9200"
ports:
- "5601:5601"
networks:
- docker_elk
depends_on:
- elasticsearch
networks:
docker_elk:
driver: bridge
20 changes: 20 additions & 0 deletions docker/Actions.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM python:3.6-slim

RUN apt update && apt install -y gcc make curl

ADD ./docker/actions.requirements.txt /tmp/

RUN pip install --upgrade pip && \
pip install -r /tmp/actions.requirements.txt

ADD ./rasa/actions/ /rasa/actions/
ADD ./rasa/Makefile /rasa/Makefile

WORKDIR rasa/

EXPOSE 5055

HEALTHCHECK --interval=300s --timeout=60s --retries=5 \
CMD curl -f http://0.0.0.0:5055/health || exit 1

CMD make run-actions
3 changes: 1 addition & 2 deletions docker/Messenger.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ FROM python:3.6

ADD ./requirements.txt /tmp

RUN pip install -r /tmp/requirements.txt && \
python -m spacy download pt
RUN pip install -r /tmp/requirements.txt

RUN pip uninstall -y tensorflow && pip install tensorflow==1.5

Expand Down
7 changes: 3 additions & 4 deletions docker/Telegram.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ FROM python:3.6

ADD ./requirements.txt /tmp

RUN pip install -r /tmp/requirements.txt && \
python -m spacy download pt
RUN pip install -r /tmp/requirements.txt

RUN pip uninstall -y tensorflow && pip install tensorflow==1.5
RUN pip uninstall -y tensorflow && pip install tensorflow==1.12.0

RUN mkdir /2018.2-Lino

Expand All @@ -16,4 +15,4 @@ WORKDIR /2018.2-Lino/rasa
ENV TRAINING_EPOCHS=450 \
CREDENTIALS="credentials.yml"

CMD python train-telegram.py
CMD make train && python train-telegram.py
10 changes: 10 additions & 0 deletions docker/actions.requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
rasa-core==0.13.1
rasa-core-sdk==0.12.1
oauth2client==4.1.3
gspread==3.1.0
logger==1.4
Flask==1.0.2
Flask-Cors==3.0.6
httpretty
requests
pymongo==3.7.1
Loading