Esempio n. 1
0
    def __init__(self, credentials, contacts, encryptionEnabled=False):
        """
        :param credentials:
        :param contacts: list of [jid ]
        :param encryptionEnabled:
        :return:
        """
        if encryptionEnabled:
            from yowsup.layers.axolotl import YowAxolotlLayer
            layers = (SyncLayer,
                      YowParallelLayer([
                          YowAuthenticationProtocolLayer,
                          YowContactsIqProtocolLayer, YowReceiptProtocolLayer,
                          YowAckProtocolLayer
                      ]), YowAxolotlLayer, YowLoggerLayer, YowCoderLayer,
                      YowCryptLayer, YowStanzaRegulator, YowNetworkLayer)
        else:
            layers = (SyncLayer,
                      YowParallelLayer([
                          YowAuthenticationProtocolLayer,
                          YowContactsIqProtocolLayer, YowReceiptProtocolLayer,
                          YowAckProtocolLayer
                      ]), YowLoggerLayer, YowCoderLayer, YowCryptLayer,
                      YowStanzaRegulator, YowNetworkLayer)

        self.stack = YowStack(layers)
        self.stack.setProp(SyncLayer.PROP_CONTACTS, contacts)
        self.stack.setProp(YowAuthenticationProtocolLayer.PROP_PASSIVE, True)
        self.stack.setCredentials(credentials)
Esempio n. 2
0
    def __init__(self, credentials, messages, encryptionEnabled = False):
        """
        :param credentials:
        :param messages: list of (jid, message) tuples
        :param encryptionEnabled:
        :return:
        """
        if encryptionEnabled:
            from yowsup.layers.axolotl                     import YowAxolotlLayer
            layers = (
                SendLayer,
                YowParallelLayer([YowAuthenticationProtocolLayer, YowMessagesProtocolLayer, YowReceiptProtocolLayer, YowAckProtocolLayer]),
                YowAxolotlLayer,
                YowLoggerLayer,
                YowCoderLayer,
                YowCryptLayer,
                YowStanzaRegulator,
                YowNetworkLayer
            )
        else:
            layers = (
                SendLayer,
                YowParallelLayer([YowAuthenticationProtocolLayer, YowMessagesProtocolLayer, YowReceiptProtocolLayer, YowAckProtocolLayer]),
                YowLoggerLayer,
                YowCoderLayer,
                YowCryptLayer,
                YowStanzaRegulator,
                YowNetworkLayer
            )

        self.stack = YowStack(layers)
        self.stack.setProp(SendLayer.PROP_MESSAGES, messages)
        self.stack.setProp(YowAuthenticationProtocolLayer.PROP_PASSIVE, True)
        self.stack.setCredentials(credentials)
Esempio n. 3
0
def recv_message():
    layers = (
        EchoLayer,
        YowParallelLayer([
            YowAuthenticationProtocolLayer, YowMessagesProtocolLayer,
            YowReceiptProtocolLayer, YowAckProtocolLayer
        ]),
        AxolotlControlLayer,
        YowParallelLayer((AxolotlSendLayer, AxolotlReceivelayer)),
    ) + YOWSUP_CORE_LAYERS

    stack = YowStack(layers)
    # Setting credentials
    stack.setProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS, CREDENTIALS)

    # WhatsApp server address
    stack.setProp(YowNetworkLayer.PROP_ENDPOINT, YowConstants.ENDPOINTS[0])
    stack.setProp(YowCoderLayer.PROP_DOMAIN, YowConstants.DOMAIN)
    stack.setProp(YowCoderLayer.PROP_RESOURCE,
                  YowsupEnv.getCurrent().getResource())

    # Sending connecting signal
    stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
    try:
        # Program main loop
        stack.loop()
    except AuthError as e:
        print('Authentication error %s' % e.message)
        sys.exit(1)
