2024-09-30 18:29:41 +07:00
# huesos
Basis for developing chat-robots with "Web App" technology for Telegram
2025-01-16 09:42:29 +07:00
## Dependencies
1. ![PHP 8.4 ](https://www.php.net/releases/8.4/en.php )
2. ![MINIMAL ](https://git.svoboda.works/mirzaev/minimal ) (PHP framework)
3. ![Twig ](https://twig.symfony.com/ ) (HTML templater)
4. ![Zanzara ](https://github.com/badfarm/zanzara ) (Telegram framework + ReactPHP)
5. ![ArangoDB ](https://docs.arangodb.com/3.11/about-arangodb/ ) (non-relational database)
6. ![NGINX ](https://nginx.org/en/ ) (web server) *(can be replaced)*
7. ![SystemD ](https://systemd.io/ ) (service manager) *(can be replaced)*
8. ![Composer ](https://getcomposer.org/ ) (php package manager)
< small > You can find other dependencies in the file `/composer.json` </ small >
2024-09-30 18:29:41 +07:00
## Installation
### AnangoDB
2025-01-15 13:20:11 +07:00
1. **Configure unix-socket** < br >
< br >
2025-01-15 02:11:54 +07:00
Edit the file `/etc/arangodb3/arangod.conf` < br >
`endpoint = tcp://127.0.0.1:8529` -> `endpoint = unix:///var/run/arangodb3/arango.sock` (this will disable the web panel)< br >
2025-01-15 13:20:11 +07:00
< br >
2025-01-15 02:11:54 +07:00
To make the web panel work, you can add this to the NGINX server settings:
```lua
server {
...
server_name arangodb.domain.zone;
...
2025-01-15 13:20:11 +07:00
allow YOUR_IP_ADDRESS;
2025-01-15 02:11:54 +07:00
allow 192.168.1.1/24;
allow 127.0.0.1;
deny all;
# ArangoDB
location / {
proxy_pass http://arangodb;
}
}
upstream arangodb {
server unix:/var/run/arangodb3/arango.sock;
}
```
2025-01-15 13:20:11 +07:00
![here is my solution for "permission denied" problem on Ubuntu (accepted by ArangoDB maintainer) ](https://github.com/arangodb/arangodb/issues/17302 )< br >
1. **Configure TCP (instead of unix-socket)** < br >
2025-01-15 02:11:54 +07:00
< br >
Edit the file `/etc/arangodb3/arangod.conf` < br >
`endpoint = tcp://127.0.0.1:8529` -> `endpoint = tcp://0.0.0.0:8529` < br >
2025-01-15 13:20:11 +07:00
< br >
Edit the file `mirzaev/huesos/system/settings/arangodb.php` < br >
2025-01-15 02:11:54 +07:00
`unix:///var/run/arangodb3/arango.sock` -> `tcp://YOUR_IP_ADDRESS:8529` (it is slow and not secure)< br >
2025-01-15 13:20:11 +07:00
---
2. **Create a Graph with the specified values** < br >
2024-11-19 08:15:30 +07:00
< br >
2025-01-15 13:20:11 +07:00
**Name:** catalog< br >
* Relation 1< br >
2024-11-19 08:15:30 +07:00
**edgeDefinition:** entry< br >
2025-01-15 13:20:11 +07:00
**fromCollections:** category, product< br >
2024-10-11 13:58:35 +07:00
**toCollections:** category
2024-09-30 18:29:41 +07:00
2025-01-15 13:20:11 +07:00
* Relation 2< br >
2024-11-19 08:15:30 +07:00
**edgeDefinition:** reservation< br >
**fromCollections:** product< br >
**toCollections:** cart
2025-01-15 13:20:11 +07:00
---
3. **Create a Graph with the specified values** < br >
2024-11-19 08:15:30 +07:00
< br >
2025-01-15 13:20:11 +07:00
**Name:** users< br >
* Relation 1< br >
2024-11-19 08:15:30 +07:00
**edgeDefinition:** connect< br >
**fromCollections:** cart, session< br >
2025-01-15 13:20:11 +07:00
**toCollections:** account, session< br >
< br >
2024-11-19 08:15:30 +07:00
**Orphan Collections:** product
2025-01-15 13:20:11 +07:00
---
4. **Create indexes for the "product" collection** < br >
< br >
2024-11-19 08:15:30 +07:00
**Type:** "Inverted Index"< br >
**Fields:** name.ru< br >
**Analyzer:** "text_ru"< br >
**Search field:** true< br >
**Name:** name_ru< br >
< br >
*Add indexes for all search parameters and for all languages (search language is selected based on the user's language, < br >
otherwise from the default language specified in the active settings from **settings** collection document)*< br >
< br >
*See fields in the `mirzaev/arming_bot/models/product` < br >
2025-01-15 13:20:11 +07:00
**name.ru**, **description.ru** and **compatibility.ru** *< br >
---
5. **Create a View with the specified values**
2024-11-19 08:15:30 +07:00
**type:** search-alias (you can also use "arangosearch")< br >
**name:** **product**s_search< br >
**indexes:**< br >
< br >
You can copy an example of view file from here: `/examples/arangodb/views/products_search.json`
2024-10-11 15:23:05 +07:00
```json
2024-09-30 18:29:41 +07:00
"indexes": [
{
"collection": "product",
2024-10-11 15:23:05 +07:00
"index": "title_ru" # THIS IS AN EXAMPLE
2024-09-30 18:29:41 +07:00
}
]
2024-10-11 15:23:05 +07:00
```
2024-09-30 18:29:41 +07:00
### NGINX
2025-01-15 13:20:11 +07:00
1. **Create a NGINX server** < br >
2024-11-19 08:15:30 +07:00
You can copy an example of server file from here: `/examples/nginx/server.conf`
2024-10-11 13:58:35 +07:00
2025-01-15 13:20:11 +07:00
2. **Add support for javascript modules** < br >
2024-11-19 08:15:30 +07:00
Edit the file `/etc/nginx/mime.types` < br >
`application/javascript js;` -> `application/javascript js mjs;`
2024-09-30 18:29:41 +07:00
2024-10-11 13:58:35 +07:00
### SystemD (or any alternative you like)
2024-11-19 08:15:30 +07:00
You can copy an example of systemd file from here: `/examples/systemd/huesos.service` < br >
< br >
**Execute:** `sudo cp huesos.service /etc/systemd/system/huesos.service && sudo chmod +x /etc/systemd/system/huesos.service` < br >
< br >
*before you execute the command think about **what it does** and whether the **paths** are specified correctly*< br >
2024-10-11 13:58:35 +07:00
*the configuration file is very simple and you can remake it for any alternative to SystemD that you like*
2024-11-19 08:15:30 +07:00
2025-01-15 13:20:11 +07:00
## Menu
Menu inside the Web App< br >
< br >
Make sure you have a **menu** collection (can be created automatically)< br >
You can copy a clean menu documents without comments from here: `/examples/arangodb/collections/menu`
```json
{
"urn": "/", // Link
"name": {
"en": "Main page",
"ru": "Главная страница"
},
"style": { // The `style` attribute
"order": 0
},
"class": {},
"icon": { // Icon from `/themes/default/css/icons`
"style": { // The `style` attribute
"rotate": "-135deg"
},
"class": "arrow circle" // Classes of the icon
},
"image": { // Image at the background @deprecated ?
"storage": null
}
}
```
2024-09-30 18:29:41 +07:00
## Settings
2024-11-19 08:15:30 +07:00
Settings of chat-robot and Web App< br >
< br >
Make sure you have a **settings** collection (can be created automatically) and at least one document with the "status" parameter set to "active"< br >
You can copy a clean settings document without comments from here: `/examples/arangodb/collections/settings.json`
2024-10-11 15:23:05 +07:00
```json
2024-09-30 18:29:41 +07:00
{
2024-11-19 08:15:30 +07:00
"status": "active",
"project": {
"name": "PROJECT"
},
"language": "en", // Will be converted to an instance of enumeration `mirzaev\arming_bot\models\enumerations\language`
"currency": "usd", // Will be converted to an instance of enumeration `mirzaev\arming_bot\models\enumerations\currency`
"company": {
"identifier": null, // Example: "000000000000000" (string|null) (if `null` it will not be displayed)
"tax": null, // Example: "000000000000" (string|null) (if `null` it will not be displayed)
"name": null, // Example: "COMPANY" (string|null) (if `null` it will not be displayed)
"offer": false, // Display the data of a public offer in the footer? (bool) (does not affect the `/offer` page generation)
"sim": null, // Examples: "+7 000 000-00-00", "70000000000" (string|null) (if `null` it will not be displayed)
"mail": null // Example: "name@domain.zone" (string|null) (if `null` it will not be displayed)
}
2024-09-30 18:29:41 +07:00
}
2024-10-11 15:23:05 +07:00
```
2024-09-30 18:29:41 +07:00
## Suspensions
2024-11-19 08:15:30 +07:00
System of suspensions of chat-robot and Web App< br >
< br >
Make sure you have a **suspension** collection (can be created automatically)< br >
You can copy a clean suspension document without comments from here: `/examples/arangodb/collections/suspension.json`
2024-10-11 15:23:05 +07:00
```json
2024-09-30 18:29:41 +07:00
{
2024-11-19 08:15:30 +07:00
"end": 1726068961, // Unixtime
2024-09-30 18:29:41 +07:00
"targets": {
2024-11-19 08:15:30 +07:00
"chat-robot": true, // Block chat-robot
"web app": true // Block "Web App"
},
2024-09-30 18:29:41 +07:00
"access": {
2024-11-19 08:15:30 +07:00
"tester": true, // Account with `"tester": true`
"developer": true // Account with `"developer": true`
2024-09-30 18:29:41 +07:00
},
"description": {
"ru": "Разрабатываю каталог, поиск и корзину",
"en": "I am developing a catalog, search and cart"
}
}
2024-10-11 15:23:05 +07:00
```