Example #1
0
    def __init__(self, credentials, encryptionEnabled = False):
        stackBuilder = YowStackBuilder()


        self.stack = stackBuilder.pushDefaultLayers(encryptionEnabled).push(SendLayer).build()
        # self.stack.setProp(YowAuthenticationProtocolLayer.PROP_PASSIVE, True)
        self.stack.setCredentials(credentials)
Example #2
0
    def start(self, config):

        yowsupConfig = config["Yowsup"]
        credentials = (yowsupConfig["Username"], yowsupConfig["Password"])  # replace with your phone and password

        sendQueue = queue.Queue()

        stackBuilder = YowStackBuilder()
        self.stack = stackBuilder.pushDefaultLayers(True).push(QueueLayer(sendQueue)).build()

        beanstalkdConfig = config["Beanstalkd"]
        beanstalkdStack = BeanstalkStack()
        beanstalkdStack.setConnectParams(beanstalkdConfig["Host"], beanstalkdConfig["Port"], sendQueue, self.stack)

        beanstalkdStack.daemon = True
        beanstalkdStack.start()

        self.stack.setCredentials(credentials)
        connectEvent = YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT)
        self.stack.broadcastEvent(connectEvent)

        while 1:
            try:
                # self.stack.loop(timeout = 0.5, discrete = 0.5)
                self.stack.loop(timeout=0.5)
            except AuthError as e:
                print("Auth Error, reason %s" % e)
            # Bugfix for : https://github.com/tgalal/yowsup/issues/978
            except DuplicateMessageException as e:
                print("Please delete .yowsup/<yournumber>/axolotl.db")
                break
                pass
Example #3
0
def setup_stack(credentials, target_dir):
    stack_builder = YowStackBuilder()
    stack = stack_builder.pushDefaultLayers(
        axolotl=True).push(LogLayer).build()
    stack.setCredentials(credentials)
    stack.setProp(LogLayer.PROP_TARGET, target_dir)
    return stack
Example #4
0
def workerwhatsapp():
    stackBuilder = YowStackBuilder()
    stack = stackBuilder.pushDefaultLayers(True).push(laye).build()
    stack.setCredentials(CREDENTIALS)
    stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
    stack.setProp(YowNetworkLayer.PROP_ENDPOINT, YowConstants.ENDPOINTS[0])
    stack.setProp(YowCoderLayer.PROP_DOMAIN, YowConstants.DOMAIN)
    stack.setProp(YowCoderLayer.PROP_RESOURCE,
                  YowsupEnv.getCurrent().getResource())
    stack.loop(timeout=0.5, discrete=0.5)
    def prepare_stack(self, credentials, messages):
        stackBuilder = YowStackBuilder()
        stack = stackBuilder.pushDefaultLayers(True).push(EchoLayer).build()

        stack.setProp("messages", messages)
        stack.setCredentials(credentials)

        stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))

        return stack
    def prepare_stack(self, credentials, messages):
        stackBuilder = YowStackBuilder()
        stack = stackBuilder.pushDefaultLayers(True).push(EchoLayer).build()

        stack.setProp("messages", messages)
        stack.setCredentials(credentials)

        stack.broadcastEvent(YowLayerEvent(
            YowNetworkLayer.EVENT_STATE_CONNECT))

        return stack
Example #7
0
    def __init__(self,
                 credentials,
                 date,
                 encryptionEnabled=True,
                 verbose=False):
        stackBuilder = YowStackBuilder()

        self.stack = stackBuilder.pushDefaultLayers(encryptionEnabled).push(
            YowsupNewsbotLayer(date, verbose)).build()

        self.stack.setCredentials(credentials)
        self.stack.setProp(PROP_IDENTITY_AUTOTRUST, True)