Esempio n. 4
0
def run(wttQueue, ttwQueue, config):
    logger.info("Starting Whatsapp Self-Bot")

    keypair = KeyPair.from_bytes(
        base64.b64decode(config["client_static_keypair"]))

    credentials = (config["phone"], keypair)

    layers = (
        WhatsappLayer(wttQueue, ttwQueue),
        YowParallelLayer([
            YowAuthenticationProtocolLayer, YowMessagesProtocolLayer,
            YowReceiptProtocolLayer, YowAckProtocolLayer, YowIqProtocolLayer,
            YowGroupsProtocolLayer, YowMediaProtocolLayer
        ]),
        AxolotlControlLayer,
        YowParallelLayer((AxolotlSendLayer, AxolotlReceivelayer)),
    ) + YOWSUP_CORE_LAYERS

    stack = YowStack(layers)
    stack.setProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS,
                  credentials)  # setting credentials
    stack.setProp(YowNetworkLayer.PROP_ENDPOINT,
                  YowConstants.ENDPOINTS[0])  # whatsapp server address
    # stack.setProp(YowCoderLayer.PROP_DOMAIN, YowConstants.DOMAIN)
    # stack.setProp(YowCoderLayer.PROP_RESOURCE, YowsupEnv.getCurrent().getResource()) #info about us as WhatsApp client

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

    stack.loop()
Esempio n. 5
0
    def getDefaultLayers(groups = True, media = True, privacy = True, profiles = True):
        coreLayers = YowStackBuilder.getCoreLayers()
        protocolLayers = YowStackBuilder.getProtocolLayers(groups = groups, media=media, privacy=privacy, profiles=profiles)

        allLayers = coreLayers
        allLayers += (AxolotlControlLayer,)
        allLayers += (YowParallelLayer((AxolotlSendLayer, AxolotlReceivelayer)),)

        allLayers += (YowParallelLayer(protocolLayers),)

        return allLayers
Esempio n. 6
0
    def __init__(self,
                 imap_data,
                 smtp_data,
                 credentials,
                 encryptionEnabled=False):
        if encryptionEnabled:
            layers = (YowParallelLayer(
                (YowAuthenticationProtocolLayer, YowMessagesProtocolLayer,
                 YowReceiptProtocolLayer, YowAckProtocolLayer,
                 YowMediaProtocolLayer, YowIqProtocolLayer,
                 YowCallsProtocolLayer), ), YowAxolotlLayer, YowLoggerLayer,
                      YowCoderLayer, YowCryptLayer, YowStanzaRegulator,
                      YowTwistedNetworkLayer)
        else:
            env.CURRENT_ENV = env.S40YowsupEnv()
            layers = (YowParallelLayer(
                (YowAuthenticationProtocolLayer, YowMessagesProtocolLayer,
                 YowReceiptProtocolLayer, YowAckProtocolLayer,
                 YowMediaProtocolLayer, YowIqProtocolLayer,
                 YowCallsProtocolLayer), ), YowLoggerLayer, YowCoderLayer,
                      YowCryptLayer, YowStanzaRegulator,
                      YowTwistedNetworkLayer)

        if smtp_data:
            layers = (YowTwistedSmtpLayer, ) + layers

        if imap_data:
            layers = (YowTwistedImapLayer, ) + layers

        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)
        self.stack.setProp(YowCoderLayer.PROP_RESOURCE,
                           env.CURRENT_ENV.getResource())

        if smtp_data:
            self.stack.setProp(YowTwistedSmtpLayer.PROP_USER, smtp_data[0])
            self.stack.setProp(YowTwistedSmtpLayer.PROP_PASS, smtp_data[1])
            self.stack.setProp(YowTwistedSmtpLayer.PROP_ENDPOINT, smtp_data[2])
            self.stack.setProp(YowTwistedSmtpLayer.PROP_DST_MAIL, smtp_data[3])
            self.stack.setProp(YowTwistedSmtpLayer.PROP_REPLY_MAIL,
                               smtp_data[4])

        if imap_data:
            self.stack.setProp(YowTwistedImapLayer.PROP_USER, imap_data[0])
            self.stack.setProp(YowTwistedImapLayer.PROP_PASS, imap_data[1])
            self.stack.setProp(YowTwistedImapLayer.PROP_ENDPOINT, imap_data[2])
            self.stack.setProp(YowTwistedImapLayer.PROP_DST_PHONE,
                               imap_data[3])
