PHP code example of thekdesign / fbots

1. Go to this page and download the library: Download thekdesign/fbots 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/ */

    

thekdesign / fbots example snippets


Route::match(['get', 'post'], '/bots', 'ChatController@talk');


    /************************/
    /* -------------------- */
    /*         Chat         */
    /* -------------------- */
    /************************/
    
    // new a fbot
    
        $bots = new FBots($request);
    
    // chat function
    
        $bots->chat('Hey', 'Hello!');
        
    // other chat function ($method is array or object)
    
        $bots->chat('Hey', $method);

    // conversation function (YourConversation is class)
    
        $bots->chat('Hey', startConvesation(new YourConversation));
        
    // listen function
    
        $bots->listen();


    public function publish()
    {
        $pages = new Publish();

        $pages_id = '***';
        $message = 'Hello World';
        $link = 'https://github.com/ThekDesign';
        // $link = 'https://www.youtube.com/';
        $photo = 'https://c1.staticflickr.com/9/8755/16962787241_0f4839004a_b.jpg';
        
        /* 排定發佈,選擇false會得到response後的id,根據個人需要發佈的時機發佈 */
        /* If you set "$publish = false", you will get the id of response. */
        /* You can decide the publish time. */ 
        // reference - https://developers.facebook.com/docs/pages/publishing
        $publish = true;

        $result = $pages->post(
            $pages_id,
            $message,
            $link,
            $photo,
            $publish);

        return $result;
    }

    public function reply()
    {
        $pages = new Publish();


        // type: comments(公開回覆), private_replies(私人訊息)
        $pages->reply('comments', 'page_id', 'message');
    }
    
    public function obtain()
    {
        $pages = new Publish();

        // get the post 拿到那則貼文
        $result = $pages->get('page_id');
        
        // type: comments(公開回覆)
        // get all comments 拿到所有留言
        // $result = $pages->get('page_id', 'comments');

        return $result;
    }
    
    public function send()
    {
        $pages = new Publish();
        
        $pages->finishPost('page_id');
    }