PHP code example of backtik-ch / laravel-kchat-sdk

1. Go to this page and download the library: Download backtik-ch/laravel-kchat-sdk 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/ */

    

backtik-ch / laravel-kchat-sdk example snippets


use Backtik\KChat\Facades\KChat;

$post = KChat::messages()
    ->toChannel('channel_id')
    ->message('Hello')
    ->send();

KChat::messages()
    ->toChannel('channel_id')
    ->message('**Hello**')
    ->send();

KChat::messages()
    ->toUserId('user_id')
    ->message('Hello')
    ->send();

KChat::messages()
    ->toUsername('simon')
    ->message('**Hello**')
    ->send();

KChat::messages()
    ->toChannel('channel_id')
    ->message('Reply')
    ->inThread('root_post_id')
    ->send();

$post = KChat::messages()->find('post_id');
$thread = KChat::messages()->thread('post_id');
$updated = KChat::messages()->update('post_id', 'Updated message');
$deleted = KChat::messages()->delete('post_id');

KChat::messages()
    ->toChannel('channel_id')
    ->message('Hello')
    ->asBot(name: 'Deploy Bot', avatarUrl: 'https://example.com/avatar.png')
    ->send();

KChat::messages()
    ->toChannel('channel_id')
    ->message('Build failed')
    ->attachment(
        color: '#d92d20',
        title: 'CI',
        text: 'Tests failed',
    )
    ->send();

KChat::messages()
    ->toChannel('channel_id')
    ->message('Report')
    ->attachFile('/tmp/report.pdf')
    ->send();

$user = KChat::users()->find('user_id');
$user = KChat::users()->findByUsername('simon');
$user = KChat::users()->findByEmail('[email protected]');
$users = KChat::users()->list();

use Backtik\KChat\Exceptions\KChatNotFoundException;
use Backtik\KChat\Exceptions\KChatRequestException;
use Backtik\KChat\Facades\KChat;

try {
    $post = KChat::messages()
        ->toUsername('simon')
        ->message('**Hello**')
        ->send();
} catch (KChatNotFoundException $exception) {
    // user or post not found
} catch (KChatRequestException $exception) {
    // request failed
}

use Backtik\KChat\Facades\KChat;

KChat::messages()
    ->toChannel('channel_id')
    ->message('Hello from the local SDK')
    ->send();

use Backtik\KChat\Facades\KChat;
use Illuminate\Support\Facades\Route;

Route::get('/test-kchat', function () {
    $post = KChat::messages()
        ->toChannel('channel_id')
        ->message('Test from Laravel')
        ->send();

    return $post->raw();
});
bash
php artisan vendor:publish --tag="laravel-kchat-sdk-config"
bash
php artisan boost:install
bash
php artisan vendor:publish --tag="kchat-sdk-config"
bash
php artisan tinker
bash
composer dump-autoload