Esempio n. 7
0
	def __init__(self):
		env.CURRENT_ENV = env.S40YowsupEnv()

		layers = (YowsupAppLayer,
				YowParallelLayer((YowAuthenticationProtocolLayer,
					YowMessagesProtocolLayer,
					YowReceiptProtocolLayer,
					YowAckProtocolLayer,
					YowMediaProtocolLayer,
					YowIbProtocolLayer,
					YowIqProtocolLayer,
					YowNotificationsProtocolLayer,
					YowContactsIqProtocolLayer,
					YowChatstateProtocolLayer,
					YowCallsProtocolLayer,
					YowPrivacyProtocolLayer,
					YowProfilesProtocolLayer,
					YowGroupsProtocolLayer,
					YowPresenceProtocolLayer)),
				YowAxolotlLayer,
				YowCoderLayer,
				YowCryptLayer,
				YowStanzaRegulator,
				YowNetworkLayer
		)
		self.logger = logging.getLogger(self.__class__.__name__)
		self.stack = YowStack(layers)
		self.stack.broadcastEvent(
			YowLayerEvent(YowsupAppLayer.EVENT_START, caller = self)
		)
Esempio n. 8
0
    def _construct(self):
        logger.debug("Initializing stack")
        for s in self.__stack:
            if type(s) is tuple:
                logger.warn(
                    "Implicit declaration of parallel layers in a tuple is deprecated, pass a YowParallelLayer instead"
                )
                inst = YowParallelLayer(s)
            else:
                if inspect.isclass(s):
                    if issubclass(s, YowLayer):
                        inst = s()
                    else:
                        raise ValueError(
                            "Stack must contain only subclasses of YowLayer")
                elif issubclass(s.__class__, YowLayer):
                    inst = s
                else:
                    raise ValueError(
                        "Stack must contain only subclasses of YowLayer")
                #inst = s()
            logger.debug("Constructed %s" % inst)
            inst.setStack(self)
            self.__stackInstances.append(inst)

        for i in range(0, len(self.__stackInstances)):
            upperLayer = self.__stackInstances[i + 1] if (i + 1) < len(
                self.__stackInstances) else None
            lowerLayer = self.__stackInstances[i - 1] if i > 0 else None
            self.__stackInstances[i].setLayers(upperLayer, lowerLayer)
Esempio n. 9
0
    def __init__(self, smarthome, account, password, trusted=None, logic='Whatsapp', cli_mode='False'):
# Set Plugin Attributes
        self._sh = smarthome
        self._credentials = (account, password.encode('utf-8'))
        self._trusted = trusted
        self._logic = logic
        self._run = False
        if cli_mode == 'True':
            self._cli_mode = True
            return
        else:
            self._cli_mode = False
# Yowsup Layers
        self._layers = (
            SmarthomeLayer,
            YowParallelLayer((YowAuthenticationProtocolLayer, YowMessagesProtocolLayer, YowReceiptProtocolLayer, YowAckProtocolLayer, YowIbProtocolLayer, YowIqProtocolLayer, YowNotificationsProtocolLayer, YowPresenceProtocolLayer)),
            YowCoderLayer,
#            YowLoggerLayer,
            YowCryptLayer,
            YowStanzaRegulator,
            YowNetworkLayer)

# Yowsup Properties
        self._stack = YowStack(self._layers)
        self._stack.setProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS, self._credentials)
        self._stack.setProp(YowNetworkLayer.PROP_ENDPOINT, YowConstants.ENDPOINTS[0])
        self._stack.setProp(YowCoderLayer.PROP_DOMAIN, YowConstants.DOMAIN)
        self._stack.setProp(YowCoderLayer.PROP_RESOURCE, env.CURRENT_ENV.getResource())

# Connect Yowsup
        self._stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))

# Get SmarthomeLayer and set this Plugin
        self._SmarthomeLayer = self._stack.getLayer(len(self._stack._YowStack__stack) - 1)
        self._SmarthomeLayer.setPlugin(self)
Esempio n. 10
0
    def __init__(self, credentials):
        "Creates the stacks of the Yowsup Server,"
        self.credentials = credentials
        stack_builder = YowStackBuilder().pushDefaultLayers(True)

        # on the top stack, the two layers that controls the bot and respond to messages and notifications
        # see both of classes for more documentation
        stack_builder.push(YowParallelLayer([EchoLayer]))
        self.stack = stack_builder.build()
        self.stack.setCredentials(credentials)
Esempio n. 11
0
    def getDefaultLayers(axolotl=False,
                         groups=True,
                         privacy=True,
                         profiles=True):
        coreLayers = YowStackBuilder.getCoreLayers()
        protocolLayers = YowStackBuilder.getProtocolLayers(groups=groups,
                                                           privacy=privacy,
                                                           profiles=profiles)

        allLayers = coreLayers
        if axolotl:
            from yowsup.layers.axolotl import AxolotlSendLayer, AxolotlControlLayer, AxolotlReceivelayer
            allLayers += (AxolotlControlLayer, )
            allLayers += (YowParallelLayer(
                (AxolotlSendLayer, AxolotlReceivelayer)), )

        allLayers += (YowParallelLayer(protocolLayers), )

        return allLayers
