pimax / fb-messenger-php

Facebook Messenger Bot PHP API
GNU General Public License v2.0
314 stars 147 forks source link

How do I include a Quick Reply in a Structured Message #93

Closed tinonetic closed 7 years ago

tinonetic commented 7 years ago

According to the Facebook docs, you can include QuickReplies in your structured data.

https://www.facebook.com/business/help/1646890868956360

How do I achieve this using this library!

Great library, by the way!!!

wittfabian commented 7 years ago

80

tinonetic commented 7 years ago

Hi Thanks for the quick response.

From the link, I don't see any sample code or any discussion on how to achieve this...

wittfabian commented 7 years ago

Example will follow shortly

tinonetic commented 7 years ago

Thank-you @wittfabian . Will wait...

tinonetic commented 7 years ago

Sorry to bother @wittfabian ... still waiting for the example

wittfabian commented 7 years ago

For the impatient the short version. Should work.

                    $bot->send(new StructuredMessage($message['sender']['id'],
                        StructuredMessage::TYPE_GENERIC,
                        [
                            'elements' => [
                                new MessageElement("First item", "Item description", "", [
                                    new MessageButton(MessageButton::TYPE_POSTBACK, 'First button'),
                                    new MessageButton(MessageButton::TYPE_WEB, 'Web link', 'http://facebook.com')
                                ]),
                                new MessageElement("Second item", "Item description", "", [
                                    new MessageButton(MessageButton::TYPE_POSTBACK, 'First button'),
                                    new MessageButton(MessageButton::TYPE_POSTBACK, 'Second button')
                                ]),
                                new MessageElement("Third item", "Item description", "", [
                                    new MessageButton(MessageButton::TYPE_POSTBACK, 'First button'),
                                    new MessageButton(MessageButton::TYPE_POSTBACK, 'Second button')
                                ])
                            ]
                        ],
                        [ 
                            new QuickReplyButton(QuickReplyButton::TYPE_TEXT, 'First button','THIS PARAM is required, atleast put a whitespace!') 
                        ]
                    ));
tinonetic commented 7 years ago

Lol. Sorry...

Much appreciated though! Thanks for your support and your awesome library!

Sincerely, The Impatient