PHP code example of toolkito / larasap

1. Go to this page and download the library: Download toolkito/larasap library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

toolkito / larasap example snippets


'telegram' => [
    'api_token' => 'your_telegram_bot_token',
    'bot_username' => 'your_bot_username',
    'channel_username' => 'your_channel_username',
    'channel_signature' => 'your_channel_signature',
    'proxy' => false,
],

'x' => [
    'consumer_key' => 'your_consumer_key',
    'consumer_secret' => 'your_consumer_secret',
    'access_token' => 'your_access_token',
    'access_token_secret' => 'your_access_token_secret'
],

'facebook' => [
    'app_id' => 'your_app_id',
    'app_secret' => 'your_app_secret',
    'default_graph_version' => 'v19.0',
    'page_access_token' => 'your_page_access_token',
    'page_id' => 'your_page_id',
    'enable_beta_mode' => false,
    'debug_mode' => false,
]

use Alihesari\Larasap\SendTo;
use Alihesari\Larasap\Facades\X;
use Alihesari\Larasap\Facades\Telegram;
use Alihesari\Larasap\Facades\Facebook;

SendTo::telegram('Hello, I\'m testing Laravel social auto posting');

SendTo::telegram(
    'Check out our website!',
    '',
    [
        [
            [
                'text' => 'Visit Website',
                'url' => 'https://example.com'
            ],
            [
                'text' => 'Follow Us',
                'url' => 'https://t.me/yourchannel'
            ]
        ]
    ]
);

SendTo::telegram(
    'Beautiful sunset! 🌅',
    [
        'type' => 'photo',
        'file' => 'https://example.com/sunset.jpg',
        'width' => 1920,
        'height' => 1080
    ]
);

SendTo::telegram(
    'Listen to our podcast! 🎧',
    [
        'type' => 'audio',
        'file' => 'https://example.com/podcast.mp3',
        'duration' => 1800,
        'performer' => 'Your Podcast Name',
        'title' => 'Episode 1'
    ]
);

SendTo::telegram(
    'Watch our latest video! 🎥',
    [
        'type' => 'video',
        'file' => 'https://example.com/video.mp4',
        'thumb' => 'https://example.com/thumbnail.jpg',
        'duration' => 300,
        'width' => 1920,
        'height' => 1080
    ]
);

SendTo::telegram(
    'Download our whitepaper! 📄',
    [
        'type' => 'document',
        'file' => 'https://example.com/whitepaper.pdf',
        'thumb' => 'https://example.com/thumb.jpg'
    ]
);

SendTo::telegram(
    null,
    [
        'type' => 'location',
        'latitude' => 40.7128,
        'longitude' => -74.0060,
        'live_period' => 3600
    ]
);

SendTo::x('Hello, I\'m testing Laravel social auto posting!');

SendTo::x(
    'Check out these amazing photos! 📸',
    [
        'media' => [
            'path/to/photo1.jpg',
            'path/to/photo2.jpg',
            'path/to/photo3.jpg'
        ]
    ]
);

SendTo::x(
    'Thanks for your feedback!',
    [
        'reply_to' => '1234567890'
    ]
);

SendTo::x(
    'This is a great point!',
    [
        'quote_tweet_id' => '1234567890'
    ]
);

SendTo::x(
    'What\'s your favorite programming language?',
    [
        'poll' => [
            'options' => ['PHP', 'Python', 'JavaScript', 'Java'],
            'duration_minutes' => 1440
        ]
    ]
);

SendTo::x(
    'Check out this amazing place!',
    [
        'location' => [
            'place_id' => 'abc123xyz'
        ]
    ]
);

SendTo::facebook(
    'link',
    [
        'link' => 'https://github.com/alihesari/laravel-social-auto-posting',
        'message' => 'Check out this awesome package!',
        'privacy' => [
            'value' => 'EVERYONE'
        ]
    ]
);

SendTo::facebook(
    'photo',
    [
        'photo' => 'path/to/photo.jpg',
        'message' => 'Beautiful sunset! 🌅',
        'targeting' => [
            'countries' => ['US', 'CA'],
            'age_min' => 18,
            'age_max' => 65
        ]
    ]
);

SendTo::facebook(
    'video',
    [
        'video' => 'path/to/video.mp4',
        'title' => 'My Amazing Video',
        'description' => 'Check out this amazing video!',
        'privacy' => [
            'value' => 'FRIENDS'
        ],
        'scheduled_publish_time' => strtotime('+1 day')
    ]
);

SendTo::facebook(
    'link',
    [
        'link' => 'https://example.com',
        'message' => 'Private post',
        'privacy' => [
            'value' => 'CUSTOM',
            'friends' => 'ALL_FRIENDS',
            'allow' => '123456789',
            'deny' => '987654321'
        ]
    ]
);

SendTo::facebook(
    'photo',
    [
        'photo' => 'path/to/photo.jpg',
        'message' => 'Targeted post',
        'targeting' => [
            'countries' => ['US'],
            'regions' => ['CA'],
            'cities' => ['San Francisco'],
            'age_min' => 21,
            'age_max' => 35,
            'genders' => ['male', 'female'],
            'interests' => ['Technology', 'Programming']
        ]
    ]
);



namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Alihesari\Larasap\Facades\X;
use Alihesari\Larasap\Facades\Telegram;
use Alihesari\Larasap\Facades\Facebook;

class SocialMediaController extends Controller
{
    public function test()
    {
        try {
            // Test Telegram posting
            $telegramResult = Telegram::sendMessage('Test message from Laravel 12');
            
            // Test X (Twitter) posting
            $xResult = X::post('Test tweet from Laravel 12');
            
            // Test Facebook posting
            $facebookResult = Facebook::post([
                'message' => 'Test post from Laravel 12'
            ]);
            
            return response()->json([
                'telegram' => $telegramResult,
                'x' => $xResult,
                'facebook' => $facebookResult
            ]);
        } catch (\Exception $e) {
            return response()->json(['error' => $e->getMessage()], 500);
        }
    }
}

use App\Http\Controllers\SocialMediaController;

Route::get('/test-social-posting', [SocialMediaController::class, 'test'])
    ->name('social.test');
sh
php artisan vendor:publish --tag=larasap
bash
php artisan config:clear
bash
php artisan make:controller SocialMediaController
sh
php artisan serve