Esempio n. 12
0
 def __init__(self, credentials):
     """Default Yowsup setup, with the Route Layer on top"""
     layers = (RouteLayer,
               YowParallelLayer([YowAuthenticationProtocolLayer,
                                 YowMessagesProtocolLayer,
                                 YowReceiptProtocolLayer,
                                 YowAckProtocolLayer,
                                 YowMediaProtocolLayer,
                                 YowIqProtocolLayer]),
               YowAxolotlLayer,
               ) + YOWSUP_CORE_LAYERS
     self.stack = YowStack(layers)
     self.stack.setCredentials(credentials)
Esempio n. 13
0
    def getDefaultLayers(axolotl=False, groups=True, media=True, privacy=True):
        coreLayers = YowStackBuilder.getCoreLayers()
        protocolLayers = YowStackBuilder.getProtocolLayers(groups=groups,
                                                           media=media,
                                                           privacy=privacy)

        allLayers = coreLayers
        if axolotl:
            allLayers += (YowAxolotlLayer, )

        allLayers += (YowParallelLayer(protocolLayers), )

        return allLayers
Esempio n. 14
0
    def __init__(self, credentials, allowed_users, encryptionEnabled=False):
        if encryptionEnabled:
            from yowsup.layers.axolotl import YowAxolotlLayer
            layers = (CommandServerLayer(allowed_users),
                      YowParallelLayer([
                          YowAuthenticationProtocolLayer,
                          YowMessagesProtocolLayer, YowReceiptProtocolLayer,
                          YowAckProtocolLayer, YowMediaProtocolLayer,
                          YowIqProtocolLayer, YowCallsProtocolLayer
                      ]), YowAxolotlLayer, YowLoggerLayer, YowCoderLayer,
                      YowCryptLayer, YowStanzaRegulator, YowNetworkLayer)
        else:
            layers = (CommandServerLayer(allowed_users),
                      YowParallelLayer([
                          YowAuthenticationProtocolLayer,
                          YowMessagesProtocolLayer, YowReceiptProtocolLayer,
                          YowAckProtocolLayer, YowMediaProtocolLayer,
                          YowIqProtocolLayer, YowCallsProtocolLayer
                      ]), YowLoggerLayer, YowCoderLayer, YowCryptLayer,
                      YowStanzaRegulator, YowNetworkLayer)

        self.stack = YowStack(layers)
        self.stack.setCredentials(credentials)
Esempio n. 15
0
    def __init__(self, encryption_enabled=True):
        if encryption_enabled:
            from yowsup.layers.axolotl import YowAxolotlLayer
            layers = (EchoLayer,
                      YowParallelLayer([
                          YowAuthenticationProtocolLayer,
                          YowMessagesProtocolLayer, YowReceiptProtocolLayer,
                          YowAckProtocolLayer, YowMediaProtocolLayer,
                          YowIqProtocolLayer, YowCallsProtocolLayer
                      ]), YowAxolotlLayer, YowLoggerLayer, YowCoderLayer,
                      YowCryptLayer, YowStanzaRegulator, YowNetworkLayer)
        else:
            layers = (EchoLayer,
                      YowParallelLayer([
                          YowAuthenticationProtocolLayer,
                          YowMessagesProtocolLayer, YowReceiptProtocolLayer,
                          YowAckProtocolLayer, YowMediaProtocolLayer,
                          YowIqProtocolLayer, YowCallsProtocolLayer
                      ]), YowLoggerLayer, YowCoderLayer, YowCryptLayer,
                      YowStanzaRegulator, YowNetworkLayer)

        self.stack = YowStack(layers)
        self.stack.setCredentials(settings.CREDENTIALS)
