2 Commits

Author SHA1 Message Date
8f7c6b6c36 create a simple instruction 2026-01-07 21:09:04 +05:00
fe9e5f7256 fixed crontab every 5 seconds AND skipping empty messages 2026-01-07 17:17:51 +05:00
4 changed files with 54 additions and 2 deletions

View File

@@ -1,2 +1,40 @@
# campanula
# Campanula
Receive and send messages through Gammu server and Telegram messenger interface
## Preparation
1. **Ubuntu** linux distributive
2. Any **SIM-modem**, for example **[SIM900](https://ali.click/xxe9vh?erid=2SDnjdoLMq2)**
</br><sub><sup>Реклама: ООО "АЛИБАБА.КОМ (РУ)" ИНН: 7703380158</sup></sub>
3. **UART****USB** adapter
4. **[Gammu](https://docs.gammu.org/smsd/smsd.html)** installed and configured
## Installation
### Download the repository and its dependencies
```bash
cd /var/www
git clone https://git.svoboda.works/garden/campanula
cd campanula
composer update
```
### Edit settings files
```bash
cd garden/campanula/system/settings
nvim system.php
nvim telegram.php
nvim gammu.php
```
### Test manually launch
```bash
cd ../public
php telegram_week.php
```
*The robot will send a message only if you have already started a conversation with it*
### Write script launch into crontab
```bash
cat ../../../../examples/crontab/records.sh
sudo crontab -e
```

View File

@@ -1 +1 @@
*/10 * * * * php /var/www/campanula/garden/campanula/system/public/telegram_week.php
* * * * * /var/www/campanula/examples/crontab/week.sh

11
examples/crontab/week.sh Executable file
View File

@@ -0,0 +1,11 @@
#!/bin/bash
# Loop 6 times (60 seconds / 10 seconds = 6 iterations)
for i in {1..6}; do
php /var/www/campanula/garden/campanula/system/public/telegram_week.php
# Wait 10 seconds before next iteration (skip sleep after the last run)
if [ $i -lt 6 ]; then
sleep 5
fi
done

View File

@@ -104,6 +104,9 @@ $response = (array) $request->fetchAll(pdo::FETCH_ASSOC);
foreach ($response as $message) {
// Iterating over messages from last week
// Skipping empty messages
if (empty($message['TextDecoded'])) continue;
// Searching for the message
$model = new message()->read(filter: fn(record $record) => $record->sended === 1 && $record->identifier_gammu === (int) $message['ID']);