How to implement List Template Structured Message ?
Closed this issue · 20 comments
How to implement List Template Structured Message with global button @wittfabian ?
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.
Will be thankful
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')
]
));
Please check the code, then it can be added to the examples.
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" => [
====> {
I've edited the example.
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"=> [
Sorry, missed one item^^
@wittfabian
OK no worries
I add this example to the index.php file.
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')
Line 169 in StructuredMessage.php do not call the QuickReply part
you changed it
case 'list':
break;
Yes, I mean the file StructuredMessage.php
solved
It not working Sir from the example @wittfabian there were bugs
someone removed the list part from the example
No, index is also updated.
The example above was tested.
Sorry Just tested it working fine thanks a million @wittfabian
Solved
Good