How to send a message to a group conversation using Skype4Py in Python

I'm trying to send my script message in a group conversation on Skype using the Skype4Py library, the only way I can currently 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?

+4
source share
1 answer

The following small script should work. (Assuming you already have 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 basically import all current chats, checking the number of participants and sending a message accordingly. It should also be easy to check in different groups.

To get pens, 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 tag your chat, you just need to do it.

 >>> 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 
+8
source

Source: https://habr.com/ru/post/1486893/


All Articles