Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
72f684dc97 | ||
|
|
dcd7be9816 | ||
|
|
81d1a070b6 |
Vendored
BIN
Binary file not shown.
@@ -0,0 +1,165 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
|
||||
use App\Services\Telegram\TgService;
|
||||
use App\Services\VK\Wall\VkWallService;
|
||||
use Carbon\Carbon;
|
||||
use DefStudio\Telegraph\Facades\Telegraph;
|
||||
use DefStudio\Telegraph\Models\TelegraphChat;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CreateTgPostJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
protected $post_id;
|
||||
protected $title;
|
||||
protected $message;
|
||||
protected $images;
|
||||
protected $videos;
|
||||
protected $documents;
|
||||
protected $publish_date;
|
||||
|
||||
public function __construct(
|
||||
int $post_id, string $title, string $message, array $images = [], array $videos = [], array $documents = [], ?int $publish_date = null
|
||||
)
|
||||
{
|
||||
$this->post_id = $post_id;
|
||||
$this->title = $title;
|
||||
$this->message = $message;
|
||||
$this->images = $images;
|
||||
$this->videos = $videos;
|
||||
$this->documents = $documents;
|
||||
$this->publish_date = $publish_date;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$chat = TelegraphChat::find(1);
|
||||
$baseUrl = config('app.url');
|
||||
$messageIds = [];
|
||||
$captionSent = false;
|
||||
|
||||
// Отправка медиагруппы, если есть изображения или видео
|
||||
if (!empty($this->images) || !empty($this->videos)) {
|
||||
$mediaGroup = $this->createMediaGroup($this->message, $this->images, $this->videos);
|
||||
$response = $chat->mediaGroup($mediaGroup)->send();
|
||||
|
||||
if ($response->successful()) {
|
||||
$messages = $response->json()['result'];
|
||||
$messageIds = array_merge($messageIds, array_map(function($msg) {
|
||||
return $msg['message_id'];
|
||||
}, $messages));
|
||||
Log::info('Media group sent: ' . json_encode($messageIds));
|
||||
$captionSent = true; // Подпись отправлена с медиагруппой
|
||||
} else {
|
||||
Log::error('Failed to send media group: ' . $response->body());
|
||||
}
|
||||
}
|
||||
|
||||
// Отправка документов, если они есть
|
||||
if (!empty($this->documents)) {
|
||||
foreach ($this->documents as $index => $document) {
|
||||
$fullDocument = $baseUrl . $document;
|
||||
if ($index == 0 && !$captionSent) {
|
||||
// Отправка первого документа с подписью, если она еще не отправлена
|
||||
$response = $chat->document($fullDocument)->markdown($this->message)->send();
|
||||
$captionSent = true;
|
||||
} else {
|
||||
// Отправка документа без подписи
|
||||
$response = $chat->document($fullDocument)->send();
|
||||
}
|
||||
|
||||
if ($response->successful()) {
|
||||
$messageId = $response->telegraphMessageId();
|
||||
$messageIds[] = $messageId;
|
||||
Log::info('Document sent: ' . $messageId);
|
||||
} else {
|
||||
Log::error('Failed to send document: ' . $fullDocument . ' - ' . $response->body());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Отправка текста, если ничего другого не отправлено
|
||||
if (!$captionSent) {
|
||||
$response = $chat->markdown($this->message)->send();
|
||||
|
||||
if ($response->successful()) {
|
||||
$messageId = $response->telegraphMessageId();
|
||||
$messageIds[] = $messageId;
|
||||
Log::info('Text message sent: ' . $messageId);
|
||||
} else {
|
||||
Log::error('Failed to send text message: ' . $response->body());
|
||||
}
|
||||
}
|
||||
|
||||
// Вставка записи в базу данных
|
||||
if (!empty($messageIds)) {
|
||||
$tgPostId = $messageIds[0];
|
||||
$mediaContent = count($messageIds) > 1 ? json_encode($messageIds) : null;
|
||||
$this->insertPostRecord($tgPostId, $mediaContent);
|
||||
}
|
||||
}
|
||||
|
||||
private function insertPostRecord($tgPostId, $mediaIds)
|
||||
{
|
||||
$mediaContent = is_array($mediaIds) ? json_encode($mediaIds) : $mediaIds;
|
||||
|
||||
DB::table('posts_tg_posts')->insert([
|
||||
'post_id' => $this->post_id,
|
||||
'tg_post_id' => $tgPostId,
|
||||
'media_content' => $mediaContent,
|
||||
'unchange_time_after' => Carbon::now()->addWeek(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function createMediaGroup($text, $images, $videos)
|
||||
{
|
||||
try {
|
||||
$baseUrl = config('app.url');
|
||||
$mediaItems = [];
|
||||
|
||||
// Добавление изображений
|
||||
foreach ($images as $image) {
|
||||
$mediaItems[] = [
|
||||
'type' => 'photo',
|
||||
'media' => $baseUrl . $image,
|
||||
];
|
||||
}
|
||||
|
||||
Log::info('Media items sent: ' . json_encode($mediaItems));
|
||||
|
||||
// Добавление видео
|
||||
foreach ($videos as $video) {
|
||||
$mediaItems[] = [
|
||||
'type' => 'video',
|
||||
'media' => $baseUrl . $video,
|
||||
];
|
||||
}
|
||||
|
||||
// Ограничение до 10 элементов
|
||||
$mediaItems = array_slice($mediaItems, 0, 10);
|
||||
|
||||
// Установка подписи для первого элемента
|
||||
if (!empty($mediaItems)) {
|
||||
$mediaItems[0]['caption'] = $text;
|
||||
$mediaItems[0]['parse_mode'] = 'Markdown';
|
||||
}
|
||||
|
||||
return $mediaItems;
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Ошибка при публикации в Telegram: ' . $e->getMessage());
|
||||
return [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Enums\LevelEducational;
|
||||
use App\Models\DirectionStudy;
|
||||
use App\Services\Telegram\TgService;
|
||||
use App\Services\Vicon\DirectionStudy\DirectionStudyService;
|
||||
use App\Services\VK\VkService;
|
||||
use Carbon\Carbon;
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
use VK\Client\VKApiClient;
|
||||
|
||||
class UpdateTgPost implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*/
|
||||
public function __construct(
|
||||
readonly private string $text,
|
||||
readonly private array $images = [],
|
||||
readonly private int $post_id,
|
||||
readonly private int|null $publish_date = null,
|
||||
)
|
||||
{}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
$postRelation = DB::table('posts_tg_posts')->select()->where('post_id', $this->post_id)->first();
|
||||
$tgService = new TgService();
|
||||
$tgService->updatePost($postRelation->tg_post_id, $this->text, $this->images, json_decode($postRelation->media_content));
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Ошибка при создании поста: ' . $e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -55,14 +55,12 @@ class UpdateVkPostJob implements ShouldQueue
|
||||
|
||||
$vk_post = $wallService->getPostById($this->post_id);
|
||||
|
||||
// доделать
|
||||
if ($vk_post['attachments']) {
|
||||
Log::info($vk_post);
|
||||
if ($this->getAlbumAttachment($vk_post['attachments'])) {
|
||||
Log::info('вход в аттачментс вк');
|
||||
$album = $this->getAlbumAttachment($vk_post['attachments']);
|
||||
Log::info($album);
|
||||
$albumService->deleteAlbum($album['album']['id'], $this->public_id);
|
||||
if ($vk_post['attachments']) {
|
||||
$pattern = '/\[https:\/\/vk.com\/album-?[0-9]+_([0-9]+)\|.*\]/';
|
||||
preg_match($pattern, $vk_post['text'], $matches);
|
||||
if (isset($matches[1])) {
|
||||
$album_id = $matches[1];
|
||||
$albumService->deleteAlbum($album_id, $this->public_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
BIN
Binary file not shown.
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Telegram;
|
||||
|
||||
use App\Jobs\CreateVkPost;
|
||||
use App\Services\VK\VkService;
|
||||
use Carbon\Carbon;
|
||||
use DefStudio\Telegraph\Handlers\WebhookHandler;
|
||||
use DefStudio\Telegraph\Models\TelegraphBot;
|
||||
use DefStudio\Telegraph\Models\TelegraphChat;
|
||||
use App\Models\Post;
|
||||
//use DefStudio\Telegraph\Keyboard\Button;
|
||||
//use DefStudio\Telegraph\Keyboard\Keyboard;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Services\VK\VkAuthService;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class Handler extends WebhookHandler
|
||||
{
|
||||
public function publish(): void
|
||||
{
|
||||
try {
|
||||
$post = Post::where('status', 'published')
|
||||
->latest('publish_at')->first();
|
||||
|
||||
// if (!$post) {
|
||||
// $this->reply("Нет опубликованных постов для отправки");
|
||||
// return;
|
||||
// }
|
||||
$chat = TelegraphChat::find(4);
|
||||
log::info($chat);
|
||||
$chat->markdown('zov')->send();
|
||||
|
||||
$message = '';
|
||||
|
||||
$message .= "*{$post->title}*\n\n";
|
||||
|
||||
if (is_array($post->content)) {
|
||||
$message .= $this->parseContentBlocks($post->content);
|
||||
} elseif (is_string($post->content)) {
|
||||
$contentBlocks = json_decode($post->content, true);
|
||||
if (is_array($contentBlocks)) {
|
||||
$message .= $this->parseContentBlocks($contentBlocks);
|
||||
} else {
|
||||
$message .= $this->convertToMarkdown($post->content);
|
||||
}
|
||||
} else {
|
||||
$message .= $this->convertToMarkdown((string) $post->content);
|
||||
}
|
||||
|
||||
if ($post->slug) {
|
||||
$url = config('app.url') . "posts/{$post->slug}";
|
||||
$message .= "\n\n[Читать полностью]($url)";
|
||||
}
|
||||
|
||||
// Отправляем сообщение с Markdown
|
||||
// $this->chat->markdown($message)->send();
|
||||
|
||||
// Обработка изображений и отправка сообщения в Telegram
|
||||
if ($post->images) {
|
||||
$images = is_string($post->images) ? json_decode($post->images, true) : $post->images;
|
||||
$baseUrl = config('app.url'); // Базовый URL, например, https://your-domain.com
|
||||
|
||||
if (is_array($images) && !empty($images)) {
|
||||
$mediaGroup = [];
|
||||
foreach ($images as $index => $image) {
|
||||
$mediaItem = [
|
||||
'type' => 'photo',
|
||||
'media' => config('app.url') . 'storage/' . ltrim($image, '/'),
|
||||
];
|
||||
// Добавляем текст только к первому изображению
|
||||
if ($index === 0) {
|
||||
$mediaItem['caption'] = $message; // Основной текст поста
|
||||
$mediaItem['parse_mode'] = 'Markdown'; // Поддержка Markdown
|
||||
}
|
||||
$mediaGroup[] = $mediaItem;
|
||||
}
|
||||
|
||||
// $chat = TelegraphChat::find(0);
|
||||
// $chat->mediaGroup($mediaGroup)->send();
|
||||
|
||||
|
||||
// $page = $chat->page()->content($mediaGroup)->create();
|
||||
// $bot = TelegraphBot::first();
|
||||
// $page = $bot->page()->title($post->title)->content($post->content)->create();
|
||||
// $articleUrl = $page->url();
|
||||
// $url = "https://api.telegram.org/bot7746238162:AAFGi4XwIZ0lnnNL72tlxrmqAgbHmRBMFVs/sendMessage";
|
||||
//
|
||||
// $publishDateTime = strtotime('2025-04-27 20:27:00');
|
||||
// $scheduleDate = Carbon::parse($publishDateTime)->timestamp;
|
||||
//
|
||||
// $data = [
|
||||
// 'chat_id' => $chat,
|
||||
// 'text' => $articleUrl,
|
||||
// 'schedule_date' => $scheduleDate
|
||||
// ];
|
||||
//
|
||||
// $response = Http::post($url, $data);
|
||||
// if ($response->failed()) {
|
||||
// throw new \Exception('Ошибка при планировании поста: ' . $response->body());
|
||||
// }
|
||||
|
||||
|
||||
// $publishDate = $post->publish_at > now() ? $post->publish_at->timestamp : null;
|
||||
// dispatch(new CreateVkPost($post->title, $message, $images, $post->id, $publishDate));
|
||||
|
||||
} else {
|
||||
$this->chat->markdown($message)->send();
|
||||
}
|
||||
} else {
|
||||
// Если нет изображений, отправляем только текст
|
||||
Log::info('dasdsa');
|
||||
$this->chat->markdown($message)->send();
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Ошибка при публикации в Telegram: ' . $e->getMessage());
|
||||
$this->reply("Произошла ошибка при отправке поста");
|
||||
}
|
||||
}
|
||||
|
||||
private function parseContentBlocks(array $blocks): string
|
||||
{
|
||||
$text = '';
|
||||
foreach ($blocks as $block) {
|
||||
$content = $this->decodeUnicode($block['data']['content'] ?? '');
|
||||
switch ($block['type'] ?? '') {
|
||||
case 'heading':
|
||||
$text .= "*" . $content . "*\n\n";
|
||||
break;
|
||||
case 'paragraph':
|
||||
$text .= $this->convertToMarkdown($content) . "\n\n";
|
||||
break;
|
||||
case 'list':
|
||||
if (isset($block['data']['items'])) {
|
||||
foreach ($block['data']['items'] as $item) {
|
||||
$text .= "- " . $item . "\n";
|
||||
}
|
||||
$text .= "\n";
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$text .= $content . "\n\n";
|
||||
break;
|
||||
}
|
||||
}
|
||||
return trim($text);
|
||||
}
|
||||
|
||||
private function convertToMarkdown(string $text): string
|
||||
{
|
||||
// Декодируем HTML-сущности
|
||||
$text = html_entity_decode($text, ENT_QUOTES, 'UTF-8');
|
||||
$text = $this->decodeUnicode($text);
|
||||
$text = preg_replace('/<p>(.*?)<\/p>/', '$1', $text);
|
||||
$text = preg_replace('/<b>(.*?)<\/b>/', '*$1*', $text);
|
||||
$text = preg_replace('/<i>(.*?)<\/i>/', '_$1_', $text);
|
||||
$text = preg_replace('/<strong>(.*?)<\/strong>/', '*$1*', $text);
|
||||
$text = preg_replace('/<em>(.*?)<\/em>/', '_$1_', $text);
|
||||
// Очищаем от HTML-тегов, декодируем оставшиеся сущности и экранируем спецсимволы для MarkdownV2
|
||||
return strip_tags($text);
|
||||
}
|
||||
|
||||
private function decodeUnicode(string $text): string
|
||||
{
|
||||
return preg_replace_callback(
|
||||
'/\\\\u([0-9a-fA-F]{4})/',
|
||||
function ($match) {
|
||||
return mb_convert_encoding(pack('H*', $match[1]), 'UTF-8', 'UCS-2BE');
|
||||
},
|
||||
$text
|
||||
);
|
||||
}
|
||||
|
||||
protected function handleUnknownCommand(string|\Illuminate\Support\Stringable $command): void
|
||||
{
|
||||
$this->reply("Неизвестная команда: {$command}");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,214 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Telegram;
|
||||
|
||||
use DefStudio\Telegraph\Models\TelegraphChat;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class TgService
|
||||
{
|
||||
// public function createPost($text, $images, $videos, $documents, $publishDate)
|
||||
// {
|
||||
// $chat = TelegraphChat::find(4);
|
||||
// Log::info($images);
|
||||
// if ($images !== []){
|
||||
// $images = array_slice($images, 0, 10);
|
||||
// $mediaGroup = $this->createMediaGroup($text, $images);
|
||||
// $response = $chat->mediaGroup($mediaGroup)->send();
|
||||
// if ($response->successful()) {
|
||||
// $messages = $response->json()['result'];
|
||||
// $mediaGroupId = $messages[0]['message_id'];
|
||||
// $messageIds = array_map(function($msg) {
|
||||
// return $msg['message_id'];
|
||||
// }, $messages);
|
||||
// return [$mediaGroupId, $messageIds];
|
||||
// }
|
||||
// }
|
||||
// else{
|
||||
// $response = $chat->markdown($text)->send();
|
||||
// if ($response->successful()) {
|
||||
// $messageId = $response->telegraphMessageId();
|
||||
// }
|
||||
// return [$messageId, null];
|
||||
// }
|
||||
// }
|
||||
|
||||
public function createPost($text, $images, $videos, $documents, $publishDate)
|
||||
{
|
||||
$chat = TelegraphChat::find(4);
|
||||
Log::info($images);
|
||||
Log::info($videos);
|
||||
Log::info($documents);
|
||||
|
||||
if (!empty($images) || !empty($videos)) {
|
||||
// Создаем медиагруппу из изображений и видео (до 10 элементов)
|
||||
$mediaItems = [];
|
||||
foreach ($images as $image) {
|
||||
$mediaItems[] = ['type' => 'photo', 'media' => $image];
|
||||
}
|
||||
foreach ($videos as $video) {
|
||||
$mediaItems[] = ['type' => 'video', 'media' => $video];
|
||||
}
|
||||
$mediaItems = array_slice($mediaItems, 0, 10);
|
||||
if (!empty($mediaItems)) {
|
||||
$mediaItems[0]['caption'] = $text;
|
||||
$mediaItems[0]['parse_mode'] = 'Markdown';
|
||||
}
|
||||
$response = $chat->mediaGroup($mediaItems)->send();
|
||||
if ($response->successful()) {
|
||||
$messages = $response->json()['result'];
|
||||
$mainMessageId = $messages[0]['message_id'];
|
||||
$mediaMessageIds = array_map(function($msg) {
|
||||
return $msg['message_id'];
|
||||
}, $messages);
|
||||
}
|
||||
|
||||
// // Отправляем документы
|
||||
// $documentMessageIds = [];
|
||||
// foreach ($documents as $document) {
|
||||
// $response = $chat->document($document)->caption($text)->parseMode('Markdown')->send();
|
||||
// if ($response->successful()) {
|
||||
// $documentMessageIds[] = $response->telegraphMessageId();
|
||||
// }
|
||||
// }
|
||||
// $allMessageIds = array_merge($mediaMessageIds, $documentMessageIds);
|
||||
return [$mainMessageId, $mediaMessageIds];
|
||||
} elseif (!empty($documents)) {
|
||||
// Отправляем только документы
|
||||
$documentMessageIds = [];
|
||||
$mainMessageId = null;
|
||||
foreach ($documents as $index => $document) {
|
||||
$response = $chat->document($document)->caption($text)->parseMode('Markdown')->send();
|
||||
if ($response->successful()) {
|
||||
$messageId = $response->telegraphMessageId();
|
||||
$documentMessageIds[] = $messageId;
|
||||
if ($index == 0) {
|
||||
$mainMessageId = $messageId;
|
||||
}
|
||||
}
|
||||
}
|
||||
return [$mainMessageId, $documentMessageIds];
|
||||
} else {
|
||||
// Отправляем только текст
|
||||
$response = $chat->markdown($text)->send();
|
||||
if ($response->successful()) {
|
||||
$messageId = $response->telegraphMessageId();
|
||||
return [$messageId, [$messageId]];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function updatePost($post_id, $text, $images, $media_ids)
|
||||
{
|
||||
$chat = TelegraphChat::find(1);
|
||||
|
||||
if ($images !== []) {
|
||||
try {
|
||||
// if (count($images) !== count($media_ids)) {
|
||||
// foreach ($media_ids as $messageId) {
|
||||
// $chat->deleteMessage($messageId)->send();
|
||||
// }
|
||||
//
|
||||
// $modifiedText = $text . "\n\n_(сообщение изменено)_";
|
||||
//
|
||||
// $result = $this->createPost($modifiedText, $images);
|
||||
//
|
||||
// return [
|
||||
// 'post_id' => $result[0],
|
||||
// 'media_ids' => $result[1] ?? []
|
||||
// ];
|
||||
// }
|
||||
|
||||
$firstMessageId = $media_ids[0];
|
||||
$chat->editCaption($firstMessageId)
|
||||
->markdown($text)
|
||||
->send();
|
||||
|
||||
// $messageIds = [];
|
||||
// $firstMessageId = null;
|
||||
|
||||
// foreach ($media_ids as $index => $messageId) {
|
||||
// if (!isset($images[$index])) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// $newMedia = $images[$index];
|
||||
// $response = $chat->editMedia($messageId)
|
||||
// ->photo(config('app.url') . $newMedia)
|
||||
// ->send();
|
||||
//
|
||||
// if ($response->successful()) {
|
||||
// $updatedMessageId = $response->json()['result']['message_id'];
|
||||
// $messageIds[] = $updatedMessageId;
|
||||
//
|
||||
// if ($index === 0) {
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Ошибка при изменении поста ' . $e->getMessage());
|
||||
return []; // Или null/исключение
|
||||
}
|
||||
} else {
|
||||
// Для текстовых сообщений
|
||||
$chat->edit($post_id)
|
||||
->markdown($text)
|
||||
->send();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// $chat = TelegraphChat::find(4);
|
||||
// if ($images !== []){
|
||||
// try {
|
||||
// Log::info(json_encode($media_ids));
|
||||
// $firstMessageId = $media_ids[0];
|
||||
// foreach ($media_ids as $index => $messageId) {
|
||||
// $newMedia = $images[$index];
|
||||
// Log::info($newMedia);
|
||||
// Log::info($messageId);
|
||||
// $chat->editMedia($messageId)
|
||||
// ->photo(config('app.url') . $newMedia)
|
||||
// ->send();
|
||||
// }
|
||||
// $chat->editCaption($firstMessageId)
|
||||
// ->markdown($text)
|
||||
// ->send();
|
||||
//
|
||||
// } catch (\Exception $e) {
|
||||
// Log::error('Ошибка при изменении поста ' . $e->getMessage());
|
||||
// }
|
||||
// }
|
||||
// else{
|
||||
// $chat->edit($post_id)->markdown($text)->send();
|
||||
// }
|
||||
}
|
||||
|
||||
private function createMediaGroup($text, $images)
|
||||
{
|
||||
try {
|
||||
$baseUrl = config('app.url');
|
||||
|
||||
if (is_array($images) && !empty($images)) {
|
||||
$mediaGroup = [];
|
||||
foreach ($images as $index => $image) {
|
||||
$mediaItem = [
|
||||
'type' => 'photo',
|
||||
'media' => $baseUrl . $image,
|
||||
// https://crack-gar-specially.ngrok-free.app/storage/posts/gallery/01JT5R37Z05S119VCRRFEADSAG.jpg
|
||||
];
|
||||
|
||||
if ($index === 0) {
|
||||
$mediaItem['caption'] = $text;
|
||||
$mediaItem['parse_mode'] = 'Markdown';
|
||||
}
|
||||
$mediaGroup[] = $mediaItem;
|
||||
}
|
||||
return $mediaGroup;
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Ошибка при публикации в Telegram: ' . $e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,7 +102,16 @@ class VkService
|
||||
$postRelation = DB::table('posts_vk_posts')->select()->where('post_id', $post_id)->first();
|
||||
$post_id = $postRelation->vk_post_id;
|
||||
$vk_post = $this->getPostById($post_id);
|
||||
$this->wallService->deletePost($vk_post['id']);
|
||||
|
||||
$pattern = '/\[https:\/\/vk.com\/album-?[0-9]+_([0-9]+)\|.*\]/';
|
||||
preg_match($pattern, $vk_post['text'], $matches);
|
||||
if (isset($matches[1])) {
|
||||
$album_id = $matches[1];
|
||||
$this->albumService->deleteAlbum($album_id, $this->public_id);
|
||||
$this->wallService->deletePost($vk_post['id']);
|
||||
} else {
|
||||
$this->wallService->deletePost($vk_post['id']);
|
||||
}
|
||||
}
|
||||
|
||||
public function createAlbum(string $title, $images)
|
||||
|
||||
@@ -0,0 +1,214 @@
|
||||
<?php
|
||||
|
||||
use DefStudio\Telegraph\Telegraph;
|
||||
|
||||
return [
|
||||
/*
|
||||
* Telegram api base url, it can be overridden
|
||||
* for self-hosted servers
|
||||
*/
|
||||
'telegram_api_url' => 'https://api.telegram.org/',
|
||||
|
||||
/*
|
||||
* Sets Telegraph messages default parse mode
|
||||
* allowed values: html|markdown|MarkdownV2
|
||||
*/
|
||||
'default_parse_mode' => Telegraph::PARSE_HTML,
|
||||
|
||||
'webhook' => [
|
||||
/*
|
||||
* Sets the webhook URL that will be exposed by the server,
|
||||
* this can be customized or entirely disabled (by setting it to NULL)
|
||||
*/
|
||||
'url' => '/telegraph/{token}/webhook',
|
||||
|
||||
/*
|
||||
* Sets the handler to be used when Telegraph
|
||||
* receives a new webhook call.
|
||||
*
|
||||
* For reference, see https://docs.defstudio.it/telegraph/webhooks/overview
|
||||
*/
|
||||
'handler' => \App\Services\Telegram\Handler::class,
|
||||
|
||||
/*
|
||||
* Middleware to be applied to the webhook route
|
||||
*/
|
||||
'middleware' => [],
|
||||
|
||||
/*
|
||||
* Sets a custom domain when registering a webhook. This will allow a local telegram bot api server
|
||||
* to reach the webhook. Disabled by default
|
||||
*
|
||||
* For reference, see https://core.telegram.org/bots/api#using-a-local-bot-api-server
|
||||
*/
|
||||
// 'domain' => 'http://my.custom.domain',
|
||||
|
||||
/*
|
||||
* If enabled, unknown webhook commands are
|
||||
* reported as exception in application logs
|
||||
*/
|
||||
'report_unknown_commands' => env('TELEGRAPH_REPORT_UNKNOWN_COMMANDS', true),
|
||||
|
||||
/**
|
||||
* secret token to be sent in a X-Telegram-Bot-Api-Secret-Token header
|
||||
* to verify the authenticity of the webhook
|
||||
*/
|
||||
'secret' => env('TELEGRAPH_WEBHOOK_SECRET'),
|
||||
|
||||
/**
|
||||
* maximum allowed simultaneous connections to the webhook (defaults to 40)
|
||||
*/
|
||||
'max_connections' => env('TELEGRAPH_WEBHOOK_MAX_CONNECTIONS', 40),
|
||||
|
||||
/**
|
||||
* List of event types for which the webhook should fire.
|
||||
*
|
||||
* Specify a null to receive all update types except `chat_member`, `message_reaction`,
|
||||
* and `message_reaction_count` (by default).
|
||||
*
|
||||
* @see https://core.telegram.org/bots/api#setwebhook
|
||||
*/
|
||||
'allowed_updates' => null,
|
||||
|
||||
/*
|
||||
* If enabled, Telegraph dumps received
|
||||
* webhook messages to logs
|
||||
*/
|
||||
'debug' => env('TELEGRAPH_WEBHOOK_DEBUG', false),
|
||||
],
|
||||
|
||||
/*
|
||||
* Sets HTTP request timeout when interacting with Telegram servers
|
||||
*/
|
||||
'http_timeout' => env('TELEGRAPH_HTTP_TIMEOUT', 30),
|
||||
|
||||
/*
|
||||
* Sets HTTP connection request timeout when interacting with Telegram servers
|
||||
*/
|
||||
'http_connection_timeout' => env('TELEGRAPH_HTTP_CONNECTION_TIMEOUT', 10),
|
||||
|
||||
'security' => [
|
||||
/*
|
||||
* if enabled, allows callback queries from unregistered chats
|
||||
*/
|
||||
'allow_callback_queries_from_unknown_chats' => true,
|
||||
|
||||
/*
|
||||
* if enabled, allows messages and commands from unregistered chats
|
||||
*/
|
||||
'allow_messages_from_unknown_chats' => true,
|
||||
|
||||
/*
|
||||
* if enabled, store unknown chats as new TelegraphChat models
|
||||
*/
|
||||
'store_unknown_chats_in_db' => true,
|
||||
],
|
||||
|
||||
/*
|
||||
* Set model class for both TelegraphBot and TelegraphChat,
|
||||
* to allow more customization.
|
||||
*
|
||||
* Bot model must be or extend `DefStudio\Telegraph\Models\TelegraphBot::class`
|
||||
* Chat model must be or extend `DefStudio\Telegraph\Models\TelegraphChat::class`
|
||||
*/
|
||||
'models' => [
|
||||
'bot' => DefStudio\Telegraph\Models\TelegraphBot::class,
|
||||
'chat' => DefStudio\Telegraph\Models\TelegraphChat::class,
|
||||
],
|
||||
|
||||
'storage' => [
|
||||
/**
|
||||
* Default storage driver to be used for Telegraph data
|
||||
*/
|
||||
'default' => 'file',
|
||||
|
||||
'stores' => [
|
||||
'file' => [
|
||||
/**
|
||||
* Telegraph cache driver to be used, must implement
|
||||
* DefStudio\Telegraph\Contracts\StorageDriver contract
|
||||
*/
|
||||
'driver' => \DefStudio\Telegraph\Storage\FileStorageDriver::class,
|
||||
|
||||
/*
|
||||
* Laravel Storage disk to use. See /config/filesystems/disks for available disks
|
||||
* If 'null', Laravel default store will be used,
|
||||
*/
|
||||
'disk' => 'local',
|
||||
|
||||
/**
|
||||
* Folder inside filesystem to be used as root for Telegraph storage
|
||||
*/
|
||||
'root' => 'telegraph',
|
||||
],
|
||||
'cache' => [
|
||||
/**
|
||||
* Telegraph cache driver to be used, must implement
|
||||
* DefStudio\Telegraph\Contracts\StorageDriver contract
|
||||
*/
|
||||
'driver' => \DefStudio\Telegraph\Storage\CacheStorageDriver::class,
|
||||
|
||||
/*
|
||||
* Laravel Cache store to use. See /config/cache/stores for available stores
|
||||
* If 'null', Laravel default store will be used,
|
||||
*/
|
||||
'store' => null,
|
||||
|
||||
/*
|
||||
* Prefix to be prepended to cache keys
|
||||
*/
|
||||
'key_prefix' => 'tgph',
|
||||
],
|
||||
],
|
||||
],
|
||||
|
||||
/**
|
||||
* Attachment validation rules, Telegram bot API defaults are set
|
||||
* can be changed to match higher limits when using a local bot
|
||||
* API server (ref. https://core.telegram.org/bots/api#using-a-local-bot-api-server)
|
||||
*/
|
||||
'attachments' => [
|
||||
'thumbnail' => [
|
||||
'max_size_kb' => 200,
|
||||
'max_height_px' => 320,
|
||||
'max_width_px' => 320,
|
||||
'allowed_ext' => ['jpg'],
|
||||
],
|
||||
'photo' => [
|
||||
'max_size_mb' => 10,
|
||||
'max_ratio' => 20,
|
||||
'height_width_sum_px' => 10000,
|
||||
],
|
||||
'animation' => [
|
||||
'max_size_mb' => 50,
|
||||
],
|
||||
'video' => [
|
||||
'max_size_mb' => 50,
|
||||
],
|
||||
'audio' => [
|
||||
'max_size_mb' => 50,
|
||||
],
|
||||
'document' => [
|
||||
'max_size_mb' => 50,
|
||||
],
|
||||
'sticker' => [
|
||||
'max_size_mb' => 50,
|
||||
],
|
||||
],
|
||||
|
||||
/*
|
||||
* Sets preferences for commands
|
||||
*/
|
||||
'commands' => [
|
||||
/*
|
||||
* Defines a list of characters that are the identifier of a command sent to the chat.
|
||||
*
|
||||
* Default is `/`
|
||||
*/
|
||||
'start_with' => ['/'],
|
||||
],
|
||||
|
||||
'payments' => [
|
||||
'provider_token' => env('TELEGRAPH_PAYMENT_PROVIDER_TOKEN', ''),
|
||||
],
|
||||
];
|
||||
Reference in New Issue
Block a user