Example #8
0
    def loop(self):
        # set the yowsup environment - not supported in fork
        # YowsupEnv.setEnv(self.yowsup_env)

        stackBuilder = YowStackBuilder()
        # Create the default stack (a pile of layers) and add the Ongair Layer to the top of the stack
        stack = stackBuilder.pushDefaultLayers(True).push(OngairLayer).build()

        ping_interval = int(get_env('ping_interval'))

        # Set the phone number as a property that can be read by other layers
        stack.setProp(YowIqProtocolLayer.PROP_PING_INTERVAL, ping_interval)
        stack.setProp('ongair.account', self.phone_number)
        stack.setProp(YowNetworkLayer.PROP_ENDPOINT,
                      YowConstants.ENDPOINTS[0])  # whatsapp server address
        stack.setProp(YowCoderLayer.PROP_DOMAIN, YowConstants.DOMAIN)

        # Broadcast the login event. This gets handled by the OngairLayer
        stack.broadcastEvent(YowLayerEvent(OngairLayer.EVENT_LOGIN))

        try:
            # Run the asyncore loop
            stack.loop(timeout=0.5,
                       discrete=0.5)  # this is the program mainloop
        except AttributeError:
            # for now this is a proxy for ProtocolException i.e. where yowsup has tried to read an
            # attribute that does not exist
            self.logger.exception("Attribute error")
            rollbar.report_exc_info()
            sys.exit(0)
        except AssertionError:
            # this is a proxy for a wrong expected attribute
            self.logger.exception("Assertion error")
            rollbar.report_exc_info()
            sys.exit(0)
        except KeyboardInterrupt:
            # manually stopped. more a development debugging issue
            self.logger.info("Manually interupted")
            sys.exit(2)
        except PingTimeoutError:
            self.logger.info("Ping timeout error")
            sys.exit(2)
        except RequestedDisconnectError:
            self.logger.info("We requested to disconnect")
            sys.exit(2)
        except ConnectionClosedError:
            self.logger.info("Disconnected")
            sys.exit(2)
        except:
            self.logger.exception("Unknown error")
            rollbar.report_exc_info()
            # do not restart as we are not sure what the problem is
            sys.exit(0)
Example #9
0
    def loop(self):
        # set the yowsup environment - not supported in fork
        # YowsupEnv.setEnv(self.yowsup_env)

        stackBuilder = YowStackBuilder()
        # Create the default stack (a pile of layers) and add the Ongair Layer to the top of the stack
        stack = stackBuilder.pushDefaultLayers(True).push(OngairLayer).build()

        ping_interval = int(get_env('ping_interval'))            

        # Set the phone number as a property that can be read by other layers
        stack.setProp(YowIqProtocolLayer.PROP_PING_INTERVAL, ping_interval)
        stack.setProp('ongair.account', self.phone_number)
        stack.setProp(YowNetworkLayer.PROP_ENDPOINT, YowConstants.ENDPOINTS[0])  # whatsapp server address
        stack.setProp(YowCoderLayer.PROP_DOMAIN, YowConstants.DOMAIN)

        # Broadcast the login event. This gets handled by the OngairLayer
        stack.broadcastEvent(YowLayerEvent(OngairLayer.EVENT_LOGIN))        

        try:
            # Run the asyncore loop
            stack.loop(timeout=0.5, discrete=0.5)  # this is the program mainloop
        except AttributeError:
            # for now this is a proxy for ProtocolException i.e. where yowsup has tried to read an 
            # attribute that does not exist
            self.logger.exception("Attribute error")
            rollbar.report_exc_info()
            sys.exit(0)
        except AssertionError:
            # this is a proxy for a wrong expected attribute 
            self.logger.exception("Assertion error")
            rollbar.report_exc_info()
            sys.exit(0)
        except KeyboardInterrupt:
            # manually stopped. more a development debugging issue
            self.logger.info("Manually interupted")
            sys.exit(2)
        except PingTimeoutError:
            self.logger.info("Ping timeout error")
            sys.exit(2)
        except RequestedDisconnectError:
            self.logger.info("We requested to disconnect")
            sys.exit(2)
        except ConnectionClosedError:
            self.logger.info("Disconnected")
            sys.exit(2)
        except:
            self.logger.exception("Unknown error")
            rollbar.report_exc_info()
            # do not restart as we are not sure what the problem is
            sys.exit(0)
Example #10
0
def run(phone, password):

    # credentials = (phone.encode(), password.encode())

    stackBuilder = YowStackBuilder()

    stack = stackBuilder.pushDefaultLayers(True).push(BotLayer()).build()

    # Setting credentials
    stack.setCredentials((phone, password))

    # Whatsapp server address
    stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))

    stack.loop()
