Telegram notifications tmp fix

This commit is contained in:
Matteo Gheza 2023-09-02 00:11:24 +02:00
parent 633aaa381f
commit 1e1a224531
4 changed files with 15 additions and 1 deletions

View File

@ -81,12 +81,18 @@ class UpdateAvailabilityWithSchedulesJob implements ShouldQueue
$text = "🚒 Distaccamento operativo con squadra completa";
}
if(!is_null($text)) {
//Find message hash
$hash = md5($text);
$chat_ids = TelegramBotNotifications::where("type_team_state", true)
->whereNot("last_message_hash", $hash)
->get()->pluck('chat_id')->toArray();
foreach ($chat_ids as $chat_id) {
$chat = Telegraph::chat($chat_id);
$chat->message($text)->send();
TelegramBotNotifications::where("chat_id", $chat_id)
->update(["last_message_hash" => $hash]);
}
}
}

View File

@ -16,6 +16,7 @@ class TelegramBotNotifications extends Model
*/
protected $fillable = [
'chat_id',
'type_team_state'
'type_team_state',
'last_message_hash'
];
}

View File

@ -44,12 +44,18 @@ class Availability {
$text = "🧯 Distaccamento operativo per supporto";
}
if(!is_null($text)) {
//Find message hash
$hash = md5($text);
$chat_ids = TelegramBotNotifications::where("type_team_state", true)
->whereNot("last_message_hash", $hash)
->get()->pluck('chat_id')->toArray();
foreach ($chat_ids as $chat_id) {
$chat = Telegraph::chat($chat_id);
$chat->message($text)->send();
TelegramBotNotifications::where("chat_id", $chat_id)
->update(["last_message_hash" => $hash]);
}
}

View File

@ -15,6 +15,7 @@ return new class extends Migration
$table->id();
$table->string('chat_id')->unique();
$table->boolean('type_team_state')->default(true);
$table->varchar('last_message_hash')->nullable();
$table->timestamps();
});
}