如何为充当网络视图的Facebook Messenger制作一个Botman URL按钮?

时间:2018-06-28 04:08:44

标签: laravel laravel-5 facebook-messenger-bot

我正在使用botman作为制作Messenger bot的插件。我有打开Web URL的这段代码,但是我想要使其成为WebView。 这是我的代码:

$botman->hears('try', function ($bot) {
    $bot->typesAndWaits(2);
    $bot->reply(ListTemplate::create()
    ->useCompactView()
    ->addElement(
        Element::create('Sample Title')
            ->subtitle('Some subtitle.')
            ->image('https://sampleurl.com/images/logo.png')
            ->addButton(ElementButton::create('Sample Button')
                ->url('https://sampleurl.com')
                )
        )
    );
});

上面的代码有效,但是它在新标签页中打开了url。我希望它的行为就像Web视图一样,就像我在持久菜单中创建的一样:

'persistent_menu' => [
    [
        'locale' => 'default',
        'composer_input_disabled' => 'false',
        'call_to_actions' => [
            [
                'title' => 'Sample Title',
                'type' => 'web_url',
                'url' => 'https://sampleurl.com',
                'webview_height_ratio' => 'full',
                'webview_share_button' => 'hide',
                'messenger_extensions' => true
            ],
        ],
    ],
],

1 个答案:

答案 0 :(得分:0)

您需要使用enableExtensions()这样的方法。它告诉FB请求允许通过按钮或菜单进行Web视图。

When you are opening the webview from the persistent menu or a button, ensure that the messenger_extensions parameter is set to true. If a user has opened the webview via a shared message, it is not required that they have talked to your bot for Messenger Extensions to work.(来自FB文档)

ButtonTemplate::create('Open Webview')
        ->addButton(ElementButton::create('Click here')
             ->url(https://myurl.com/webview')
             ->enableExtensions()
        );