SendTelegramGroupMessageJob.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Jobs;
  3. use App\Jobs\Concerns\HandlesTelegramJobFailure;
  4. use Illuminate\Bus\Queueable;
  5. use Illuminate\Contracts\Queue\ShouldQueue;
  6. use Illuminate\Foundation\Bus\Dispatchable;
  7. use Illuminate\Queue\InteractsWithQueue;
  8. use Illuminate\Queue\SerializesModels;
  9. use Illuminate\Support\Facades\Log;
  10. use App\Services\BaseService;
  11. class SendTelegramGroupMessageJob implements ShouldQueue
  12. {
  13. use Dispatchable, HandlesTelegramJobFailure, InteractsWithQueue, Queueable, SerializesModels;
  14. public $tries = 1;
  15. public $timeout = 85;
  16. public $chatId;
  17. public $text;
  18. public $buttons;
  19. public $image;
  20. public $isTop;
  21. public $separator;
  22. /**
  23. * @param string $chatId
  24. * @param string $text
  25. * @param array $buttons
  26. * @param string|null $image
  27. * @param string $separator 分隔符
  28. */
  29. public function __construct($text, $buttons = [], $image = null, $isTop = false, $separator = "\n")
  30. {
  31. $this->text = $text;
  32. $this->buttons = $buttons;
  33. $this->image = $image;
  34. $this->isTop = $isTop;
  35. $this->separator = $separator;
  36. }
  37. public function handle()
  38. {
  39. try {
  40. BaseService::bettingGroupNotice($this->text, $this->buttons, $this->image, $this->isTop, $this->separator);
  41. Log::channel('issue')->info('Telegram群消息发送成功', [
  42. 'attempt' => $this->attempts(),
  43. 'text_length' => strlen((string)$this->text),
  44. 'has_image' => !empty($this->image),
  45. 'is_top' => $this->isTop,
  46. ]);
  47. } catch (\Throwable $exception) {
  48. $this->handleTelegramJobFailure($exception, 'Telegram群消息发送失败', [
  49. 'text_length' => strlen((string)$this->text),
  50. 'has_image' => !empty($this->image),
  51. 'is_top' => $this->isTop,
  52. ], false);
  53. }
  54. }
  55. }