Esempio n. 16
0
def send_message(destination, message):
    '''
    destination is <phone number> without '+'
    and with country code of type string,
    message is string
    e.g send_message('11133434343','hello')
    '''
    messages = [(destination, message)]
    layers = (
        EchoLayer,
        YowParallelLayer([
            YowAuthenticationProtocolLayer, YowMessagesProtocolLayer,
            YowReceiptProtocolLayer, YowAckProtocolLayer
        ]),
        AxolotlControlLayer,
        YowParallelLayer((AxolotlSendLayer, AxolotlReceivelayer)),
    ) + YOWSUP_CORE_LAYERS
    stack = YowStack(layers)
    stack.setProp(EchoLayer.PROP_MESSAGES, messages)
    stack.setProp(YowAuthenticationProtocolLayer.PROP_PASSIVE, True)
    # Setting credentials
    stack.setProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS, CREDENTIALS)

    # WhatsApp server address
    stack.setProp(YowNetworkLayer.PROP_ENDPOINT, YowConstants.ENDPOINTS[0])
    stack.setProp(YowCoderLayer.PROP_DOMAIN, YowConstants.DOMAIN)
    stack.setProp(YowCoderLayer.PROP_RESOURCE,
                  YowsupEnv.getCurrent().getResource())

    # Sending connecting signal
    stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
    try:
        # Program main loop
        stack.loop()
    except AuthError as e:
        print('Authentication error %s' % e.message)
        sys.exit(1)
Esempio n. 17
0
	def __init__(self):
		env.CURRENT_ENV = env.AndroidYowsupEnv()

		layers = (YowsupAppLayer,
				YowParallelLayer((YowAuthenticationProtocolLayer,
					YowMessagesProtocolLayer,
					YowReceiptProtocolLayer,
					YowAckProtocolLayer,
					YowMediaProtocolLayer,
					YowIbProtocolLayer,
					YowIqProtocolLayer,
					YowNotificationsProtocolLayer,
					YowContactsIqProtocolLayer,
					YowChatstateProtocolLayer,
					YowCallsProtocolLayer,
					YowPrivacyProtocolLayer,
					YowProfilesProtocolLayer,
					YowGroupsProtocolLayer,
					YowPresenceProtocolLayer)),
				AxolotlControlLayer,
				YowParallelLayer((AxolotlSendLayer, AxolotlReceivelayer)),
				YowCoderLayer,
				YowCryptLayer,
				YowStanzaRegulator,
				YowNetworkLayer
		)

		self.logger = logging.getLogger(self.__class__.__name__)
		stackBuilder = YowStackBuilder()

		self.stack = stackBuilder \
			.pushDefaultLayers(True) \
			.push(YowsupAppLayer) \
			.build()
		self.stack.broadcastEvent(
			YowLayerEvent(YowsupAppLayer.EVENT_START, caller = self)
		)
Esempio n. 18
0
    def _construct(self):
        logger.debug("Initializing stack")
        for s in self.__stack:
            if type(s) is tuple:
                inst = YowParallelLayer(s)
            else:
                inst = s()
            logger.debug("Constructed %s" % inst)
            inst.setStack(self)
            self.__stackInstances.append(inst)

        for i in range(0, len(self.__stackInstances)):
            upperLayer = self.__stackInstances[i + 1] if (i + 1) < len(
                self.__stackInstances) else None
            lowerLayer = self.__stackInstances[i - 1] if i > 0 else None
            self.__stackInstances[i].setLayers(upperLayer, lowerLayer)
Esempio n. 19
0
    def getDefaultLayers(axolotl=False,
                         groups=True,
                         media=True,
                         privacy=True,
                         profiles=True):
        coreLayers = YowStackBuilder.getCoreLayers()
        protocolLayers = YowStackBuilder.getProtocolLayers(groups=groups,
                                                           media=media,
                                                           privacy=privacy,
                                                           profiles=profiles)

        allLayers = coreLayers
        if axolotl:
            from yowsup.layers.axolotl import YowAxolotlLayer
            allLayers += (YowAxolotlLayer, )

        allLayers += (YowParallelLayer(protocolLayers), )

        return allLayers
Esempio n. 20
0
    def run(self):
        layers = (EchoLayer,
                  YowParallelLayer([
                      YowAuthenticationProtocolLayer, YowMessagesProtocolLayer,
                      YowReceiptProtocolLayer, YowAckProtocolLayer
                  ]), YowAxolotlLayer) + YOWSUP_CORE_LAYERS

        stack = YowStack(layers)
        stack.setProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS,
                      CREDENTIALS)  #setting credentials
        stack.setProp(YowNetworkLayer.PROP_ENDPOINT,
                      YowConstants.ENDPOINTS[0])  #whatsapp server address
        stack.setProp(YowCoderLayer.PROP_DOMAIN, YowConstants.DOMAIN)
        stack.setProp(
            YowCoderLayer.PROP_RESOURCE,
            env.CURRENT_ENV.getResource())  #info about us as WhatsApp client

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

        stack.loop()  #this is the program mainloop
