tgalal / yowsup

The WhatsApp lib
GNU General Public License v3.0
7.08k stars 2.23k forks source link

send via Broadcast #1441

Open holgerschochwitz opened 8 years ago

holgerschochwitz commented 8 years ago

Can you implement this code in the sendclient/layer.py? When comma seperated phone numbers then send the message via broadcast:

import TextMessageProtocolEntity, BroadcastTextMessage

        if ',' in phone: 
           jids = [Jid.normalize(number) for number in phone.split(',')]
       messageEntity = BroadcastTextMessage(jids, message)
        else:
           messageEntity = TextMessageProtocolEntity(message, to = Jid.normalize(phone))
jlguardi commented 8 years ago

Yowsup cli already contains /message broadcast command.

maruen commented 8 years ago

Hi Jlguardi,

But this broadcast could be invoked like the examples provided in the demo folder? I saw there only a Echo and Send Client. So my question is if we can have a broadcast client like the send client. provided in the examples of demo folder. Could you help me on something like it?

Thank you so much!

Maruen Mehana Mobile: +55 (011) 98438.8499

São Paulo - SP / BrasilThe way of the righteous is like the first gleam of dawn,which shines ever brighter until the full light of day. - Proverbs 4:18

On Fri, Apr 1, 2016 at 4:59 PM, jlguardi notifications@github.com wrote:

Yowsup cli already contains /message broadcast command.

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/tgalal/yowsup/issues/1441#issuecomment-204545129

maruen commented 8 years ago

Only clarifying more, I want to broadcast messages without being logged in the CLI

Maruen Mehana Mobile: +55 (011) 98438.8499

São Paulo - SP / BrasilThe way of the righteous is like the first gleam of dawn,which shines ever brighter until the full light of day. - Proverbs 4:18

On Fri, Apr 1, 2016 at 5:04 PM, Maruen Mehana maruen@gmail.com wrote:

Hi Jlguardi,

But this broadcast could be invoked like the examples provided in the demo folder? I saw there only a Echo and Send Client. So my question is if we can have a broadcast client like the send client. provided in the examples of demo folder. Could you help me on something like it?

Thank you so much!

Maruen Mehana Mobile: +55 (011) 98438.8499

São Paulo - SP / BrasilThe way of the righteous is like the first gleam of dawn,which shines ever brighter until the full light of day. - Proverbs 4:18

On Fri, Apr 1, 2016 at 4:59 PM, jlguardi notifications@github.com wrote:

Yowsup cli already contains /message broadcast command.

— You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub https://github.com/tgalal/yowsup/issues/1441#issuecomment-204545129

holgerschochwitz commented 8 years ago

Yes, but with this code you can send broadcast message over the "yowsup-cli demos"

That is easier ?!

Thank you

maruen commented 8 years ago

For what I'm doing would be better. If I could have something like this:

_${YOWSUP_HOME}/yowsup-cli demos -M -c ${YOWSUP_HOME}/configs/${LINE}.cfg -s ${NUMBERS} "${MESSAGE}"_ but instead of -s , something like -b (broadcast) and a list of numbers

Anyone could help me on something like that?

Thanks

Maruen Mehana Mobile: +55 (011) 98438.8499

São Paulo - SP / BrasilThe way of the righteous is like the first gleam of dawn,which shines ever brighter until the full light of day. - Proverbs 4:18

On Fri, Apr 1, 2016 at 5:09 PM, holgerschochwitz notifications@github.com wrote:

Yes, but with this code you can send broadcast message over the "yowsup-cli demos"

That is easier ?!

Thank you

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/tgalal/yowsup/issues/1441#issuecomment-204550527

maruen commented 8 years ago

@jlguardi

Hi Yowsup cli already contains /message broadcast command.

jlguardi, can I use the /message broadcast command without beeing with my terminal attached to the CLI? I want to use calling for another application that I have, so because of this, I need some script to call this function to broacast without being attached to the CLI. Could you help me on this?

jlguardi commented 8 years ago

You need to implement you own app. See demos/sendclient/layer.py

maruen commented 8 years ago

I know somebody already did that. Could you or anyone share this with me?

Thanks

Maruen Mehana Mobile: +55 (011) 98438.8499

São Paulo - SP / BrasilThe way of the righteous is like the first gleam of dawn,which shines ever brighter until the full light of day. - Proverbs 4:18

On Mon, Apr 4, 2016 at 1:26 PM, jlguardi notifications@github.com wrote:

You need to implement you own app. See demos/sendclient/layer.py

— You are receiving this because you commented. Reply to this email directly or view it on GitHub https://github.com/tgalal/yowsup/issues/1441#issuecomment-205376273

JerS-vzla commented 7 years ago

Hi,