Example #11
0
    def __init__(self, num, token, read=False):
        # TODO: user/.yowsup/phonenumber/axolotl.db must be removed if someone changed device, else untrusted identity
        self.read_notify = read

        self.echoLayer = EchoLayer()
        stackBuilder = YowStackBuilder()
        self.stack = stackBuilder.pushDefaultLayers(True).push(
            self.echoLayer).build()

        # credentials
        self.credentials = (num, token)
        logger.info('Connecting as {}'.format(num))

        self.stack.setCredentials(self.credentials)

        self.stack.broadcastEvent(
            YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT)
        )  # sending the connect signal

        self.thread = threading.Thread(
            target=self.stack.loop)  # message receiver thread
Example #12
0
    def __init__(self, credentials):
        """
        layers = (ReceiveLayer,
                  (YowAuthenticationProtocolLayer,
                   YowMessagesProtocolLayer,
                   YowReceiptProtocolLayer,
                   YowAckProtocolLayer,
                   YowMediaProtocolLayer),
                  YowCoderLayer,
                  YowCryptLayer,
                  YowStanzaRegulator,
                  YowNetworkLayer)

        self.stack = YowStack(layers)
        self.stack.setProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS, credentials)
        self.stack.setProp(YowNetworkLayer.PROP_ENDPOINT, YowConstants.ENDPOINTS[0])
        self.stack.setProp(YowCoderLayer.PROP_DOMAIN, YowConstants.DOMAIN)
"""
        stackBuilder = YowStackBuilder()

        self.stack = stackBuilder.pushDefaultLayers(True).push(EchoLayer).build()
        self.stack.setCredentials(credentials)
Example #13
0
from yowsup.layers.network import YowNetworkLayer
from yowsup.layers import YowLayerEvent
from yowsup.stacks import YowStackBuilder
from palayer import PictureArchiverLayer
from config import CREDENTIALS

if __name__==  "__main__":
    stackbuilder = YowStackBuilder()

    stack = stackbuilder.pushDefaultLayers(True).push(PictureArchiverLayer).build()

    stack.setCredentials(CREDENTIALS)
    stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))

    stack.loop()

Example #14
0
from yowsup.layers.network import YowNetworkLayer
from yowsup.stacks import YowStackBuilder
from palayer import PictureArchiverLayer
from config import CREDENTIALS
from yowsup.layers.axolotl.props import PROP_IDENTITY_AUTOTRUST

stackbuilder = YowStackBuilder()

stack = stackbuilder.pushDefaultLayers(True).push(PictureArchiverLayer).build()

stack.setCredentials(CREDENTIALS)
stack.setProp(PROP_IDENTITY_AUTOTRUST, True)
while True:
    stack.getLayerInterface(YowNetworkLayer).connect()
    stack.loop()

Example #15
0
from yowsup.stacks import  YowStackBuilder
from layer import SendLayer
from yowsup.layers.auth import AuthError
from yowsup.layers import YowLayerEvent
from yowsup.layers.auth import YowAuthenticationProtocolLayer
from yowsup.layers.network import YowNetworkLayer


CREDENTIALS = ("917639905993", "RvA9EAe0Io3eUU+A2bJ19KxsYkA=") # replace with your phone and password

if __name__==  "__main__":

    stackBuilder = YowStackBuilder()

    stack = stackBuilder.pushDefaultLayers(True).push(SendLayer).build()
    messages = [
        ("*****@*****.**" , "Hello yo albin"),
    ]

    stack.setProp(SendLayer.PROP_MESSAGES, messages)
    stack.setProp(YowAuthenticationProtocolLayer.PROP_PASSIVE, True)
    stack.setProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS, CREDENTIALS)
    # stack.setCredentials(credentials)

    stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))   #sending the connect signal

    stack.loop() #this is the program mainloop
Example #16
0
        for msg in raw_messages:
            stack.send_message(msg['phone'] + '@s.whatsapp.net',
                               msg['message'])
            bot.expire_reminder(msg)


if __name__ == "__main__":

    setup()

    stackBuilder = YowStackBuilder()

    send_layer = SendLayer()

    stack = stackBuilder.pushDefaultLayers(True).push(send_layer).build()

    stack.setProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS, CREDENTIALS)
    stack.setProp(YowNetworkLayer.PROP_ENDPOINT, YowConstants.ENDPOINTS[0])
    stack.setProp(YowCoderLayer.PROP_DOMAIN, YowConstants.DOMAIN)
    stack.setProp(YowCoderLayer.PROP_RESOURCE,
                  YowsupEnv.getCurrent().getResource())
    stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))

    try:

        print("Starting thread")

        t = Thread(target=check_for_reminder_messages, args=(send_layer, ))
        t.start()