Esempio n. 21
0
class YowsupDaemon(Daemon):

    def run(self):
		credentials = settings.get('Yowsup')
        phone = credentials['phone']
        password = credentials['pwd']
        CREDENTIALS = (phone, password) # replace with your phone and password
        logging.basicConfig(level = logging.DEBUG)
        layers = (
        HomeLayer,
        YowParallelLayer([YowAuthenticationProtocolLayer, YowMessagesProtocolLayer, YowReceiptProtocolLayer, YowAckProtocolLayer]),YowAxolotlLayer
        ) + YOWSUP_CORE_LAYERS

        stack = YowStack(layers)
        stack.setProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS, CREDENTIALS)         #setting credentials
        stack.setProp(YowNetworkLayer.PROP_ENDPOINT, YowConstants.ENDPOINTS[0])    #whatsapp server address
        stack.setProp(YowCoderLayer.PROP_DOMAIN, YowConstants.DOMAIN)
        stack.setProp(YowCoderLayer.PROP_RESOURCE, YowsupEnv.getCurrent().getResource())          #info about us as WhatsApp client

        stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))   #sending the connect signal
        stack.loop() #this is the program mainloop
Esempio n. 22
0
from yowsup.layers.protocol_iq import YowIqProtocolLayer
from yowsup.stacks import YowStack
from yowsup.common import YowConstants
from yowsup.layers import YowLayerEvent
from yowsup.stacks import YowStack, YOWSUP_CORE_LAYERS
from yowsup.layers.axolotl import YowAxolotlLayer
from yowsup.env import YowsupEnv

CREDENTIALS = ("CC9999999999", "password-here"
               )  # replace with your phone and password

if __name__ == "__main__":
    layers = (EchoLayer,
              YowParallelLayer([
                  YowAuthenticationProtocolLayer, YowIqProtocolLayer,
                  YowMessagesProtocolLayer, YowReceiptProtocolLayer,
                  YowAckProtocolLayer
              ]), YowAxolotlLayer) + YOWSUP_CORE_LAYERS

    stack = YowStack(layers)
    stack.setProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS,
                  CREDENTIALS)  #setting credentials
    stack.setProp(YowNetworkLayer.PROP_ENDPOINT,
                  YowConstants.ENDPOINTS[0])  #whatsapp server address
    stack.setProp(YowCoderLayer.PROP_DOMAIN, YowConstants.DOMAIN)
    stack.setProp(YowCoderLayer.PROP_RESOURCE,
                  YowsupEnv.getCurrent().getResource()
                  )  #info about us as WhatsApp client

    stack.broadcastEvent(YowLayerEvent(
        YowNetworkLayer.EVENT_STATE_CONNECT))  #sending the connect signal
Esempio n. 23
0
from RetransLayer import RetransLayer
from yowsup.layers import YowParallelLayer, YowLayerEvent
from yowsup.layers.protocol_receipts import YowReceiptProtocolLayer
from yowsup.layers.auth import YowAuthenticationProtocolLayer
from yowsup.layers.protocol_messages import YowMessagesProtocolLayer
from yowsup.layers.protocol_acks import YowAckProtocolLayer
from yowsup.layers.axolotl import AxolotlSendLayer, AxolotlControlLayer, AxolotlReceivelayer
from yowsup.layers.network import YowNetworkLayer
from yowsup.stacks import YowStack, YOWSUP_CORE_LAYERS

vk_credentials = (6376055, input('enter you vk login\n'),
                  input('enter you vk password\n'))
whatsapp_credentials = (
    input('enter you phone number for whatsapp\n'),
    input('enter the code you\'ve received via yowsup cli\n'))

AXOLOTL_LAYERS = (YowParallelLayer([AxolotlSendLayer,
                                    AxolotlReceivelayer]), AxolotlControlLayer)
layers = (RetransLayer,
          YowParallelLayer([
              YowAuthenticationProtocolLayer, YowMessagesProtocolLayer,
              YowAckProtocolLayer, YowReceiptProtocolLayer
          ])) + AXOLOTL_LAYERS + YOWSUP_CORE_LAYERS

stack = YowStack(layers)
stack.setProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS,
              whatsapp_credentials)
