Is it possible to post message in multiple group in on go?
Closed this issue · 11 comments
Currently I am posting message in whatsapp groups by using for loop, which is posting message one by one in each group.
Let's say if I have 30 groups, it take time to post message in all 30 groups.
Is it possible to post message in all groups in same time?
please share your code
What you could do is use threads to execute all or many at the same time, I haven't tried something like this, so I could be missing something, but I think that's more botty behaviour that Whatsapp could detect and ban.. I always try to mimic a human as much as possible, for example giving some time between each message sent
please share your code
Here is my sample code, In my function send_message() I have following for loop
for active_whatsapp_group in active_whatsapp_groups:
g.driver.chat_send_message(active_whatsapp_group, message)
What you could do is use threads to execute all or many at the same time, I haven't tried something like this, so I could be missing something, but I think that's more botty behaviour that Whatsapp could detect and ban.. I always try to mimic a human as much as possible, for example giving some time between each message sent
Let me try your suggestion
is this list of groups dynamic or fixed?
is this list of groups dynamic or fixed?
it is dynamic
try to use g.driver.send_message_to_id(active_whatsapp_group, message)
send_message_to_id
I do not find method name send_message_to_id()
def send_message_to_id(self, recipient, message):
"""
Send a message to a chat given its ID
:param recipient: Chat ID
:type recipient: str
:param message: Plain-text message to be sent.
:type message: str
"""
return self.wapi_functions.sendMessageToID(recipient, message)
If you're still wondering if it can be done and is fine with the risk, you can try this.
async function sendMultiGroup(chatIds, message) {
const promises = chatIds.map((cid) => {
return WAPI.sendMessage(cid, message);
});
const result = await Promise.all(promises);
return result;
}
find a way to declare that javascript function on your whatsapp instance startup, then implement this python snippet.
from openwa.wapi_js_wrapper import JsArg
group_ids = ['1234567890@g.us', '0987654321@g.us']
message = "hi"
args = [JsArg(gid) for gid in group_ids]
script = 'return WAPI.pyFunc(() => sendMultiGroup([{gid}], {msg}), arguments[0])'.format(gid=",".join([str(arg) for arg in args]), msg=message)
g.driver.execute_async_script(script)
Note that I haven't tried this yet