Terrance/SkPy

Send message to some groups

Closed this issue · 8 comments

Hi, i am new to this topic and this language, i'm trying to send the exctly same message at the exctly same time to 3 different groups in skype, im out of ideas how to do it, even chatgpt coldn't help me out. By now, i have this code below.
`from skpy import Skype,
import requests, time, schedule

Substitua 'seu_email' e 'sua_senha' pelas suas credenciais do Skype

sk = Skype("...", "m...")

Lista de IDs de contatos para os quais você deseja enviar a mensagem

contacts_ids = ['live:.cid.6000b2330b1a104c', 'live:.cid.a84ba69c28c5bfbd']

Loop para enviar a mensagem para cada contato

for contact_id in contatos_ids:
# Encontre o contato pelo ID
contact = sk.contacts[contacts_ids]

def send_message():
# Coloque aqui o código para enviar a mensagem
message = "Sua mensagem aqui" # Substitua pela mensagem que você deseja enviar
contact.chat.sendMsg(message)

Agende o envio da mensagem às 15 horas todos os dias

schedule.every().day.at("15:00").do(send_message)

O loop a seguir verifica regularmente se há tarefas agendadas para serem executadas

while True:
schedule.run_pending()
time.sleep(1) # Você pode ajustar o intervalo de verificação, se desejar`

You haven't said what your problem is, and the one bit of SkPy code (sk.contacts[contact_id].chat.sendMsg(message)) should work, so without any more context, either there's a problem elsewhere in your code or you're getting rate-limited from spamming your contacts every second if run_pending() actually triggers the sending every second.

Im getting de error 404
image

I'm assuming that's the call to fetch the chat, but I can't tell unless you post the full URL that's 404ing.

Are the referenced users actually contacts? If you don't have a chat with them yet then you'll probably need to invite them (and wait for their acceptance) first.

This is actually a group, i'm trying to send a message to three different groups
image

The code you posted originally does not create or interact with any groups, it's sending messages to individual users. Please post the code you're actually running code in full, and show the corresponding output and errors.

Peeking at that traceback, that group ID doesn't look long enough. Are you passing a user ID instead of a group chat ID? You should also be using key lookups on sk.chats, no need to call chat().

I don't even know if this makes sense at all, i'm new at dev and just trying this
image

No problems here reading a group like that:

>>> group_id = "19:b07bbfdc71174e1b88e491c451824b99@thread.skype"
>>> group = sk.chats.chat(group_id)
>>> group
SkypeGroupChat(id='19:b07bbfdc71174e1b88e491c451824b99@thread.skype', alerts=True, topic='Test group', creatorId='8:fred.2', userIds=['8:fred.2'], adminIds=['8:fred.2'], open=False, history=False, active=False, moderated=False)

Or using key access as recommended earlier:

>>> sk.chats[group_id]
SkypeGroupChat(id='19:b07bbfdc71174e1b88e491c451824b99@thread.skype', alerts=True, topic='Test group', creatorId='8:fred.2', userIds=['8:fred.2'], adminIds=['8:fred.2'], open=False, history=False, active=False, moderated=False)

Reiterating from above:

Peeking at that traceback, that group ID doesn't look long enough. Are you passing a user ID instead of a group chat ID?

The prefix (19:) is correct so I'm unsure if you've actually obtained it from somewhere, or just manually typed an invalid ID.

sk.contacts[group_id] (line 21) also won't work, presumably you mean to use group there.

As far as I can tell, there's no issue with SkPy here, so please take some time to read the Guides section of the docs that explains how to do the basic tasks like retrieving users and chats.

The code you posted originally does not create or interact with any groups, it's sending messages to individual users. Please post the code you're actually running code in full, and show the corresponding output and errors.

Peeking at that traceback, that group ID doesn't look long enough. Are you passing a user ID instead of a group chat ID? You should also be using key lookups on sk.chats, no need to call chat().

This tip solved my problems, thank you so much