stack.setProp('vk_credentials', vk_credentials)
stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
stack.loop()
Esempio n. 24
0
from yowsup.layers.stanzaregulator import YowStanzaRegulator
from yowsup.layers.protocol_receipts import YowReceiptProtocolLayer
from yowsup.layers.protocol_acks import YowAckProtocolLayer
from yowsup.stacks import YowStack
from yowsup.common import YowConstants
from yowsup.layers import YowLayerEvent
from yowsup.layers.axolotl import YowAxolotlLayer
from yowsup.env import YowsupEnv

CREDENTIALS = ("phone number here", "password here"
               )  # replace with your phone and password

if __name__ == "__main__":
    layers = (Robotinic,
              YowParallelLayer([
                  YowAuthenticationProtocolLayer, YowMessagesProtocolLayer,
                  YowReceiptProtocolLayer, YowAckProtocolLayer
              ]), YowAxolotlLayer, YowCoderLayer, YowCryptLayer,
              YowStanzaRegulator, YowNetworkLayer)

    stack = YowStack(layers)
    stack.setProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS,
                  CREDENTIALS)  # setting credentials
    stack.setProp(YowNetworkLayer.PROP_ENDPOINT,
                  YowConstants.ENDPOINTS[0])  # whatsapp server address
    stack.setProp(YowCoderLayer.PROP_DOMAIN, YowConstants.DOMAIN)
    stack.setProp(YowCoderLayer.PROP_RESOURCE,
                  YowsupEnv.getCurrent().getResource()
                  )  # info about us as WhatsApp client

    stack.broadcastEvent(YowLayerEvent(
        YowNetworkLayer.EVENT_STATE_CONNECT))  # sending the connect signal
Esempio n. 25
0
def main():
    ''' Console script to start the bot or output default config file. '''
    # Arguments
    parser = argparse.ArgumentParser(
        description=_('Start Tombot, a chatbot for Whatsapp'))
    parser.add_argument('-v',
                        '--verbose',
                        help=_("enable debug logging"),
                        action='store_true')
    parser.add_argument('-d',
                        '--dry-run',
                        help=_("don't actually start bot, but print config"),
                        action='store_true')
    parser.add_argument(
        '-p',
        '--poke',
        action='store_true',
        help=_("do everything except connecting (for testing)"))
    parser.add_argument('configfile',
                        help=_("config file location"),
                        nargs='?')
    args = parser.parse_args()
    # Set up logging
    if args.verbose:
        loglevel = logging.DEBUG
    else:
        loglevel = logging.INFO
    logging.basicConfig(level=loglevel,
                        format='%(levelname)s - %(name)s - %(message)s')
    # Read configuration
    specpath = os.path.join(os.path.dirname(__file__), 'configspec.ini')
    config = ConfigObj(args.configfile, configspec=specpath)

    if not args.dry_run:
        config.validate(Validator())
        if not args.configfile:
            error = _("You must specify a config file!")
            generate_hint = _("Generate one using 'tombot -d > file.ini'.")
            logging.critical(error)
            logging.critical(generate_hint)
            sys.exit(1)

        # Build scheduler, will be started in the bot's layer once connected
        jobstores = {
            'default': SQLAlchemyJobStore(url='sqlite:///jobs.sqlite'),
        }
        scheduler = BackgroundScheduler(jobstores=jobstores)

        # Build Yowsup stack
        credentials = (config['Yowsup']['username'],
                       config['Yowsup']['password'])
        bot = TomBotLayer(config, scheduler)
        layers = (
            bot,
            YowParallelLayer([
                YowPresenceProtocolLayer, YowAuthenticationProtocolLayer,
                YowMessagesProtocolLayer, YowIqProtocolLayer,
                YowReceiptProtocolLayer, YowChatstateProtocolLayer,
                YowAckProtocolLayer, YowGroupsProtocolLayer
            ]),
            YowAxolotlLayer,
        ) + YOWSUP_CORE_LAYERS

        stack = YowStack(layers)
        # Set credentials, server address, info about us as WhatsApp client
        stack.setProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS,
                      credentials)
        stack.setProp(YowNetworkLayer.PROP_ENDPOINT, YowConstants.ENDPOINTS[0])
        stack.setProp(YowCoderLayer.PROP_DOMAIN, YowConstants.DOMAIN)

        # Send connect signal if we aren't poking at the bot
        if not args.poke:
            stack.broadcastEvent(
                YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))

            stack.loop(timeout=0.5,
                       discrete=0.5)  #this is the program mainloop
        else:
            code.interact(local=locals())
    else:
        # Output config file to stdout
        config.filename = None
        config.validate(Validator(), copy=True)
        output = config.write()
        for line in output:
            print(line)
