Comments (22)
I have the same error.
The answer from the server that I got is:
{
"error": {
"message": "(#100) Invalid data",
"type": "OAuthException",
"code": 100,
"error_subcode": 2018032,
"fbtrace_id": "BDf3+Fhu7Kj"
}
}
Error codes - Messenger Platform
I'm seeing the documentation but I don't find the corresponding error_subcode (2018032) in there.
from fb-messenger-php-example.
@wittfabian @andreshg112 I tested with another image link and it worked.
http://res.cloudinary.com/gememerald/image/upload/v1485745856/facebook-announces-clickable-hashtags--resolution-media-17_cckv7m.png
I'll recommend the sample url changed or encoded.
from fb-messenger-php-example.
@ekundayo-ab Any error messages?
from fb-messenger-php-example.
@wittfabian I got a 200 OK Response, but an undefined in response served.
Notice: Undefined index: is_echo in /var/www/html/solaso/index.php on line 63
from fb-messenger-php-example.
@andreshg112 what tool do you use, to see server response?
from fb-messenger-php-example.
@ekundayo-ab is the index file the original one from this repo?
from fb-messenger-php-example.
from fb-messenger-php-example.
@wittfabian here:
<?php
$verify_token = ""; // Verify token
$token = ""; // Page token
if (file_exists(__DIR__.'/config.php')) {
$config = include __DIR__.'/config.php';
$verify_token = $config['verify_token'];
$token = $config['token'];
}
require_once(dirname(__FILE__) . '/vendor/autoload.php');
use solaso\FbBotApp;
use solaso\Messages\Message;
use solaso\Messages\ImageMessage;
use solaso\UserProfile;
use solaso\Messages\MessageButton;
use solaso\Messages\StructuredMessage;
use solaso\Messages\MessageElement;
use solaso\Messages\MessageReceiptElement;
use solaso\Messages\Address;
use solaso\Messages\Summary;
use solaso\Messages\Adjustment;
use solaso\Messages\AccountLink;
// Make Bot Instance
$bot = new FbBotApp($token);
if (!empty($_REQUEST['local'])) {
$message = new ImageMessage(1585388421775947, dirname(__FILE__).'/fb4d_logo-2x.png');
$message_data = $message->getData();
$message_data['message']['attachment']['payload']['url'] = 'fb4d_logo-2x.png';
echo '<pre>', print_r($message->getData()), '</pre>';
$res = $bot->send($message);
echo '<pre>', print_r($res), '</pre>';
}
// Receive something
if (!empty($_REQUEST['hub_mode']) && $_REQUEST['hub_mode'] == 'subscribe' && $_REQUEST['hub_verify_token'] == $verify_token) {
// Webhook setup request
echo $_REQUEST['hub_challenge'];
} else {
// Other event
$data = json_decode(file_get_contents("php://input"), true, 512, JSON_BIGINT_AS_STRING);
if (!empty($data['entry'][0]['messaging'])) {
foreach ($data['entry'][0]['messaging'] as $message) {
// Skipping delivery messages
if (!empty($message['delivery'])) {
continue;
}
// skip the echo of my own messages
if (($message['message']['is_echo'] == "true")) {
continue;
}
$command = "";
// When bot receive message from user
if (!empty($message['message'])) {
$command = $message['message']['text'];
// When bot receive button click from user
} else if (!empty($message['postback'])) {
$command = $message['postback']['payload'];
}
// Handle command
switch ($command) {
// When bot receive "text"
case 'text':
$bot->send(new Message($message['sender']['id'], 'This is a simple text message.'));
break;
// When bot receive "image"
case 'image':
$bot->send(new ImageMessage($message['sender']['id'], 'https://developers.facebook.com/images/devsite/fb4d_logo-2x.png'));
break;
// When bot receive "image"
case 'local image':
$bot->send(new ImageMessage($message['sender']['id'], dirname(__FILE__).'/fb4d_logo-2x.png'));
break;
// When bot receive "profile"
case 'profile':
$user = $bot->userProfile($message['sender']['id']);
$bot->send(new StructuredMessage($message['sender']['id'],
StructuredMessage::TYPE_GENERIC,
[
'elements' => [
new MessageElement($user->getFirstName()." ".$user->getLastName(), " ", $user->getPicture())
]
]
));
break;
// When bot receive "button"
case 'button':
$bot->send(new StructuredMessage($message['sender']['id'],
StructuredMessage::TYPE_BUTTON,
[
'text' => 'Choose category',
'buttons' => [
new MessageButton(MessageButton::TYPE_POSTBACK, 'First button'),
new MessageButton(MessageButton::TYPE_POSTBACK, 'Second button'),
new MessageButton(MessageButton::TYPE_POSTBACK, 'Third button')
]
]
));
break;
// When bot receive "generic"
case 'generic':
$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')
])
]
]
));
break;
// When bot receive "receipt"
case 'receipt':
$bot->send(new StructuredMessage($message['sender']['id'],
StructuredMessage::TYPE_RECEIPT,
[
'recipient_name' => 'Fox Brown',
'order_number' => rand(10000, 99999),
'currency' => 'USD',
'payment_method' => 'VISA',
'order_url' => 'http://facebook.com',
'timestamp' => time(),
'elements' => [
new MessageReceiptElement("First item", "Item description", "", 1, 300, "USD"),
new MessageReceiptElement("Second item", "Item description", "", 2, 200, "USD"),
new MessageReceiptElement("Third item", "Item description", "", 3, 1800, "USD"),
],
'address' => new Address([
'country' => 'US',
'state' => 'CA',
'postal_code' => 94025,
'city' => 'Menlo Park',
'street_1' => '1 Hacker Way',
'street_2' => ''
]),
'summary' => new Summary([
'subtotal' => 2300,
'shipping_cost' => 150,
'total_tax' => 50,
'total_cost' => 2500,
]),
'adjustments' => [
new Adjustment([
'name' => 'New Customer Discount',
'amount' => 20
]),
new Adjustment([
'name' => '$10 Off Coupon',
'amount' => 10
])
]
]
));
break;
case 'set menu':
$bot->setPersistentMenu([
new MessageButton(MessageButton::TYPE_WEB, "First link", "http://yandex.ru"),
new MessageButton(MessageButton::TYPE_WEB, "Second link", "http://google.ru")
]);
break;
case 'delete menu':
$bot->deletePersistentMenu();
break;
case 'login':
$bot->send(new StructuredMessage($message['sender']['id'],
StructuredMessage::TYPE_GENERIC,
[
'elements' => [
new AccountLink(
'Welcome to Bank',
'To be sure, everything is safe, you have to login to your administration.',
'https://www.example.com/oauth/authorize',
'https://www.facebook.com/images/fb_icon_325x325.png')
]
]
));
break;
case 'logout':
$bot->send(new StructuredMessage($message['sender']['id'],
StructuredMessage::TYPE_GENERIC,
[
'elements' => [
new AccountLink(
'Welcome to Bank',
'To be sure, everything is safe, you have to login to your administration.',
'',
'https://www.facebook.com/images/fb_icon_325x325.png',
TRUE)
]
]
));
break;
// Other message received
default:
if (!empty($command)) // otherwise "empty message" wont be understood either
//$bot->send(new Message($message['sender']['id'], 'Sorry. I don’t understand you.'));
$bot->send(new Message($message['sender']['id'], $message['message']['text']));
}
}
}
}
?>
from fb-messenger-php-example.
@andreshg112 "error codes" are not the best part of the facebook docs
from fb-messenger-php-example.
@wittfabian the sample url seems to be the problem.
https://developers.facebook.com/images/devsite/fb4d_logo-2x.png
Is there a way it can be encoded before posting to open graph?
from fb-messenger-php-example.
@ekundayo-ab, I use ngrok, and I add return before sending the message:
return $this->bot->send(
new ImageMessage(
$message['sender']['id'], 'https://developers.facebook.com/images/devsite/fb4d_logo-2x.png'
)
);
from fb-messenger-php-example.
@ekundayo-ab, It's working using the image link you posted above.
from fb-messenger-php-example.
I think the problem is $command never gets set to "Image" so it never tries to send image back.
`$command = "";
// When bot receive message from user
if (!empty($message['message'])) {
$command = $message['message']['text'];
// When bot receive button click from user
} else if (!empty($message['postback'])) {
$command = $message['postback']['payload'];
}`
from fb-messenger-php-example.
if you send "image" via the facebook messenger, the first part of the if statement is triggered
from fb-messenger-php-example.
I am wrong then, sorry I have not tried sending image yet so I just guessed maybe that is the issue
from fb-messenger-php-example.
@wittfabian I think you are wrong actually, I agree that it will go to first IF block but for images there won't be any "text" field inside message object. I just sent an image to my bot and the response is as following:
{ "object": "page", "entry": [ { "id": "948228081946815", "time": 1492695965342, "messaging": [ { "sender": { "id": "1084062888365040" }, "recipient": { "id": "948228081946815" }, "timestamp": 1492695965149, "message": { "mid": "mid.$cAAMEm6ehgyxhvOIl3Vbi5zbu0LLz", "seq": 302620, "attachments": [ { "type": "image", "payload": { "url": "https://scontent.xx.fbcdn.net/v/t34.0-12/18009151_1502125549811905_2134570616_n.png?_nc_ad=z-m&oh=1637634ecb1bc2c55cfa8dac6f279ecd&oe=58FB1894" } } ] } } ] } ] }
So I updated command setting code to the following and it correctly sets command to be image as I tested but stilldoes not send image back. If I send text back instead of image inside "case 'image':" block then it does send the text but not image.
if (!empty($message['message'])) { if(isset($message['message']['text'])){ $messageText = $message['message']['text']; $command = 'text'; } else if(isset($message['message']['attachments'])){ $command = $message['message']['attachments'][0]['type']; } } else if (!empty($message['postback'])) { $command = $message['postback']['payload']; }
from fb-messenger-php-example.
No, the idea is to send the text "image" as command.
In this case, the bot sends an image back.
from fb-messenger-php-example.
It does not do it, in your code command would never be set to image IMO. Because there is no "text" field in "message" object of the response when you send image
EDIT: ohh you mean sending "image" as text message to bot
from fb-messenger-php-example.
Why not? $message['message']['text']
contains the text you send to the bot.
from fb-messenger-php-example.
I get it now, I did not understand it properly before.
I thought you would nee to send real image (not "image" text) to bot in order to receive image from bot.
from fb-messenger-php-example.
The initial problem is solved, use the following image:
http://res.cloudinary.com/gememerald/image/upload/v1485745856/facebook-announces-clickable-hashtags--resolution-media-17_cckv7m.png
from fb-messenger-php-example.
Closed. The example will be updated!
from fb-messenger-php-example.
Related Issues (20)
- Add QuickReply to objects
- Update image example
- set menu not working HOT 21
- button POSTBACK is not working HOT 4
- How to implement List Template Structured Message ? HOT 20
- Add example for TargetAudience & Tags
- Sending elements inside Structured message with data from database. HOT 5
- Guys, you have an error in your PersistentMenu example HOT 2
- Example for "chat extensions home_url"
- Example for "GetStartedButton"
- How to get Postback button value in the callback url in Facebook messenger bot? HOT 10
- Add example: default_action for MessageElement
- default: doesn't work. HOT 2
- MessageButton Questions HOT 9
- Remove title from Share--button example
- Should be check X-Hub-Signature headers
- Add example: how to add image with buttons HOT 1
- Can you show us an example how i can send a message depending by last 2-3 replies ? HOT 2
- Multiple payloads on sequence HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fb-messenger-php-example.