PHPackages                             thekdesign/fbots - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. thekdesign/fbots

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

thekdesign/fbots
================

chatbot

0.2.4(8y ago)18161MITPHPPHP &gt;=7.0.0

Since Jan 2Pushed 8y agoCompare

[ Source](https://github.com/ThekDesign/FBots)[ Packagist](https://packagist.org/packages/thekdesign/fbots)[ RSS](/packages/thekdesign-fbots/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (3)Versions (11)Used By (0)

FBots
=====

[](#fbots)

[![stable version](https://camo.githubusercontent.com/c90b55a3c5508eae184f05304cc48b8d77d002760ac8d9d888030cbe60be79e9/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f737461626c652d302e322e342d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/thekdesign/fbots)[![unstable version](https://camo.githubusercontent.com/ed4d93ff16e9ac9bae7b35855ff96b005fab47c9555042b52386239319fb1a14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f756e737461626c652d6465762d6f72616e67652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/thekdesign/fbots)[![php version](https://camo.githubusercontent.com/8090d88ff8978f9b0b1d596ec2638c1b48c5e21a43f929f66488583b7094ed06/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d2533453d372e302e302d626c75652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/thekdesign/fbots)[![GitHub license](https://camo.githubusercontent.com/820c471a9374d53c893e8c95cd2e3b389aa358c21530cfb8ece1b1b58706688b/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f5468656b44657369676e2f46426f74732e7376673f7374796c653d666c61742d737175617265)](https://github.com/ThekDesign/FBots/blob/master/LICENSE)

reference - [BotMan](https://botman.io/)
reference - [Messenger](https://developers.facebook.com/docs/messenger-platform)
reference - [Pages](https://developers.facebook.com/docs/pages)

開始使用 Getting Started
--------------------

[](#開始使用-getting-started)

- 產生一個空的 laravel 專案
- new a laravel project

```
laravel new fbots

```

or

```
composer create-project --prefer-dist laravel/laravel fbots

```

- 有一個 facebook developer 的帳號
- have a facebook developer account
- 擁有一個 https 的網址 (推薦使用 heroku 部署)
- have a https web (recommend heroku)

### 必要條件 Prerequisites

[](#必要條件-prerequisites)

- 確定你有一個 facebook developer 帳號，並新建一個應用程式
- make sure that you have a facebook developer account and create an application

### 安裝及設定 Install and Settings

[](#安裝及設定-install-and-settings)

```
composer require thekdesign/fbots

```

到 .env 檔內新增三個設定值 add three values in .env

```
//粉絲專頁的權杖
FACEBOOK_TOKEN = "your-facebook-page-token"

//自己設定，主要是拿來驗證webhook
FACEBOOK_VERIFICATION = "your-facebook-verification-token"

//應用程式的密鑰
FACEBOOK_APP_SECRET = "your-facebook-app-secret"

```

---

快速使用 Quick Start
----------------

[](#快速使用-quick-start)

**安裝所有元件 install all**

```
composer require thekdesign/fbots

```

新增一個 Controller 再新增一個 function
new a Controller and new a function

**Controller**

```
class ChatController extends Controller
{
    public function talk(Request $request)
    {

        /*************************************************************/
        /*                            config                         */
        /* --------------------------------------------------------- */
        /* token         : facebook page's access_token              */
        /* app_secret    : application's secret                      */
        /* verification  : to connect webhook, so it depends on you  */
        /* --------------------------------------------------------- */
        /*************************************************************/

        // 記得去獲取永久不過期的 facebook page's access_token
        // get the facebook page's access_token that never expires

        $config = [
            'facebook' => [
                'token' => env('FACEBOOK_TOKEN'),
                'app_secret' => env('FACEBOOK_APP_SECRET'),
                'verification' => env('FACEBOOK_VERIFICATION'),
            ]
        ];

        $bots = new FBots($request, $config);

        $bots->chat('Hey', 'Hello');

        $bots->listen();

    }
}

```

**Route**

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

```

**VerifyCsrfToken**

reference -

將你的route加入白名單
Excluding URIs From CSRF Protection

### Messenger 設定 Messenger Settings

[](#messenger-設定-messenger-settings)

參考

reference

功能說明 functions
--------------

[](#功能說明-functions)

詳細功能請查閱

reference

---

**聊天機器人**
**ChatBots**

```

    /************************/
    /* -------------------- */
    /*         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();

```

```
        $bots = new FBots($request);

        // 按鈕形式 button template
        $button = ButtonTemplate::create('123')
            ->addButtons([
                    ElementButton::create('Tell me more')->type("postback")->payload("tellmemore"),
                    ElementButton::create('visit')->url("http://botman.io/")
                ]
            );

        // 滑動瀏覽 generic template
        $generic = GenericTemplate::create()
            ->addImageAspectRatio(GenericTemplate::RATIO_SQUARE)
            ->addElements([
                Element::create('BotMan Documentation')
                    ->subtitle('All about BotMan')
                    ->image('http://botman.io/img/botman-body.png')
                    ->addButton(ElementButton::create('visit')->url('http://botman.io'))
                    ->addButton(ElementButton::create('tell me more')
                        ->payload('tellmemore')->type('postback')),
                Element::create('BotMan Laravel Starter')
                    ->subtitle('This is the best way to start with Laravel and BotMan')
                    ->image('http://botman.io/img/botman-body.png')
                    ->addButton(ElementButton::create('visit')
                        ->url('https://github.com/mpociot/botman-laravel-starter')
                    )
            ]);

        //列表形式 list template
        $list = ListTemplate::create()
            ->useCompactView()
            ->addGlobalButton(ElementButton::create('view more')->url('http://test.at'))
            ->addElements([
                Element::create('BotMan Documentation')
                    ->subtitle('All about BotMan')
                    ->image('http://botman.io/img/botman-body.png')
                    ->addButton(ElementButton::create('tell me more')
                        ->payload('tellmemore')->type('postback')),

                Element::create('BotMan Laravel Starter')
                    ->subtitle('This is the best way to start with Laravel and BotMan')
                    ->image('http://botman.io/img/botman-body.png')
                    ->addButton(ElementButton::create('visit')
                        ->url('https://github.com/mpociot/botman-laravel-starter')
                    )
            ]);

        // 點餐形式 receipt template
        $receipt = ReceiptTemplate::create()
            ->recipientName('Christoph Rumpel')
            ->merchantName('BotMan GmbH')
            ->orderNumber('342343434343')
            ->timestamp('1428444852')
            ->orderUrl('http://test.at')
            ->currency('USD')
            ->paymentMethod('VISA')
            ->addElement(ReceiptElement::create('T-Shirt Small')->price(15.99)->image('http://botman.io/img/botman-body.png'))
            ->addElement(ReceiptElement::create('Sticker')->price(2.99)->image('http://botman.io/img/botman-body.png'))
            ->addAddress(ReceiptAddress::create()
                ->street1('Watsonstreet 12')
                ->city('Bot City')
                ->postalCode(100000)
                ->state('Washington AI')
                ->country('Botmanland')
            )
            ->addSummary(ReceiptSummary::create()
                ->subtotal(18.98)
                ->shippingCost(10)
                ->totalTax(15)
                ->totalCost(23.98)
            )
            ->addAdjustment(ReceiptAdjustment::create('Laravel Bonus')->amount(5));

        // 圖片形式 image template
        $image = MediaTemplate::create()
            ->element(MediaAttachmentElement::create('image')
                ->attachmentId('1543527005693234')
                ->addButton(ElementButton::create('Tell me more')
                    ->type('postback')
                    ->payload('Tell me more'))
                ->addButton(ElementButton::create('Documentation')
                    ->url('https://botman.io/')));

        //影片形式 video template
       $video = MediaTemplate::create()
            ->element(MediaUrlElement::create('video')
                ->url('https://www.facebook.com/liechteneckers/videos/10155225087428922/')
                ->addButtons([
                    ElementButton::create('Web URL')
                        ->url('http://liechtenecker.at'),
                    ElementButton::create('payload')
                        ->type('postback')
                        ->payload('test'),
                ]));

        $bots->chat('Hey', 'Hello!');

        // 加入你想要的 add whatever you want
        // $bots->chat('give me button', $button);
        // $bots->chat('give me generic', $generic);
        // $bots->chat('give me list', $list);
        // $bots->chat('give me receipt', $receipt);
        // $bots->chat('give me image', $image);
        // $bots->chat('give me video', $video);

        $bots->listen();

```

---

**粉絲團**
**Pages**

```

        /***************************/
        /* ----------------------- */
        /*         Publish         */
        /* ----------------------- */
        /***************************/

    // new a publish

        $pages = new Publish();

    /***********************************************************************/
    /*                          post method                                */
    /* ------------------------------------------------------------------- */
    /* $pages_id     : id from your facebook pages        | string         */
    /* $message      : write what you want to post        | string         */
    /* $link         : if you want to post include links  | string         */
    /* $photo        : if you want to post include photos | string(url)    */
    /* $published    : decide that publish now or later   | string(url)    */
    /* $publish_time : decide that publish time           | Unix timestamp */
    /* ------------------------------------------------------------------- */
    /***********************************************************************/

    // post function

    // 圖片請使用url
    // use url for photo

        $pages->post($pages_id, $message);

    /*************************************************************/
    /*                          get method                       */
    /* --------------------------------------------------------- */
    /* $page_id  : the post's id                        | string */
    /* $type     : get information from pages or posts  | string */
    /* --------------------------------------------------------- */
    /*************************************************************/

    // get function

        $pages->get($page_id);

    /************************************************************************/
    /*                               reply method                           */
    /* -------------------------------------------------------------------- */
    /* $type     : comments, private_replies(Permissions problems) | string */
    /* $page_id  : the post's id                                   | string */
    /* $message  : write what you want to reply                    | string */
    /* -------------------------------------------------------------------- */
    /************************************************************************/

    // reply function

        $pages->reply($type, $post_id, $message);

    /**********************************************************/
    /*                    autoReply method                    */
    /* ------------------------------------------------------ */
    /* $type_reply : comments, private_replies    | string    */
    /* $post_id    : the post's id                | string    */
    /* $hears      : keyword that start to reply  | string    */
    /* $reply      : write what you want to reply | string    */
    /* $repeat     : remove the repeat user       | boolean   */
    /* ------------------------------------------------------ */
    /**********************************************************/

    // autoReply function

        $pages->autoReply($type_reply, $post_id, $hears, $reply);

    /****************************************/
    /*          finishPost method           */
    /* ------------------------------------ */
    /* $post_id  : the post's id   | string */
    /* ------------------------------------ */
    /****************************************/

    // finishPost function

        $pages->finishPost($post_id);

```

```
Get Method

reference - https://developers.facebook.com/docs/graph-api/reference/page/

$pages->get('page_id', $type);

```

```
    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');
    }

```

Deployment
----------

[](#deployment)

Built With
----------

[](#built-with)

Contributing
------------

[](#contributing)

Versioning
----------

[](#versioning)

Authors
-------

[](#authors)

- **Kevin Xu** - *Initial work* - [ThekDesign](https://github.com/ThekDesign)

License
-------

[](#license)

FBots is licensed under the MIT License - see the [LICENSE](LICENSE) file for details

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~6 days

Recently: every ~11 days

Total

9

Last Release

3054d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/30178778?v=4)[thekdesign](/maintainers/thekdesign)[@thekdesign](https://github.com/thekdesign)

---

Top Contributors

[![thekdesign](https://avatars.githubusercontent.com/u/30178778?v=4)](https://github.com/thekdesign "thekdesign (41 commits)")

### Embed Badge

![Health badge](/badges/thekdesign-fbots/health.svg)

```
[![Health](https://phpackages.com/badges/thekdesign-fbots/health.svg)](https://phpackages.com/packages/thekdesign-fbots)
```

###  Alternatives

[markwalet/nova-modal-response

A Laravel Nova asset for Modal responses on an action.

17818.7k](/packages/markwalet-nova-modal-response)[crumbls/layup

A visual page builder plugin for Filament 5 — Divi-style grid layouts with extensible widgets.

591.7k1](/packages/crumbls-layup)[tomshaw/electricgrid

A feature-rich Livewire package designed for projects that require dynamic, interactive data tables.

119.2k](/packages/tomshaw-electricgrid)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
