Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into 40-issue-prevent-us…
Browse files Browse the repository at this point in the history
…ers-from-deleting-their-own-roles
  • Loading branch information
Emnaghz committed Sep 21, 2024
2 parents cb64234 + 1ece819 commit 42cfc1f
Show file tree
Hide file tree
Showing 46 changed files with 484 additions and 369 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
name: Build and Push Docker Images

on:
push:
branches: ["main"]
workflow_dispatch:

jobs:
paths-filter:
runs-on: ubuntu-latest
outputs:
frontend: ${{ steps.filter.outputs.frontend }}
api: ${{ steps.filter.outputs.api }}
widget: ${{ steps.filter.outputs.widget }}
nlu: ${{ steps.filter.outputs.nlu }}
steps:
- uses: actions/checkout@v4
- name: Filter paths
id: filter
uses: dorny/paths-filter@v3
with:
filters: |
frontend:
- 'frontend/**'
api:
- 'api/**'
widget:
- 'widget/**'
nlu:
- 'nlu/**'
build-and-push:
runs-on: ubuntu-latest
needs:
- paths-filter
steps:
- name: Check out repository code
uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to Docker Hub
id: docker_login
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push Frontend Docker image
if: ${{ needs.paths-filter.outputs.frontend == 'true' }}
uses: docker/build-push-action@v6
with:
context: ./
file: ./frontend/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: hexastack/hexabot-ui:latest

- name: Build and push API Docker image
if: ${{ needs.paths-filter.outputs.api == 'true' }}
uses: docker/build-push-action@v6
with:
context: ./api/
file: ./api/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: hexastack/hexabot-api:latest

- name: Build and push Widget Docker image
if: ${{ needs.paths-filter.outputs.widget == 'true' }}
uses: docker/build-push-action@v6
with:
context: ./widget/
file: ./widget/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: hexastack/hexabot-widget:latest

- name: Build and push NLU Docker image
if: ${{ needs.paths-filter.outputs.nlu == 'true' }}
uses: docker/build-push-action@v6
with:
context: ./nlu/
file: ./nlu/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: hexastack/hexabot-nlu:latest
41 changes: 27 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Default path setup
COMPOSE_FILES := -f ./docker/docker-compose.yml -f ./docker/docker-compose.dev.yml
COMPOSE_FILES := -f ./docker/docker-compose.yml

# Function to add service files
define add_service
Expand All @@ -8,20 +7,29 @@ define add_service
ifneq ($(wildcard ./docker/docker-compose.$(1).prod.yml),)
COMPOSE_FILES += -f ./docker/docker-compose.$(1).prod.yml
endif
else
COMPOSE_FILES += -f ./docker/docker-compose.$(1).yml -f ./docker/docker-compose.$(1).dev.yml
else ifeq ($(DEV_MODE), true)
COMPOSE_FILES += -f ./docker/docker-compose.$(1).yml
ifneq ($(wildcard ./docker/docker-compose.$(1).dev.yml),)
COMPOSE_FILES += -f ./docker/docker-compose.$(1).dev.yml
endif
endif
endef


# Check if services are specified and add corresponding compose files
ifneq ($(NGINX),)
$(eval $(call add_service,nginx))
endif

ifneq ($(NLU),)
$(eval $(call add_service,nlu))
endif
# Function to set up COMPOSE_FILES
define compose_files
ifeq ($(1), true)
ifneq ($(wildcard ./docker/docker-compose.dev.yml),)
COMPOSE_FILES += -f ./docker/docker-compose.dev.yml
endif
endif
ifneq ($(NGINX),)
$(eval $(call add_service,nginx))
endif
ifneq ($(NLU),)
$(eval $(call add_service,nlu))
endif
endef

# Ensure .env file exists and matches .env.example
check-env:
Expand All @@ -36,16 +44,21 @@ init:
cp ./docker/.env.example ./docker/.env

dev: check-env
$(eval $(call compose_files,true))
docker compose $(COMPOSE_FILES) up -d

