4

I've been trying to get my script to send a message to a group conversation in Skype using the Skype4Py library, the only way I am currently able to send messages is to specific users.

import Skype4Py
Skype = Skype4Py.Skype()
Skype.Attach()
Skype.SendMessage('namehere','testmessage')

Does anyone know how I can change my code to send a message to a group conversation?

ekad
  • 14,436
  • 26
  • 44
  • 46
Ryflex
  • 5,559
  • 25
  • 79
  • 148

1 Answers1

8

The following little script should work. (Assuming you already have a group chat open)

def sendGroupChatMessage():
    """
    Send Group Chat Messages.
    """
    import Skype4Py as skype
    skypeClient = skype.Skype()
    skypeClient.Attach()
    for elem in skypeClient.ActiveChats:
        if len(elem.Members) > 2:
            elem.SendMessage("SomeMessageHere")

I'm basically importing all the current chats, checking the number of members and sending a message accordingly. It should be easy to check within various groups too.

To get the handles too, change your function to this.

def sendGroupChatMessage():
    """
    Send Group Chat Messages.
    """
    import Skype4Py as skype
    skypeClient = skype.Skype()
    skypeClient.Attach()
    for elem in skypeClient.ActiveChats:
        if len(elem.Members) > 2:
            for friend in elem.Members:
                  print friend.Handle
            elem.SendMessage("SomeMessageHere")

If you can bookmark your chat, you just have to do this, then.

>>> groupTopic = 'Insert a Topic Here'
>>> for chat in skypeClient.BookmarkedChats:
        if chat.Topic == groupTopic:
            chat.SendMessage("Send a Message Here")

This is the final code that should be standalone.

def sendGroupChatMessage(topic=""):
    """
    Send Group Chat Messages.
    """
    import Skype4Py as skype
    skypeClient = skype.Skype()
    skypeClient.Attach()
    messageSent = False
    for elem in skypeClient.ActiveChats:
        if len(elem._GetMembers()) > 2 and elem.Topic == topic:
            elem.SendMessage("SomeMessageHere")
            messageSent = True

    if not messageSent:
        for chat in skypeClient.BookmarkedChats:
            if chat.Topic == topic:
                chat.SendMessage("SomeMessageHere")
                messageSent = True

    return messageSent
Sukrit Kalra
  • 33,167
  • 7
  • 69
  • 71
  • Looks good, but the only issue is that I have multiple 2 member groups, I need it to send to a specific one either using the group name or the blob to check if it's the right one. – Ryflex Jun 18 '13 at 18:39
  • 1
    Do you have the handles of the users in that group? – Sukrit Kalra Jun 18 '13 at 18:40
  • 1
    What can you use to identify the group? Do you have the blob, the topic, the handle of members? – Sukrit Kalra Jun 18 '13 at 18:46
  • I'm unsure how to get the handles I tried adding: `if elem._GetBlob() == "Insertblobhere":` but it doesn't work, also it would need to activate or better send to the conversation (it wont always be open/active) – Ryflex Jun 18 '13 at 18:46
  • 1
    Working on the activation. Added how to find the handles. – Sukrit Kalra Jun 18 '13 at 18:50
  • `elem._GetTopic()` will give me a way to choose the right group, `if elem._GetTopic() == "topic here":` – Ryflex Jun 18 '13 at 18:51
  • 2
    Yup. Asked you if you had the Topic, you could just do, `elem.Topic` since the `_funcName` functions are considered to be private. I shouldn't have called those either, fixing. – Sukrit Kalra Jun 18 '13 at 18:53
  • The blob can't be used by the way, because it's encrypted or something and keeps changing (do /get uri) on a skype convo and it'll change every time you do it. – Ryflex Jun 18 '13 at 18:56
  • 1
    Then, you could decide the group through the topic or the members. I still can't figure out how to revive an old group. – Sukrit Kalra Jun 18 '13 at 18:59
  • I assume it has something to do with: http://skype4py.sourceforge.net/doc/html/Skype4Py.skype.Skype-class.html down at FindChatUsingBlob My blob is changing all the time, I need it to send to the conversation or activate the conversation, currently it requires me to be selected on the conversation to work :/ – Ryflex Jun 18 '13 at 19:43
  • 1
    Can you bookmark the chat once? Add it to your favourites if you will? – Sukrit Kalra Jun 18 '13 at 19:58