- Now supports Microsoft accounts (#24)
JavaSkype is a lightweight and comprehensive API for Skype, using the MSNP24 protocol, and Java 8.
This API lets you:
- Send and receive private Skype messages
- Send and receive group chat Skype messages
- Send, receive, accept, and deny friend requests
- Get your contact list, know your contacts presence, and change yours
- Add/remove users to a group
- Block and unblock contacts
- Get information about your contacts, such as their name, and their avatar
JavaSkype requires Java >= 8 to run. You can get this library using Maven by adding this to your pom.xml
:
<dependencies>
<dependency>
<groupId>fr.delthas</groupId>
<artifactId>javaskype</artifactId>
<version>1.0.22</version>
</dependency>
</dependencies>
This library is Object-oriented: the main Skype object will give you User and Group objects, on which you will call methods in order to do stuff. Let's have a look at how to interact with the library.
Skype skype = new Skype("myusername", "mypassword");
try {
// If you want to report a bug, enable logging
// Skype.setDebug(path);
skype.connect(); // Will block until we're connected
} catch (IOException e) {
System.err.println("An error occured while connecting...");
e.printStackTrace();
}
// Set the error callback (will be called if any exception is thrown)
// When it is called, you'll be automatically disconnected
skype.setErrorListener(Exception::printStackTrace);
// We're connected and ready to go
// Say hello to all your contacts
for (User user : skype.getContacts()) {
user.sendMessage("Hi, " + user.getDisplayName() + ", what's up?");
}
// Better: let's say hello whenever a user connects
skype.addUserPresenceListener((user, oldPresence, presence) -> {
if (oldPresence == Presence.OFFLINE) {
user.sendMessage("Hi, " + user.getFirstname());
}
});
// Create a simple time bot
skype.addUserMessageListener((user, message) -> {
if (message.toLowerCase().contains("time")) {
user.sendMessage("The current time is: " + LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME));
}
});
// Invite everyone to the groups you own/are admin on
for (Group group : skype.getGroups()) {
if (group.isSelfAdmin()) {
for (User user : skype.getContacts()) {
group.addUser(user, Role.USER);
}
}
}
// Kick a user whenever he rants about Java
skype.addGroupMessageListener((group, user, message) -> {
if (message.toLowerCase().contains("java") && message.toLowerCase().contains("bad")) {
group.removeUser(user);
group.changeTopic("No Java bashing allowed here!");
}
});
// Let's disconnect
skype.disconnect();
The main entry points are :
- the Skype object
- the listeners you can put on the Skype object
- the User and Group objects you get from Skype or from the listeners
The javadoc for the API is located at: http://www.javadoc.io/doc/fr.delthas/javaskype/
Note that this API doesn't support multithreaded calls: if you want to go for some multithreading, you will have to handle the synchronization yourself. You can however run multiple Skype accounts simultaneously, on the same or different threads.
Simply run mvn install
.
JavaSkype uses a very small set of libraries in order to run:
- json - Parse JSON responses from the Skype API
- JSoup - A lightweight and powerful library to parse HTML documents
- JUnit - The famous testing library
Several libraries have been used during the making of this library:
- skylogin - I originally used this library via JNI but I've rewritten it in Java in UicConnector.java
- pyskype - I've used this library to understand how to make a MSNP24 client
- msndevs-wiki - This wiki has helped me understand the MSNP24 protocol
MIT