start: check-env
docker compose $(COMPOSE_FILES) up -d --build
$(eval $(call compose_files,false))
docker compose $(COMPOSE_FILES) up -d

stop: check-env
$(eval $(call compose_files,true))
docker compose $(COMPOSE_FILES) down

destroy: check-env
$(eval $(call compose_files,true))
docker compose $(COMPOSE_FILES) down -v

migrate-up:
docker-compose $(COMPOSE_FILES) up --no-deps -d database-init
$(eval $(call compose_files,false))
docker-compose $(COMPOSE_FILES) up --no-deps -d database-init
27 changes: 21 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Hexabot

![App Screenshot](https://www.hexabot.ai/assets/images/screencast.gif)

## Description
Expand All @@ -20,13 +21,15 @@
- **Inbox & Handover:** Provides a real-time chat window where conversations can be monitored and handed over to human agents when necessary.

## Directory Structure

- **frontend:** The admin panel built with React/Next.js for managing chatbot configurations and flows.
- **api:** The backend API built with NestJS and connected to MongoDB for data storage and management.
- **widget:** A React-based live chat widget that can be embedded into any website to provide real-time interaction.
- **nlu:** The NLU Engine built with Python, enabling intent recognition and language detection through machine learning models.
- **docker:** A set of Docker Compose files for deploying the entire solution, making it easy to run Hexabot in any environment.

## Prerequisites

To ensure Hexabot runs smoothly, you'll need the following:

- **Docker:** We recommend using Docker to start the app since multiple services are required (MongoDB, Redis, Prometheus, etc.). All the necessary Docker Compose files are located in the docker folder.
Expand All @@ -35,28 +38,37 @@ To ensure Hexabot runs smoothly, you'll need the following:
## Installation

1. **Clone the Repository:**

```bash
$ git clone https://github.com/hexastack/hexabot.git
```

2. **Environment Setup:** To configure the environment variables, use the Makefile at the root folder for initialization:

```bash
$ make init
```

This will copy the `.env.example` file to `.env` in the `./docker` directory if the file does not already exist.

3. **Running the Application:** Once your environment is set up, you can start the app. Use either of the following commands:

```bash
$ make start
```

or for development mode:

```bash
$ make dev
```

**Note:** The first time you run the app, Docker will take some time to download all the required images.

## Usage

UI Admin Panel is accessible via http://localhost:8080, the default credentials are :
UI Admin Panel is accessible via http://localhost:8080, the default credentials are :

- **Username:** [email protected]
- **Password:** adminadmin

Expand All @@ -65,18 +77,20 @@ Live Chat Widget is accessible via http://localhost:5173
## Commands

- `make init` : Copies the .env.example file to .env in the ./docker directory if .env does not exist. This is usually used for initial setup.
- `make dev` : Starts all configured Docker services in development mode. It first checks the .env file for completeness against .env.example.
- `make start` : Similar to dev, but explicitly builds the Docker images before starting the services. This target also checks the .env file for required variables.
- `make dev` : Starts all configured Docker services in development mode. It first checks the .env file for completeness against .env.example and builds the docker images locally.
- `make start` : Starts all configured Docker services by loading all images from Docker Hub. This target also checks the .env file for required variables.
- `make stop` : Stops all running Docker services defined in the compose files.
- `make destroy` : Stops all services and removes all volumes associated with the Docker compose setup, ensuring a clean state.
- `make check-env` : Checks if the ./docker/.env file exists and contains all the necessary environment variables as defined in ./docker/.env.example. If the file does not exist, it is created from the example. It also lists missing variables if any.

Example on how to start the stack by adding the Nginx service :
Example on how to start the stack by adding the Nginx service :

```sh
make start NGINX=1
```

## Documentation

For detailed information on how to get started, as well as in-depth user and developer guides, please refer to our full documentation available in the docs folder or visit the [Documentation](https://docs.hexabot.ai).

You can also find specific documentation for different components of the project in the following locations:
Expand All @@ -86,16 +100,17 @@ You can also find specific documentation for different components of the project
- [Live Chat Widget Documentation](widget/README.md)
- [NLU Engine Documentation](nlu/README.md)

## Contributing
## Contributing

We welcome contributions from the community! Whether you want to report a bug, suggest new features, or submit a pull request, your input is valuable to us.

Please refer to our contribution policy first : [How to contribute to Hexabot](./CONTRIBUTING.md)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](./CODE_OF_CONDUCT.md)


Feel free to join us on [Discord](https://discord.gg/rNb9t2MFkG)

## License

This software is licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:

1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
Expand Down
40 changes: 22 additions & 18 deletions api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,24 +57,28 @@ const i18nOptions: I18nOptions = {

@Module({
imports: [
MailerModule.forRoot({
transport: new SMTPTransport({
...config.emails.smtp,
logger: true,
}),
template: {
adapter: new MjmlAdapter('ejs', { inlineCssEnabled: false }),
dir: './src/templates',
options: {
context: {
appName: config.parameters.appName,
appUrl: config.parameters.appUrl,
// TODO: add i18n support
},
},
},
defaults: { from: config.parameters.email.main },
}),
...(config.emails.isEnabled
? [
MailerModule.forRoot({
transport: new SMTPTransport({
...config.emails.smtp,
logger: true,
debug: false,
}),
template: {
adapter: new MjmlAdapter('ejs', { inlineCssEnabled: false }),
dir: './src/templates',
options: {
context: {
appName: config.parameters.appName,
appUrl: config.parameters.appUrl,
},
},
},
defaults: { from: config.emails.from },
}),
]
: []),
MongooseModule.forRoot(config.mongo.uri, {
dbName: config.mongo.dbName,
connectionFactory: (connection) => {
Expand Down
9 changes: 2 additions & 7 deletions api/src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,14 @@
*/

import { Injectable } from '@nestjs/common';
import { EventEmitter2 } from '@nestjs/event-emitter';

import { ExtendedI18nService } from './extended-i18n.service';

@Injectable()
export class AppService {
constructor(
private readonly i18n: ExtendedI18nService,
private readonly eventEmitter: EventEmitter2,
) {}
constructor(private readonly i18n: ExtendedI18nService) {}

getHello(): string {
this.eventEmitter.emit('hook:i18n:refresh', []);
return this.i18n.t('Welcome');
return this.i18n.t('welcome', { lang: 'en' });
}
}
9 changes: 6 additions & 3 deletions api/src/config/i18n/en/messages.json
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
{
"invitation_subject": "[Hexabot] Sign-Up Invitation",
"account_confirmation_subject": "[Hexabot] Account Confirmation",
"password_reset_subject": "[Hexabot] Password Reset",
"welcome": "Welcome",
"hi": "Hi",
"invitation_to_join": "Invitation to join",
"invitation_for_account_creation": "You have been invited to create a",
"account": "account",
"create_account:": "Click on the button below to create your account:",
"create_account": "Click on the button below to create your account:",
"registration_failed": "Registration failed! Either email address or invitation token is invalid.",
"create_account_button": "Click on the button below to create your account",
"join": "Join",
"account_successfully_created_confirm_password": "You have successfully created an account but you will need to confirm your email address.",
"confirm_account:": "Click on the button below in order to confirm your account:",
"confirm_account": "Click on the button below in order to confirm your account:",
"password_reset_request": "A request to reset the password for your account has been made.",
"reset": "Reset",
"click_to_reset_password:": "Click on the button below in order to set a new password:",
"click_to_reset_password": "Click on the button below in order to set a new password:",
"confirm": "Confirm",
"best_regards": "Best Regards,"
}
3 changes: 3 additions & 0 deletions api/src/config/i18n/fr/messages.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"invitation_subject": "[Hexabot] Invitation à s'inscrire",
"account_confirmation_subject": "[Hexabot] Confirmation de compte",
"password_reset_subject": "[Hexabot] Réinitialisation du mot de passe",
"welcome": "Bienvenue",
"hi": "Bonjour",
"invitation_to_join": "Invitation",
Expand Down
Loading

0 comments on commit 42cfc1f

Please sign in to comment.