OpenFire UserService Plugin extension

I want to be able to send messages from an external application via an http request to users. For this reason I 'merged' UserService and Subscription plugins. With this modification userService can send messages to users. All you need to do is to build a correct http request in your application.

  • Note, that I'm NOT a Java programmer at all!

  • In order to use this modification you'll have to reinstall the userService Plugin.

  • No error handling is provided.

 

New parameters added:

sender

sender of the message

OF version

recipient

recipient of the message

3.6+

subject

subject of the message

3.6+

msg

body (text) of the message

3.6+

username

a valid username

3.7+

 

Example query 3.6+ :

http://example.com:9090/plugins/userService/userservice?secret=bigsecret&type=sendmsg&sender=admin1&recipient=user1&subject=test_msg&msg=my_important_message

Example query 3.7+ :

http://example.com:9090/plugins/userService/userservice?secret=bigsecret&type=sendmsg&sender=admin1&recipient=user1&subject=test_msg&msg=my_important_message&username=sysuser1

 

All parameters can be sent via HTTP POST or GET methods in a single query. For example the sender, the recipient and the subject parameters use  http GET, while the msg parameter uses http POST method.

Note: In order to send big (more than ~2k) messages you need to use POST method for the msg parameter.  You need to urlencode() some or all the values!

 

An example usage is an intranet web application that sends message to a user  when someone opens a link. A simple PHP example:

 

Simple PHP example

 

// OF server address
$jserver='http://example.com:9090/plugins/userService/userservice';
//1
$postdata = http_build_query(
            array(
             'type'        => 'sendmsg',
             'secret'        => 'bigsecret',
             'username'     => 'sysuser1',    
             'msg'         => 'Call me ASAP',
             'sender'        => 'admin1',
             'recipient'    => 'user1',
             'subject'        => 'URGENT'
              )
);
//2
$opts = array('http' =>
            array(
            'method'  => 'POST',
            'header'  => 'Content-type: application/x-www-form-urlencoded',
            'content' => $postdata
            )
);
//3
$context  = stream_context_create($opts);
//Send message & Get result
$line = file_get_contents($jserver, false, $context);
//Check result
if (!(stripos($line, "<result>ok</result>") === false)){Do something - message sen