Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
RamiiYoussef opened this issue Dec 27, 2019 · 5 comments

Comments

@RamiiYoussef
Copy link

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?

@christian482
Copy link

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

botman/botman#865

Tell me if u had success

@KyawNaingTun
Copy link

KyawNaingTun commented Jun 12, 2020

@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.

@s4rrow
Copy link

s4rrow commented Oct 8, 2020

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

@christian482
Copy link

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

@christian482
Copy link

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants