Sending Skype messages in Java, using the java
I need help with my java project. I'm currently trying to send a message in a Skype conversation when a specific action happens.
For this, I am using the java-skype API v1.4 by taskan.
Here's my code:
try {
for (Group group : Skype.getContactList().getAllGroups()) {
if ((group.getDisplayName()).equals("Nameofthegroup")) { //Whatever the group name is
String id = group.getId();
Skype.chat(id).send(ep.getDisplayName() + " joins !");
ep.sendMessage("Die ID: "+ id);
}
}
} catch (Exception e3) {
e3.printStackTrace();
}
I've also tried:
try {
String id = Skype.getContactList().getGroup("Groupname").getId();
Skype.chat(id).send(p + "joins!");
} catch (SkypeException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
My problem is that Skype registers that a external program tries to do something, but after I allow access for Java, nothing else happens. No messages are sent.
Sorry for the late answer but assuming you haven't yet picked an answer the problem is still open.
I was trying to get groups the same way with you but unfortunately it doesn't work like this. I do not if this is API problem or just because microsoft dropped support from third party APIs some of its features not working.
I managed to work this around by searching for chats not for groups. Also it would be much easier if you just bookmark (add at favorites) the chat (group) you want to find.
Chat group = null;
for ( Chat c : Skype.getAllBookmarkedChats() ){
group = c;
}
I just have the group chat in my favorites so it is super easy to retrieve it! If you have more chats and you need a more general way to find a specific one there are also several ways to do this.
for (Chat c : Skype.getAllChats()){
c.getAllMembers();
c.getId();
c.getWindowTitle();
}
group = c;
But this would be harder. The getId() way may be look easier but I didn't manage to get it working. Don't know again if it was my problem or just the API but whatever I tried simple just didn't work. And do not forget to print your results at console to ease yourself.
In the end if you manage to get your group chat it is really easy to send a message:
group.send("Hi chat! This is java!!");
EDIT
This api works only for p2p chats. If you want to create a p2p chat you need to use the /createmoderatedchat command in any chat and it will create a new empty p2p chat. Any other group will be automatic cloud-based.
Also check this
SECOND EDIT
API is completely dead
I don't know too much about the Skype API, but you can check the samples for help. If you want to send a chat message when someone sends you a chat message you can use the AutoAnswering example:
package com.skype.sample;
import com.skype.ChatMessage;
import com.skype.ChatMessageAdapter;
import com.skype.Skype;
import com.skype.SkypeException;
public class AutoAnswering {
public static void main(String[] args) throws Exception {
Skype.setDaemon(false); // to prevent exiting from this program
Skype.addChatMessageListener(new ChatMessageAdapter() {
public void chatMessageReceived(ChatMessage received) throws SkypeException {
if (received.getType().equals(ChatMessage.Type.SAID)) {
received.getSender().send("I'm working. Please, wait a moment.");
}
}
});
}
}
Your code has an undefined variable ep
in it and I can't give you a better answer because of that. I would've made a comment asking about it, but Stack Overflow doesn't let new people make comments.
上一篇: 将BNF语法转换为pyparsing