Esempio n. 26
0
import ConfigParser
from configreader import FakeSecHead

config = ConfigParser.SafeConfigParser()
config.readfp(FakeSecHead(open('../yowsup.conf')))
PHONE = config.get('asection', 'phone')
PASS = config.get('asection', 'password')

CREDENTIALS = (PHONE, PASS)  # replace with your phone and password

if __name__ == "__main__":
    # import all required stacks
    layers = (
        EchoLayer,
        YowParallelLayer([
            YowAuthenticationProtocolLayer, YowMessagesProtocolLayer,
            YowReceiptProtocolLayer, YowMediaProtocolLayer, YowAckProtocolLayer
        ]),
        YowAxolotlLayer,  # required for reading encrypted messages
    ) + YOWSUP_CORE_LAYERS

    stack = YowStack(layers)
    stack.setProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS,
                  CREDENTIALS)  # setting credentials
    stack.setProp(YowNetworkLayer.PROP_ENDPOINT,
                  YowConstants.ENDPOINTS[0])  # whatsapp server address
    stack.setProp(YowCoderLayer.PROP_DOMAIN, YowConstants.DOMAIN)
    stack.setProp(
        YowCoderLayer.PROP_RESOURCE,
        env.CURRENT_ENV.getResource())  # info about us as WhatsApp client

    stack.broadcastEvent(YowLayerEvent(
Esempio n. 27
0
from yowsup.common import YowConstants
from yowsup.layers import YowLayerEvent
from yowsup.stacks import YowStack
from yowsup import env
import os

PHONE = os.environ["WHATSAPP_PHONE"]
PWD = os.environ["WHATSAPP_PWD"]
CREDENTIALS = (PHONE, PWD)

if __name__ == "__main__":
    layers = (WhatsappTunnel,
              YowParallelLayer((
                  YowAckProtocolLayer,
                  YowAuthenticationProtocolLayer,
                  YowMediaProtocolLayer,
                  YowMessagesProtocolLayer,
                  YowReceiptProtocolLayer,
              )), YowAxolotlLayer, YowLoggerLayer, YowCoderLayer,
              YowCryptLayer, YowStanzaRegulator, YowNetworkLayer)

    stack = YowStack(layers)

    # setting credentials
    stack.setProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS, CREDENTIALS)

    # Whatsapp server address
    stack.setProp(YowNetworkLayer.PROP_ENDPOINT, YowConstants.ENDPOINTS[0])
    stack.setProp(YowCoderLayer.PROP_DOMAIN, YowConstants.DOMAIN)

    # Info about us as WhatsApp client
Esempio n. 28
0
from yowsup.layers.network import YowNetworkLayer
from yowsup.layers.coder import YowCoderLayer
from yowsup.stacks import YowStack
from yowsup.common import YowConstants
from yowsup.layers import YowLayerEvent
from yowsup.stacks import YowStack, YOWSUP_CORE_LAYERS
from yowsup.layers.axolotl import AxolotlControlLayer, AxolotlSendLayer, AxolotlReceivelayer
from yowsup.env import YowsupEnv

CREDENTIALS = ("phone", "password")  # replace with your phone and password

if __name__ == "__main__":
    layers = (
        EchoLayer,
        YowParallelLayer([
            YowAuthenticationProtocolLayer, YowMessagesProtocolLayer,
            YowReceiptProtocolLayer, YowAckProtocolLayer
        ]),
        AxolotlControlLayer,
        YowParallelLayer((AxolotlSendLayer, AxolotlReceivelayer)),
    ) + YOWSUP_CORE_LAYERS

    stack = YowStack(layers)
    stack.setProp(YowAuthenticationProtocolLayer.PROP_CREDENTIALS,
                  CREDENTIALS)  #setting credentials
    stack.setProp(YowNetworkLayer.PROP_ENDPOINT,
                  YowConstants.ENDPOINTS[0])  #whatsapp server address
    stack.setProp(YowCoderLayer.PROP_DOMAIN, YowConstants.DOMAIN)
    stack.setProp(YowCoderLayer.PROP_RESOURCE,
                  YowsupEnv.getCurrent().getResource()
                  )  #info about us as WhatsApp client