Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sync contacts Unsuccessful, no result returned #3259

Open
xkjdiao opened this issue Apr 21, 2024 · 0 comments
Open

sync contacts Unsuccessful, no result returned #3259

xkjdiao opened this issue Apr 21, 2024 · 0 comments
Assignees

Comments

@xkjdiao
Copy link

xkjdiao commented Apr 21, 2024

Syncing a contact returns no results, and the person is not visible from the contact side, synchronization fails, if you can't sync the contact, then there is no point in sending this library.
Who can help me solve this problem?

stack.py
`import time

from yowsup.stacks import YowStackBuilder
from layer import SyncLayer
from stack import YowsupSyncStack
from yowsup.layers import YowLayerEvent
from yowsup.layers.network import YowNetworkLayer
from yowsup.profile.profile import YowProfile
import sys

from yowsup.layers import YowParallelLayer
from yowsup.layers.auth import YowAuthenticationProtocolLayer
from yowsup.layers.protocol_messages import YowMessagesProtocolLayer
from yowsup.layers.protocol_receipts import YowReceiptProtocolLayer
from yowsup.layers.protocol_acks import YowAckProtocolLayer
from yowsup.layers.network import YowNetworkLayer
from yowsup.layers.coder import YowCoderLayer
from yowsup.layers.protocol_presence import YowPresenceProtocolLayer
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
from yowsup.layers.auth import YowAuthenticationProtocolLayer

import sys,logging,threading

from yowsup import logger as yowlogger, formatter
logger = logging.getLogger('yowsup-cli')
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)

# add formatter to ch

ch.setFormatter(formatter)

# add ch to logger

logger.addHandler(ch)

def add_contacts(phone):
username = '6285867178214'
logger.setLevel(logging.DEBUG)
yowlogger.setLevel(level=logging.DEBUG)

stackBuilder = YowStackBuilder()
PROP_MESSAGES = "org.openwhatsapp.yowsup.prop.sendclient.queue"
stack = stackBuilder \
    .pushDefaultLayers() \
    .push(SyncLayer) \
    .build()
stack.setProp(SyncLayer.PROP_CONTACTS, phone)
stack.setProp(YowAuthenticationProtocolLayer.PROP_PASSIVE, True)
stack.setProfile(YowProfile(username))
stack.broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
stack.loop()

if name== "main":

contacts=[
    '6282116336279','6285198354865','6285475421'
]

add_contacts(contacts)

`

layer.py
`from yowsup.layers.interface import YowInterfaceLayer, ProtocolEntityCallback
from yowsup.layers.protocol_contacts.protocolentities import GetSyncIqProtocolEntity, ResultSyncIqProtocolEntity
from yowsup.layers.protocol_iq.protocolentities import ErrorIqProtocolEntity
import threading
import logging
logger = logging.getLogger(name)

class SyncLayer(YowInterfaceLayer):

PROP_CONTACTS = "org.openwhatsapp.yowsup.prop.syncdemo.contacts"

def __init__(self):
    super(SyncLayer, self).__init__()

@ProtocolEntityCallback("success")
def onSuccess(self, successProtocolEntity):
    contacts= self.getProp(self.__class__.PROP_CONTACTS, [])

    contactEntity = GetSyncIqProtocolEntity(contacts)
    self._sendIq(contactEntity, self.onGetSyncResult, self.onGetSyncError)

def onGetSyncResult(self, resultSyncIqProtocolEntity, originalIqProtocolEntity):
    print(resultSyncIqProtocolEntity)
    raise KeyboardInterrupt()

def onGetSyncError(self, errorSyncIqProtocolEntity, originalIqProtocolEntity):
    print(errorSyncIqProtocolEntity)
    raise KeyboardInterrupt()




@ProtocolEntityCallback("iq")
def onSyncSuccess(self, success_iq_protocol_entity):
    if success_iq_protocol_entity.getType() == "result":
        print("Sync successful!")
    else:
        print("Unknown success type")

def onSyncError(self, error_iq_protocol_entity):
    print("Sync error: {}".format(error_iq_protocol_entity))

def onIqError(self, error_iq_protocol_entity):
    if isinstance(error_iq_protocol_entity,ErrorIqProtocolEntity):
        print("Sync error: {}".format(error_iq_protocol_entity))`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants