diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2022-05-26 03:14:50 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2022-05-26 21:51:43 +0300 |
commit | c3ed2483ea508141431be74f29f7c209271897cd (patch) | |
tree | 9f7a416ab433ffc9bd245d1dd382f350a4e61efc /localwebsite/cron/check-vk-sms.php | |
parent | 997c6da6c40c11ec0bc6cc749f78deca8dd95db1 (diff) |
cron: vk sms checker
Diffstat (limited to 'localwebsite/cron/check-vk-sms.php')
-rwxr-xr-x | localwebsite/cron/check-vk-sms.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/localwebsite/cron/check-vk-sms.php b/localwebsite/cron/check-vk-sms.php new file mode 100755 index 0000000..5d1095a --- /dev/null +++ b/localwebsite/cron/check-vk-sms.php @@ -0,0 +1,44 @@ +#!/usr/bin/env php +<?php + +// this scripts pulls recent inbox from e3372 modem, +// looks for new messages from vk and re-sends them +// to the telegram group + +require_once __DIR__.'/../init.php'; +global $config; + +$cfg = $config['modems'][$config['vk_sms_checker']['modem_name']]; +$e3372 = new E3372($cfg['ip'], $cfg['legacy_token_auth']); + +$db = getDB(); + +$last_processed = $db->querySingle("SELECT last_message_time FROM vk_processed"); +$new_last_processed = 0; + +$messages = $e3372->getSMSList(); +$messages = array_reverse($messages); + +$results = []; +if (!empty($messages)) { + foreach ($messages as $m) { + if ($m['timestamp'] <= $last_processed) + continue; + + $new_last_processed = $m['timestamp']; + if (preg_match('/^vk/i', $m['phone']) || preg_match('/vk/i', $m['content'])) + $results[] = $m; + } +} + +if (!empty($results)) { + $t = new TelegramBotClient($config['vk_sms_checker']['telegram_token']); + foreach ($results as $m) { + $text = '<b>'.htmlescape($m['phone']).'</b> ('.$m['date'].')'; + $text .= "\n".htmlescape($m['content']); + $t->sendMessage($config['vk_sms_checker']['telegram_chat_id'], $text); + } +} + +if ($new_last_processed != 0) + $db->exec("UPDATE vk_processed SET last_message_time=?", $new_last_processed);
\ No newline at end of file |