The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

SkypeAPI - Skype API simple implementation, only support windows platform now.

VERSION

0.01

SYNOPSIS

    use SkypeAPI;
    my $skype = SkypeAPI->new({is_verbose =>0});
    sleep 1;
    my $status = $skype->get_command('userstatus');
    print $status, "\n";
    my $version = $skype->get_command('skypeversion');
    print $version, "\n";
    my $currentuserhandle = $skype->get_command('currentuserhandle');
    print $currentuserhandle, "\n";
    my $FULLNAME = $skype->get_command('profile fullname');
    print $FULLNAME, "\n";
    
    #invoke the low level interface to send command
    my $cmd = 'GET USERSTATUS';
    $skype->do_command($cmd);
    #if you care about the result of the do_command
    my $cmd_id = $skype->do_command_for_result($cmd);
    my $result = $skype->wait_message($cmd_id);    
    
    #you can add/remove message listener, *DONT* call Skype API in the listener 
    my $listener = $skype->add_message_listener(\&mesasge_listener);
    $skype->remove_message_listener($listener);
    
    #if you want to call Skype API in your listener, you have to register your listener like this
    $skype->add_message_listener(\&mesasge_listener, 1);
    #and run into loop:
    $skype->message_listen();

FUNCTIONS

SkypeAPI->new( $opt )

Returns a SkypeAPI object. You can pass a option as a hashref when calling new.

    my $skype = SkypeAPI->new({is_verbose =>0});

SkypeAPI->do_command( $cmd_text )

Send command message to skype, if you are not care about the skype response.

    my $cmd = 'GET USERSTATUS';
    $skype->do_command($cmd);
    

SkypeAPI->do_command_for_result( $cmd_text )

Returns a command id. You can pass the command id when calling wait_message to get the response of skype.

    my $cmd = 'GET USERSTATUS';
    my $cmd_id = $skype->do_command_for_result($cmd);

SkypeAPI->wait_message( $cmd_id, [$wait_times, $sleep_interval] )

Watit and returns the response of the skype after calling do_command_for_result;

    my $result = $skype->wait_message($cmd_id);

Default the wait_times is 200, the sleep_interval is 0.1 seconds, this means, waiting for the response you have to wait 20 seconds at most.

It returns -1 if the $cmd_id is not valid
It returns -2 if the response not received yet.
It returns resonpse text if calling ok.

SkypeAPI->add_message_listener( $ref_callback, [$using_api] )

Add listener to the chain of message listener, when message received, listeners in the chain will be invoke in turn.

If you are not going to use Skype API in your listener, you can add the listener like this:

    sub message_listener { 
        my ($instance, $message_id) = @_;
        return 1;
    }
    $skype->add_message_listener(\&mesasge_listener);

Usually you will DO call Skype API in your listener, you have to add the listener by passing a using_api flag and run into a message loop.

    sub message_listener { 
        my ($instance, $message_id) = @_;
        my $body = $instance->get_message($message_id, 'body');
        return 1;
    }
    my $listener = $skype->add_message_listener(\&mesasge_listener);
    $skype->message_listen();

You must take care about the return value of the listener

Returns 1 if the listener DONOT want the other listeners in the chain to handle it.
Returns 0 if the listener allow the other listeners in the chain to handle it.
Returns -1 if the listener with the using_api flag want to stop the message loop.

SkypeAPI->remove_message_listener( $listener)

Remove listener in the chain.

    my $listener = $skype->add_message_listener(\&mesasge_listener);
    $skype->remove_message_listener($listener);

COMMANDS WRAPPED

SkypeAPI wraps some of the skype commands

SkypeAPI->get_command($WHAT, [$wait_times, $sleep_interval])

Send [GET WHAT COMMAND] to skype and wait for the response, then return the status

    my $status = $skype->get_command('userstatus');

SkypeAPI->get_message($message_id, $property, [$wait_times, $sleep_interval])

Send [GET CHATMESSAGE MESSAGEID PROPERTY] to skype and wait for the response, then return the property value

    my $body = $instance->get_message($message_id, 'body');

Available properties are: CHATNAME , TIMESTAMP , FROM_HANDLE , FROM_DISPNAME , TYPE , USERS , LEAVEREASON , BODY , STATUS. Refer to https://developer.skype.com/Docs/ApiDoc/src#OBJECT_CHATMESSAGE for more detail.

SkypeAPI->send_chat_message( $chat_id, $utf8_message, [$wait_times, $sleep_interval])

Send [CHATMESSAGE CHATID MESSAGE] to skype and wait for the response

    $skype->send_chat_message($chat_id, 'Hello');

SkypeAPI->search_chats($selector, [$wait_times, $sleep_interval])

Send [SEARCH SELECTOR MESSAGE] to skype and wait for the response, then return the ARRAYREF of the chats id

    my $ra_chats = $skype->search_chats('ACTIVECHATS');

Available selector are: CHATS , ACTIVECHATS , MISSEDCHATS, RECENTCHATS, BOOKMARKEDCHATS

DESCRIPTION

A Perl simple implementation of the Skype API, working off of the canonical Java and Python implementations. It is a encapsulation of Windows message communication between Skype and client applications. This version of SkypeAPI only implement some commands of SKYPE API, you can implement the others using SkypAPI->do_command or SkypAPI->do_command_for_result.

EXPORT

None by default.

ROTBOT DEMO

You can find the robot.pl in the lib/../t/robot.pl, run it and your skype will become a xiaoi robot :)

the robot needs the module XiaoI, please install it first, See http://code.google.com/p/xiaoi/

SEE ALSO

For more command information, See https://developer.skype.com/Docs/ApiDoc/src

The svn source of this project, See http://code.google.com/p/skype4perl/

AUTHOR

laomoi ( laomoi@gmail.com )

COPYRIGHT AND LICENSE

Copyright (C) 2008 by laomoi

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itinstance, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.