studio icon indicating copy to clipboard operation
studio copied to clipboard

How can use botman for multiple pages (multiple page access token) - Facebook

Open RamiiYoussef opened this issue 6 years ago • 5 comments

I'm using botman with one app id and one page access token.

How can I use my botman for multiple pages and work on multiple pages at the same time?

Where can I set an array of page access token?

RamiiYoussef avatar Dec 27 '19 05:12 RamiiYoussef

i got the same problem, i found this link, but when trying to apply the solution I was not successful.

https://github.com/botman/botman/issues/865

Tell me if u had success

christian482 avatar Jun 06 '20 17:06 christian482

@xrami @christian482 If you are using BotmanStudio, the following solution can help you. go to FacebookDriver.php

public function buildPayload(Request $request){
    $this->payload = new ParameterBag((array) json_decode($request->getContent(), true));
    $this->event = Collection::make((array) $this->payload->get('entry')[0]);
    $this->signature = $request->headers->get('X_HUB_SIGNATURE', '');
    $this->content = $request->getContent();
    
    //HERE MY CUSTOM BLOCK
    $config = config('botman.facebook', []);
    $recipient_id = $this->event->get('messaging')[0]['recipient']['id'];

    $token = null;
    if(!($recipient_id == null OR $recipient_id == "")){
        $key = 'page_token_'.$recipient_id;
        $token = Cache::remember($key, 60, function () use ($recipient_id) {
            $page_access_token = ;//search_your_page_token_by_recipient_id_here
            return $page_access_token;
        });
    }
    if($token == null){
        $this->config = Collection::make($this->config->get('facebook', []));
    }else{
        $config['token'] = $token;
        $this->config = Collection::make($config);
    }
        
}

Otherwise, If you don't use BotmanStudio, you can use like that

$config = [
            'facebook' => [
                'token'        => 'page_token',
                'app_secret'   => 'app_secret',
                'verification' => 'webhook_token',
            ],
];
// dynamic page_token logic here
// here your logic
$botman = BotManFactory::create($config);

All solutions are need to set dynamic page token. You need to write a dynamic page token logic only.

KyawNaingTun avatar Jun 12 '20 10:06 KyawNaingTun

@KyawNaingTun could you share your project? Thank you so much with dynamic page token logic any examples please

s4rrow avatar Oct 08 '20 12:10 s4rrow

I would also appreciate it, I have also had problems integrating it and if I need it a lot

christian482 avatar Oct 24 '20 16:10 christian482

where i found: search_your_page_token_by_recipient_id_here that you use here "$page_access_token = ;//search_your_page_token_by_recipient_id_here"

christian482 avatar Nov 16 '20 22:11 christian482