pimax / fb-messenger-php-example

Facebook Messenger Bot PHP API Example
107 stars 53 forks source link

How to implement List Template Structured Message ? #32

Closed jnepal closed 7 years ago

jnepal commented 7 years ago

How to implement List Template Structured Message with global button @wittfabian ?

wittfabian commented 7 years ago

Examples for structured messages are provided. Add an item to the array like "elements" with the name "buttons". There you can add one button.

Tomorrow I add an example.

ngethe commented 7 years ago

Will be thankful

wittfabian commented 7 years ago

Should work (not tested).

$bot->send(new StructuredMessage($message['sender']['id'],
                        StructuredMessage::TYPE_LIST,
                        [
                            'elements' => [
                                new MessageElement(
                                    'Classic T-Shirt Collection', // title
                                    'See all our colors', // subtitle
                                    'http://bit.ly/2pYCuIB', // image_url
                                    [ // buttons
                                        new MessageButton(MessageButton::TYPE_WEB,
                                            'View',
                                            'http://facebook.com')
                                    ]
                                ),
                                new MessageElement(
                                    'Classic White T-Shirt', // title
                                    '100% Cotton, 200% Comfortable', // subtitle
                                    'http://bit.ly/2pb1hqh', // image_url
                                    [ // buttons
                                        new MessageButton(MessageButton::TYPE_WEB,
                                            'View',
                                            'https://google.com')
                                    ]
                                )
                            ],
                            'buttons' => [
                                new MessageButton(MessageButton::TYPE_POSTBACK, 'First button', 'PAYLOAD 1')
                            ]
                        ],
                        [
                            new QuickReplyButton(QuickReplyButton::TYPE_TEXT, 'QR button','PAYLOAD')
                        ]
                    ));
wittfabian commented 7 years ago

Please check the code, then it can be added to the examples.

ngethe commented 7 years ago

Thanks for the example I am geting this error

                  syntax error, unexpected '{', expecting ']'

This below is the line

                 $bot->send(new StructuredMessage($message['sender']['id'],
                      StructuredMessage::TYPE_LIST,
                      [
                                "elements" => [
                                    ====>               {
wittfabian commented 7 years ago

I've edited the example.

ngethe commented 7 years ago

Thanks for the update I am getting this error

                     Uncaught Error: Call to a member function getData() on array in /var/www/html/fbb/vendor/pimax/fb-messenger-php/Messages/StructuredMessage.php:169\nStack trace:\n#0

I have changed from "buttons": [ to "buttons"=> [

wittfabian commented 7 years ago

Sorry, missed one item^^

ngethe commented 7 years ago

@wittfabian
OK no worries

wittfabian commented 7 years ago

I add this example to the index.php file.

ngethe commented 7 years ago

Thanks for this but I get the error

                            PHP Fatal error:  Uncaught Error: Call to a member function getData() on array in /var/www/html/fbb/vendor/pimax/fb-messenger-php/Messages/StructuredMessage.php:169\nStack trace:\n#0 /var/www/html/fbb/index.php(198)

This is line 198 new QuickReplyButton(QuickReplyButton::TYPE_TEXT, 'QR button','PAYLOAD')

wittfabian commented 7 years ago

Line 169 in StructuredMessage.php do not call the QuickReply part

ngethe commented 7 years ago

you changed it

case 'list': break;

wittfabian commented 7 years ago

Yes, I mean the file StructuredMessage.php

wittfabian commented 7 years ago

solved

ngethe commented 7 years ago

It not working Sir from the example @wittfabian there were bugs someone removed the list part from the example

wittfabian commented 7 years ago

No, index is also updated.

wittfabian commented 7 years ago

The example above was tested.

ngethe commented 7 years ago

Sorry Just tested it working fine thanks a million @wittfabian

Solved

wittfabian commented 7 years ago

Good