Implement the code as follows ` @ProtocolEntityCallback("success") def onSuccess(self, successProtocolEntity): self.lock.acquire() for target in self.getProp(self.class.PROP_MESSAGES, []):

getProp() is trying to retreive the list of (jid, message) tuples, if none exist, use the default []

        phone, message = target

if ',' in phone:
    jids = [Jid.normalize(number) for number in phone.split(',')]
    messageEntity = BroadcastTextMessage(jids, message) 
else:
    messageEntity = TextMessageProtocolEntity(message, to = Jid.normalize(phone))

        #messageEntity = TextMessageProtocolEntity(message, to = Jid.normalize(phone))
        #append the id of message to ackQueue list
        #which the id of message will be deleted when ack is received.
        self.ackQueue.append(messageEntity.getId())
        self.toLower(messageEntity)
    self.lock.release()

` But when running it only stays on the sending screen but does not send any of the messages

*[root@localhost yowsup-master]# python yowsup-cli demos -c whatsapp_config.txt -s 5XXXXXXXXXXX,5XXXXXXXXXXX "Hi" yowsup-cli v2.0.15 yowsup v2.5.0

Copyright (c) 2012-2016 Tarek Galal http://www.openwhatsapp.org

This software is provided free of charge. Copying and redistribution is encouraged.

If you appreciate this software and you would like to support future development please consider donating: http://openwhatsapp.org/yowsup/donate*

holgerschochwitz commented 7 years ago

Here is the code from my layer.py

from yowsup.layers.interface import YowInterfaceLayer, ProtocolEntityCallback from yowsup.layers.protocol_messages.protocolentities import TextMessageProtocolEntity, BroadcastTextMessage from yowsup.common.tools import Jid import threading import logging logger = logging.getLogger(name)

class SendLayer(YowInterfaceLayer):

#This message is going to be replaced by the @param message in YowsupSendStack construction
#i.e. list of (jid, message) tuples
PROP_MESSAGES = "org.openwhatsapp.yowsup.prop.sendclient.queue"

def __init__(self):
    super(SendLayer, self).__init__()
    self.ackQueue = []
    self.lock = threading.Condition()

#call back function when there is a successful connection to whatsapp server
@ProtocolEntityCallback("success")
def onSuccess(self, successProtocolEntity):
    self.lock.acquire()
    for target in self.getProp(self.__class__.PROP_MESSAGES, []):
        #getProp() is trying to retreive the list of (jid, message) tuples, if none exist, use the default []
        phone, message = target

        if ',' in phone: 
           jids = [Jid.normalize(number) for number in phone.split(',')]
       messageEntity = BroadcastTextMessage(jids, message)
        else:
           messageEntity = TextMessageProtocolEntity(message, to = Jid.normalize(phone))

        #append the id of message to ackQueue list
        #which the id of message will be deleted when ack is received.
        self.ackQueue.append(messageEntity.getId())
        self.toLower(messageEntity)
    self.lock.release()

#after receiving the message from the target number, target number will send a ack to sender(us)
@ProtocolEntityCallback("ack")
def onAck(self, entity):
    self.lock.acquire()
    #if the id match the id in ackQueue, then pop the id of the message out
    if entity.getId() in self.ackQueue:
        self.ackQueue.pop(self.ackQueue.index(entity.getId()))

    if not len(self.ackQueue):
        self.lock.release()
        logger.info("Message sent")
        raise KeyboardInterrupt()

    self.lock.release()
JerS-vzla commented 7 years ago

Hi holgerschochwitz thanks for answering

Then run it like this: [root@localhost yowsup-master]# python yowsup-cli demos -c whatsapp_config.txt -s 5XXXXXXXXXXXX,5XXXXXXXXXXXX "Hola"

la respuesta obtenida es la siguiente:

*Traceback (most recent call last): File "yowsup-cli", line 368, in if not parser.process(): File "yowsup-cli", line 272, in process self.startSendClient() File "yowsup-cli", line 324, in startSendClient stack.start() File "/var/www/html/whatsapp-py/yowsup-master/yowsup/demos/sendclient/stack.py", line 31, in start self.stack.loop() File "/var/www/html/whatsapp-py/yowsup-master/yowsup/stacks/yowstack.py", line 196, in loop asyncore.loop(args, kwargs) File "/usr/lib64/python2.7/asyncore.py", line 216, in loop poll_fun(timeout, map) File "/usr/lib64/python2.7/asyncore.py", line 156, in poll read(obj) File "/usr/lib64/python2.7/asyncore.py", line 87, in read obj.handle_error() File "/usr/lib64/python2.7/asyncore.py", line 83, in read obj.handle_read_event() File "/usr/lib64/python2.7/asyncore.py", line 449, in handle_read_event self.handle_read() File "/var/www/html/whatsapp-py/yowsup-master/yowsup/layers/network/layer.py", line 102, in handle_read self.receive(data) File "/var/www/html/whatsapp-py/yowsup-master/yowsup/layers/network/layer.py", line 110, in receive self.toUpper(data) File "/var/www/html/whatsapp-py/yowsup-master/yowsup/layers/init.py", line 76, in toUpper self.upper.receive(data) File "/var/www/html/whatsapp-py/yowsup-master/yowsup/layers/stanzaregulator/layer.py", line 29, in receive self.processReceived() File "/var/www/html/whatsapp-py/yowsup-master/yowsup/layers/stanzaregulator/layer.py", line 49, in processReceived self.toUpper(oneMessageData) File "/var/www/html/whatsapp-py/yowsup-master/yowsup/layers/init.py", line 76, in toUpper self.upper.receive(data) File "/var/www/html/whatsapp-py/yowsup-master/yowsup/layers/auth/layer_crypt.py", line 65, in receive self.toUpper(payload) File "/var/www/html/whatsapp-py/yowsup-master/yowsup/layers/init.py", line 76, in toUpper self.upper.receive(data) File "/var/www/html/whatsapp-py/yowsup-master/yowsup/layers/coder/layer.py", line 35, in receive self.toUpper(node) File "/var/www/html/whatsapp-py/yowsup-master/yowsup/layers/init.py", line 76, in toUpper self.upper.receive(data) File "/var/www/html/whatsapp-py/yowsup-master/yowsup/layers/logger/layer.py", line 14, in receive self.toUpper(data) File "/var/www/html/whatsapp-py/yowsup-master/yowsup/layers/init.py", line 76, in toUpper self.upper.receive(data) File "/var/www/html/whatsapp-py/yowsup-master/yowsup/layers/axolotl/layer_control.py", line 44, in receive self.toUpper(protocolTreeNode) File "/var/www/html/whatsapp-py/yowsup-master/yowsup/layers/init.py", line 76, in toUpper self.upper.receive(data) File "/var/www/html/whatsapp-py/yowsup-master/yowsup/layers/init__.py", line 189, in receive s.receive(data) File "/var/www/html/whatsapp-py/yowsup-master/yowsup/layers/axolotl/layer_send.py", line 64, in receive if not self.processIqRegistry(protocolTreeNode): File "/var/www/html/whatsapp-py/yowsup-master/yowsup/layers/init__.py", line 158, in processIqRegistry errorClbk(protocolTreeNode, originalIq) File "/var/www/html/whatsapp-py/yowsup-master/yowsup/layers/axolotl/layer_base.py", line 81, in onError errorClbk(errorNode, getKeysEntity) TypeError: () takes no arguments (2 given)

JerS-vzla commented 7 years ago

Hi, Friends I'm trying to send several numbers, I get the message sent but I do not get the messages, have any idea what may be going on.

[root@localhost yowsup-master]# yowsup-cli demos -c whatsapp.txt -M -s 5XXXXXXXXXXX,5XXXXXXXXXXX "Hola mundo" --debug

DEBUG:yowsup.env.env:Env not set, setting it to s40 DEBUG:yowsup.env.env:Current env changed to s40 DEBUG:yowsup.stacks.yowstack:Initializing stack DEBUG:yowsup.stacks.yowstack:Constructed Network Layer DEBUG:yowsup.stacks.yowstack:Constructed Stanza Regulator Layer DEBUG:yowsup.stacks.yowstack:Constructed Crypt Layer DEBUG:yowsup.stacks.yowstack:Constructed Coder Layer DEBUG:yowsup.stacks.yowstack:Constructed Logger Layer DEBUG:yowsup.stacks.yowstack:Constructed Authentication Layer - Messages Layer - Receipt Layer - Ack Layer - Presence Layer - Ib Layer - Iq Layer - notification Ib Layer - Iq Layer - Chatstate Layer - call Layer - Groups Iq Layer - Media Layer - Privacy Layer - Profiles Layer DEBUG:yowsup.stacks.yowstack:Constructed Interface Layer DEBUG:yowsup.layers.network.layer:Connecting to e3.whatsapp.net:443 DEBUG:yowsup.layers.logger.layer:tx:

DEBUG:yowsup.layers.logger.layer:tx: *U�!0�XyL��?�#�̓�����er~KV́���t0���Ϊ�ä.bq���Ka+��O����,������ު: HEX:2a55982130b11e58794c99c53fcb23c6cc9306ff93b39bc165727e4b56cc81a7b9877430dafedfceaa9dc3a42e0e6271a7edb64b612b81df4f99abdcc32cb7e3181ba98fe5b198bfdeaa3a DEBUG:yowsup.layers.logger.layer:rx: DEBUG:yowsup.layers.logger.layer:rx: p��f�p�U$FY�⯂oC HEX:70f5fe66ad70c65511244659061993e2af826f43 DEBUG:yowsup.layers.protocol_iq.layer:starting ping thread. DEBUG:yowsup.layers.logger.layer:tx: Hola mundo HEX:486f6c61206d756e646f DEBUG:yowsup.layers.logger.layer:rx: DEBUG:yowsup.layers.logger.layer:rx: INFO:yowsup.demos.sendclient.layer:Message sent Yowsdown [root@localhost yowsup-master]#