From 4195aca2fea5e97a0ccfec9310b74f89b9bba7a1 Mon Sep 17 00:00:00 2001 From: Charles Teh Date: Tue, 21 Nov 2023 03:10:27 +0800 Subject: [PATCH] Add (facebook) --- .../Controllers/Front/FrontPostController.php | 2 +- app/Http/Controllers/Tests/TestController.php | 12 +++++ app/Jobs/Tasks/PublishIndexPostTask.php | 9 ++++ app/Notifications/PostWasPublished.php | 41 ++++++++++++++++ composer.json | 1 + composer.lock | 49 ++++++++++++++++++- config/services.php | 5 ++ routes/tests.php | 3 ++ 8 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 app/Notifications/PostWasPublished.php diff --git a/app/Http/Controllers/Front/FrontPostController.php b/app/Http/Controllers/Front/FrontPostController.php index b58881e..6a30d35 100644 --- a/app/Http/Controllers/Front/FrontPostController.php +++ b/app/Http/Controllers/Front/FrontPostController.php @@ -28,7 +28,7 @@ public function redirect(Request $request, $slug) public function index(Request $request, $category_slug, $slug) { - $post = Post::where('slug', $slug)->where('status', 'publish')->first(); + $post = Post::where('slug', $slug)->whereIn('status', ['publish','future'])->first(); if (is_null($post)) { return abort(404); diff --git a/app/Http/Controllers/Tests/TestController.php b/app/Http/Controllers/Tests/TestController.php index aa34408..88ae48f 100644 --- a/app/Http/Controllers/Tests/TestController.php +++ b/app/Http/Controllers/Tests/TestController.php @@ -7,9 +7,21 @@ use Illuminate\Http\Request; use LaravelFreelancerNL\LaravelIndexNow\Facades\IndexNow; use LaravelGoogleIndexing; +use App\Models\Post; + +use Illuminate\Support\Facades\Notification; +use App\Notifications\PostWasPublished; class TestController extends Controller { + + public function notification(Request $request) + { + $post = Post::find(1); + + Notification::route('facebook','default')->notify(new PostWasPublished($post)); + } + public function imageGen(Request $request) { $image_url = 'https://cdn.futurewalker.co/post_images_2/whats-next-for-openai-after-ceo-sam-altmans-ouster-1700439234754.jpg'; diff --git a/app/Jobs/Tasks/PublishIndexPostTask.php b/app/Jobs/Tasks/PublishIndexPostTask.php index 115c1e8..413fe0c 100644 --- a/app/Jobs/Tasks/PublishIndexPostTask.php +++ b/app/Jobs/Tasks/PublishIndexPostTask.php @@ -6,6 +6,8 @@ use Exception; use LaravelFreelancerNL\LaravelIndexNow\Facades\IndexNow; use LaravelGoogleIndexing; +use Illuminate\Support\Facades\Notification; +use App\Notifications\PostWasPublished; class PublishIndexPostTask { @@ -35,6 +37,13 @@ public static function handle(int $post_id) } + Notification::route('facebook','default')->notify(new PostWasPublished($post)); + + + + + + } } } diff --git a/app/Notifications/PostWasPublished.php b/app/Notifications/PostWasPublished.php new file mode 100644 index 0000000..1a16e0b --- /dev/null +++ b/app/Notifications/PostWasPublished.php @@ -0,0 +1,41 @@ +post = $post; + } + + /** + * Get the notification's delivery channels. + * + * @return array + */ + public function via(object $notifiable): array + { + return [FacebookPosterChannel::class]; + } + + + public function toFacebookPoster($notifiable) { + return (new FacebookPosterPost(str_first_sentence($this->post->bites)))->withLink(route('front.post', ['slug' => $this->post->slug, 'category_slug' => $this->post->category->slug])); + } +} diff --git a/composer.json b/composer.json index 38a84f6..599f0c6 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,7 @@ "jovix/dataforseo-clientv3": "^1.1", "kalnoy/nestedset": "^6.0", "laravel-freelancer-nl/laravel-index-now": "^1.2", + "laravel-notification-channels/facebook-poster": "^5.2", "laravel-notification-channels/telegram": "^4.0", "laravel/framework": "^10.10", "laravel/horizon": "^5.21", diff --git a/composer.lock b/composer.lock index b6e98f5..4120cc5 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "a045f603e8f362bc593db2f33ea2b04d", + "content-hash": "776af1e07123b90c65fa82b84aec0043", "packages": [ { "name": "artesaos/seotools", @@ -2235,6 +2235,53 @@ ], "time": "2023-02-17T14:44:51+00:00" }, + { + "name": "laravel-notification-channels/facebook-poster", + "version": "5.2.0", + "source": { + "type": "git", + "url": "https://github.com/laravel-notification-channels/facebook-poster.git", + "reference": "46507c45d0a4116955f1c32418a523e8b4bd99f9" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel-notification-channels/facebook-poster/zipball/46507c45d0a4116955f1c32418a523e8b4bd99f9", + "reference": "46507c45d0a4116955f1c32418a523e8b4bd99f9", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": "^7.2", + "illuminate/notifications": "^8.0|^9.0|^10.0", + "illuminate/support": "^8.0|^9.0|^10.0", + "php": "^8.0" + }, + "require-dev": { + "mockery/mockery": "^1.3.3", + "phpunit/phpunit": "~9.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "NotificationChannels\\FacebookPoster\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ahmed Ashraf", + "email": "ahmed29329@gmail.com" + } + ], + "description": "Use notification to create posts on Facebook", + "support": { + "issues": "https://github.com/laravel-notification-channels/facebook-poster/issues", + "source": "https://github.com/laravel-notification-channels/facebook-poster/tree/5.2.0" + }, + "time": "2023-02-13T03:49:26+00:00" + }, { "name": "laravel-notification-channels/telegram", "version": "4.0.0", diff --git a/config/services.php b/config/services.php index 0f58929..e637c06 100644 --- a/config/services.php +++ b/config/services.php @@ -35,4 +35,9 @@ 'token' => env('TELEGRAM_BOT_TOKEN'), ], + 'facebook_poster' => [ + 'page_id' => env('FACEBOOK_PAGE_ID','126935687180121'), + 'access_token' => env('FACEBOOK_ACCESS_TOKEN','EAAiaTW680cMBO6BVskmw2ZCH0Mq9FwY8wg9YlT0bgDZBHUR4CmNfmoALkxdpZCbRSJ9Opn03NqjhnhYq7owVVIZAdYgK3ZCqpTulNmX5JWDjCRzPZAYzo0c8txmVvZCrR2mMgIHgu8tVau9XadaCHxvtmaQAhyueSD2SwXKGsrXNRtZCeq9JZBJv4EwOZBJmCcI4mopBBFtVrJobu68XZAcCniZByN2tH8O6h28wo1ICmAwZD'), + ], + ]; diff --git a/routes/tests.php b/routes/tests.php index 6c4670a..99c045b 100644 --- a/routes/tests.php +++ b/routes/tests.php @@ -34,6 +34,9 @@ | */ +Route::get('/notification', [App\Http\Controllers\Tests\TestController::class, 'notification']); + + Route::get('/image_gen', [App\Http\Controllers\Tests\TestController::class, 'imageGen']); Route::get('/incomplete/post', function (Request $request) {