Sending Skype messages in Java, using the java-skype api by taskan
Asked Answered
P

2

8

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.

Peyton answered 13/1, 2015 at 21:26 Comment(4)
This is unrelated to your question, but I'd like to say that, after seeing several questions with little to no effort put in, it's refreshing to see one that has it.Sample
need help still have the problem.Peyton
So follow Captain_D1's instructions and tell us what ep is.Sample
ep is the same as p... it is the name of the player in the event... it does not work at allPeyton
R
4

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

Realistic answered 7/2, 2015 at 13:11 Comment(8)
yes i still have the problem :) i will try this tomorrow thanks for your answer :)) hope it will workPeyton
if you need more help just let me knowRealistic
yes have a problem... :) does this work for groupchats? because if i try it i get the error: NotAttachedException?Peyton
yes it does! I am working it for group chats. Can you give me your code?Realistic
Chat group = null; try { for ( Chat f : Skype.getAllBookmarkedChats() ){ group = f; group.send("Der Spieler " + ep.getDisplayName() +" hat den Server betreten"); } } catch (SkypeException u) { u.printStackTrace(); } }Peyton
@Stefanx do you have your chat at your favorities? (bookmarked)Realistic
Thank you, @LittleJacod, it works! The only thing I noticed, the Java API always tells I have zero bookmarked chats (untruth).Lilithe
@PavelVlasov glad it works :D You guys if you like you can check my skypebot it has many features and if you writing your own you are more than welcome to help me :)Realistic
H
0

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.

Humbertohumble answered 16/1, 2015 at 20:55 Comment(1)
thanks but i do not need a listener. i just simply want to send the message but it do not work :(Peyton

© 2022 - 2024 — McMap. All rights reserved.