I am trying to send direct message with JAXL in the name of a user (authenticated application with xmpp_login). In the jaxl facebook chat example there exist a message echo structure, still it redirects received XMPPStanza to the sender. But trying to generate XMPPStanza to send performs nothing with
$client->send($stanza);
here is my XMPPStanza initialization code
$stanza = new XMPPMsg(null);
$stanza->from = $client->full_jid->to_string();
$stanza->to = '[email protected]';
$stanza->type = 'chat';
$stanza->body = 'test message';
$client->send($stanza);
To sum it up, How can i send message from server in the name of the client via JAXL?
EDIT
I forgot to mention i am using JAXL v3 and thought about appending full code and system configuration would be more helpful.
<?php
define('FACEBOOKBOT_PHP', TRUE);
// Include XMPP Engine 'JAXL'
// Path might be alter in time.
// require_once ROOT_DIR.'/JAXL/jaxl.php';
require_once '/var/www/JAXL/jaxl.php';
require_once '/var/www/JAXL/xmpp/xmpp_msg.php';
function sendMessage($client)
{
// // $stanza = new XMPPMsg(null);
// // $stanza->from = $client->full_jid->to_string();
// // $stanza->to = $to;
// // $stanza->type = 'chat';
// // $stanza->body = 'test message 1';
// // foreach ($stanza->childrens as $value)
// // {
// // $value->ns = 'jabber:client';
// // }
// // $client->send($stanza);
$msg = new XMPPMsg(array('to'=>'example-user-id-and-it-got-to-work-i-checked-on-below-echo-stanza@chat.facebook.com'), 'test message');
$client->send($msg);
_info("test messages sent");
}
$user = 'gokhanbarisaker'; // my user id (www.facebook.com/gokhanbarisaker)
// $user = $argv[1]; // User name or facebook id
$jidSuffix = '@chat.facebook.com'; // Facebook chat account suffix
$appKey = 'example-app-key'; // Taken from developer.facebook.com
// $appKey = $argv[2]; // Facebook app token
$accessToken = 'example-access-token'; // Facebook user token - tried both app token tool on developer.facebook.com and token provided after user login both posses xmpp-login permission
// $accessToken = $argv[3];
$client = new JAXL( array( // (required) credentials
'jid' => $user.$jidSuffix,
'fb_app_key' => $appKey,
'fb_access_token' => $accessToken,
// force tls (facebook require this now)
'force_tls' => true,
// (required) force facebook oauth
'auth_type' => 'X-FACEBOOK-PLATFORM',
// (optional)
//'resource' => 'resource',
'log_level' => JAXL_INFO,
'priv_dir' => '.'
));
$client->add_cb('on_auth_success', function()
{
global $client;
_info("got on_auth_success cb, jid ".$client->full_jid->to_string());
$client->set_status("available!", "dnd", 10);
// Here is the part where i tried to send message. In addition, i tried to call this function wherever i can on the code.
sendMessage($client);
});
$client->add_cb('on_auth_failure', function($reason)
{
global $client;
$client->send_end_stream();
_info("got on_auth_failure cb with reason $reason");
});
$client->add_cb('on_chat_message', function($stanza)
{
global $client;
// echo back incoming message stanza
$stanza->to = $stanza->from;
$stanza->from = $client->full_jid->to_string();
$client->send($stanza);
_info("echo message sent");
sendMessage($client);
});
$client->add_cb('on_disconnect', function()
{
_info("got on_disconnect cb");
});
$client->start();
echo "done\n";
?>
System configuration:
- Ubuntu 12.04.01 LTS
- Apache 2.2.22
- PHP 5.3.10
Terminal command to execute;
- > php facebookbot.php