Compare commits

...

4 Commits

3 changed files with 38 additions and 24 deletions

View File

@ -1,3 +1,5 @@
# Telegram-robot for registering for tasks
# Telegram chat-robot for task registering
Synchronizes accounts with the site, displays a list of published applications with a selection by date, and also register to tasks
Chat-robot Telegram for accepting applications for employees from [mirzaev/ebala](https://git.mirzaev.sexy/mirzaev/ebala)
**DEVELOPMENT COMPLETED. PROJECT CLOSED.**

View File

@ -346,37 +346,43 @@ function request_confirmed(Context $ctx): void
// Прочитана запрашиваемая заявка
// Инициализация инстанции task в базе данных (выбранного задания)
$task = collection::search($arangodb->session, sprintf("FOR d IN task FILTER d._key == '%s' && d.published == true && d.completed != true RETURN d", $_key));
$task = collection::search($arangodb->session, sprintf("FOR d IN task FILTER d._key == '%s' && d.published == true && d.completed != true && worker == null RETURN d", $_key));
if ($worker ??= worker($account->getId())) {
// Найден сотрудник
if ($task instanceof _document) {
// Найдена заявка (подразумевается, что не занята)
// Запись идентификатора нового сотрудника
$task->worker = $worker->id;
if ($worker ??= worker($account->getId())) {
// Найден сотрудник
// Снятие с публикации
$task->published = false;
// Запись идентификатора нового сотрудника
$task->worker = $worker->id;
if (document::update($arangodb->session, $task)) {
// Записано обновление в базу данных
// Снятие с публикации
$task->published = false;
$ctx->getChatDataItem("request_all")->then(function ($requests = []) use ($ctx) {
// Удаление сообщений связанных с запросом
foreach ($requests ?? [] as $_message) $ctx->deleteMessage($_message->getChat()->getId(), $_message->getMessageId());
});
$ctx->setChatDataItem("request_all", []);
if (document::update($arangodb->session, $task)) {
// Записано обновление в базу данных
$ctx->getChatDataItem("request_confirmation")->then(function ($message) use ($ctx) {
$ctx->deleteMessage($message->getChat()->getId(), $message->getMessageId());
});
$ctx->setChatDataItem("request_confirmation_target", null);
$ctx->getChatDataItem("request_all")->then(function ($requests = []) use ($ctx) {
// Удаление сообщений связанных с запросом
foreach ($requests ?? [] as $_message) $ctx->deleteMessage($_message->getChat()->getId(), $_message->getMessageId());
});
$ctx->setChatDataItem("request_all", []);
$ctx->sendMessage("✅ *Вы зарегистрировались на заявку:* \#$_key", ['reply_markup' => ['remove_keyboard' => true]])->then(function () use ($ctx) {
$ctx->getChatDataItem("request_confirmation")->then(function ($message) use ($ctx) {
$ctx->deleteMessage($message->getChat()->getId(), $message->getMessageId());
});
$ctx->setChatDataItem("request_confirmation_target", null);
$ctx->sendMessage("✅ *Вы зарегистрировались на заявку:* \#$_key", ['reply_markup' => ['remove_keyboard' => true]])->then(function () use ($ctx) {
generateMenu($ctx);
});
// End of the process
$ctx->endConversation();
} else $ctx->sendMessage("❎ *Не удалось принять заявку:* \#$_key", ['reply_markup' => ['remove_keyboard' => true]])->then(function () use ($ctx) {
generateMenu($ctx);
});
// End of the process
$ctx->endConversation();
} else $ctx->sendMessage("❎ *Не удалось принять заявку:* \#$_key", ['reply_markup' => ['remove_keyboard' => true]])->then(function () use ($ctx) {
generateMenu($ctx);
});

View File

@ -1,6 +1,9 @@
[Unit]
Description=Telegram-robot
Wants=network.target
After=syslog.target network-online.target
[Service]
ExecStart=sudo -u www-data /usr/bin/php /var/www/spetsresurs-telegram-registry-requests/mirzaev/spetsresurs/telegram/registry/requests/system/public/robot.php
PIDFile=/var/run/php/telegram-robot.pid
@ -8,3 +11,6 @@ RemainAfterExit=no
RuntimeMaxSec=3600s
Restart=always
RestartSec=5s
[Install]
WantedBy=multi-user.target