Coder Social home page Coder Social logo

ttycelery / kyros Goto Github PK

View Code? Open in Web Editor NEW
103.0 13.0 27.0 251 KB

Python wrapper for WhatsApp Web API websocket communication (based on https://github.com/sigalor/whatsapp-web-reveng)

License: MIT License

Python 2.83% HTML 97.17%
kyros whatsapp whatsapp-automation unofficial-api python-api python3 hacktoberfest

kyros's Introduction

Important Note

This project is no longer maintained. As per this commit, I decided not to maintain the project anymore. Since last year, WhatsApp has been making many changes (most notably the offline feature) that directly affected this project. I have been so busy that I can't keep up with the pace, and I don't plan to continue it in the future either.

Thanks to anyone who has been using and/or helping with the development of this project.

If someone wants to continue the project (e.g. by making a fork), I would appreciate that.

Kyros

Kyros, for now, is a Python interface to communicate easier with WhatsApp Web API. It provides an interface to connect and communicate with WhatsApp Web's websocket server. Kyros will handle encryption and decryption kind of things. In the future, Kyros is aimed to provide a full implementation of WhatsApp Web API which will give developers a clean interface to work with (more or less like go-whatsapp). This module is designed to work with Python 3.6 or latest. Special thanks to the creator of whatsapp-web-reveng and go-whatsapp. This project is largely motivated by their work. Please note that Kyros is not meant to be used actively in production servers as it is currently not production ready. Use it at your own risk.

Installation

Kyros could be installed by using pip or directly cloning it then invoking setup.py. For example, if you want to use pip, run the following command:

pip install git+https://[email protected]/ttycelery/kyros

Documentation

A simple example

import asyncio
import logging

import pyqrcode

import kyros

logging.basicConfig()
# set a logging level: just to know if something (bad?) happens
logging.getLogger("kyros").setLevel(logging.WARNING)

async def main():
    # create the Client instance using create class method
    whatsapp = await kyros.Client.create()

    # do a QR login
    qr_data, scanned = await whatsapp.qr_login()

    # generate qr code image
    qr_code = pyqrcode.create(qr_data)
    print(qr_code.terminal(quiet_zone=1))

    try:
        # wait for the QR code to be scanned
        await scanned
    except asyncio.TimeoutError:
        # timed out (left unscanned), do a shutdown
        await whatsapp.shutdown()
        return

    # how to send a websocket message
    message = kyros.WebsocketMessage(None, ["query", "exist", "[email protected]"])
    await whatsapp.websocket.send_message(message)

    # receive a websocket message
    print(await whatsapp.websocket.messages.get(message.tag))


if __name__ == "__main__":
    asyncio.run(main())

A "much more detailed documentation" kind of thing for this project is available here. You will see a piece of nightmare, happy exploring! Better documentation are being planned.

Contribution

This work is still being slowly developed. Your contribution will of course make the development process of this project even faster. Any kind of contribution is highly appreciated.

License

This project is licensed with MIT License.

Disclaimer

This code is in no way affiliated with, authorized, maintained, sponsored or endorsed by WhatsApp or any of its affiliates or subsidiaries. This is an independent and unofficial software. Use at your own risk.

kyros's People

Contributors

dependabot[bot] avatar rijumone avatar ttycelery avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kyros's Issues

Client Websockets always disconnected

So i have already success implementing handle message and readbinary, but the client websockets always stop no connection
gambar
i've try adding ["admin","test"] or ?,, but still closed.

please contact me here

Maintainers needed

I have been quite busy and not being able to maintain this package very actively. Also, I don't think I will have that much of a time to maintain it actively in the near future.

I believe that this library could be maintained better if there is another maintainer who is willing to maintain this project on their spare time. If anyone is interested to become a maintainer of this project, please let me know, I would really appreciate that.

Cannot login with the new whatsapp multi device update

I am not clear on why this is not working, Let me explain what I understood.

  • With the new multi-device web login feature, WhatsApp now needs a series of 2QR codes to be scanned to log in.
  • After the first QR is scanned, it just waits

Another issue

  • Somehow once I scanned the QR code, the program exited saying that connection_data["phone"] was not found.
  • Because now in the new beta, after scanning we just get connection_data as a simple object with the WhatsApp web version and nothing more.

server rejected WebSocket connection

Traceback (most recent call last):
  File "C:\Users\USER\Desktop\wp test.py", line 40, in <module>
    asyncio.run(main())
  File "C:\Program Files\Python37\lib\asyncio\runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "C:\Program Files\Python37\lib\asyncio\base_events.py", line 587, in run_until_complete
    return future.result()
  File "C:\Users\USER\Desktop\wp test.py", line 14, in main
    whatsapp = await kyros.Client.create()
  File "C:\Users\USER\AppData\Roaming\Python\Python37\site-packages\kyros\client.py", line 32, in create
    await instance.setup_ws()
  File "C:\Users\USER\AppData\Roaming\Python\Python37\site-packages\kyros\client.py", line 54, in setup_ws
    await self.websocket.connect()
  File "C:\Users\USER\AppData\Roaming\Python\Python37\site-packages\kyros\websocket.py", line 145, in connect
    constants.WEBSOCKET_URI, origin=constants.WEBSOCKET_ORIGIN)
  File "C:\Users\USER\AppData\Roaming\Python\Python37\site-packages\websockets\legacy\client.py", line 650, in __await_impl_timeout__
    return await asyncio.wait_for(self.__await_impl__(), self.open_timeout)
  File "C:\Program Files\Python37\lib\asyncio\tasks.py", line 442, in wait_for
    return fut.result()
  File "C:\Users\USER\AppData\Roaming\Python\Python37\site-packages\websockets\legacy\client.py", line 664, in __await_impl__
    extra_headers=protocol.extra_headers,
  File "C:\Users\USER\AppData\Roaming\Python\Python37\site-packages\websockets\legacy\client.py", line 328, in handshake
    raise InvalidStatusCode(status_code, response_headers)
websockets.exceptions.InvalidStatusCode: server rejected WebSocket connection: HTTP 404

error: connection_data["phone"]

dear @p4kl0nc4t please help me

my code is:
` # create the Client instance using create class method
whatsapp = await kyros.Client.create()

# do a QR login
qr_data, scanned = await whatsapp.qr_login()

# generate qr code image
qr_code = pyqrcode.create(qr_data)
print(qr_code.png('code.png', scale=1, module_color=[0, 0, 0, 128], background=[0xff, 0xff, 0xff]))
# print(qr_code.terminal(quiet_zone=0))`

after scan qr code, occur this error:

Traceback (most recent call last): File "init.py", line 41, in <module> asyncio.run(main()) File "/usr/local/lib/python3.8/asyncio/runners.py", line 43, in run return loop.run_until_complete(main) File "/usr/local/lib/python3.8/asyncio/base_events.py", line 612, in run_until_complete return future.result() File "init.py", line 26, in main await scanned File "/tmp/w/lib/python3.8/site-packages/kyros/client.py", line 103, in wait_qr_scan self.phone_info = connection_data["phone"] KeyError: 'phone'

Profile

How i can load session from file and get the data from number? like the photo and the status message.

Error on executing the example

Hi,

Ubuntu 20.04
Python 3.8.2

Installation:

pip3 install git+https://[email protected]/p4kl0nc4t/kyros
pip3 install pyqrcode

ls on site-packages folder
image

I tried your example and I got the following error:

Traceback (most recent call last):
  File "wa.py", line 40, in <module>
    asyncio.run(main())
  File "/usr/lib/python3.8/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.8/asyncio/base_events.py", line 616, in run_until_complete
    return future.result()
  File "wa.py", line 14, in main
    whatsapp = await kyros.Client.create()
NameError: name 'kyros' is not defined

Running as:

python3 wa.py

The example code:

import asyncio
import logging

import pyqrcode

from kyros import Client, WebsocketMessage

logging.basicConfig()
# set a logging level: just to know if something (bad?) happens
logging.getLogger("kyros").setLevel(logging.WARNING)

async def main():
    # create the Client instance using create class method
    whatsapp = await kyros.Client.create()
    
    # do a QR login
    qr_data, scanned = await whatsapp.qr_login()
    
    # generate qr code image
    qr_code = pyqrcode.create(qr_data)
    print(qr_code.terminal(quiet_zone=1))

    try:
        # wait for the QR code to be scanned
        await scanned
    except asyncio.TimeoutError:
        # timed out (left unscanned), do a shutdown
        await whatsapp.shutdown()
        return
    
    # how to send a websocket message
    message = kyros.WebsocketMessage(None, ["query", "exist", "[email protected]"])
    await whatsapp.websocket.send_message(message)

    # receive a websocket message
    print(await whatsapp.websocket.messages.get(message.tag))


if __name__ == "__main__":
    asyncio.run(main())

QRCode

The whatsapp can't read the qr code.

Demo code does not work

Tried running demo code

import asyncio
import logging
import pyqrcode
import kyros

logging.basicConfig()
logging.getLogger("kyros").setLevel(logging.WARNING)


async def main():
    whatsapp = await kyros.Client.create()
    qr_data, scanned = await whatsapp.qr_login()
    qr_code = pyqrcode.create(qr_data)
    print(qr_code.terminal(quiet_zone=1))

    try:
        await scanned
    except asyncio.TimeoutError:
        await whatsapp.shutdown()
        return

    # how to send a websocket message
    message = kyros.WebsocketMessage(None, ["query", "exist", "[email protected]"])
    await whatsapp.websocket.send_message(message)

    # receive a websocket message
    print(await whatsapp.websocket.messages.get(message.tag))


if __name__ == "__main__":
    asyncio.run(main())

received error
ERROR:asyncio:Task exception was never retrieved future: <Task finished name='Task-4' coro=<WebsocketClient._start_receiver.<locals>.receiver() done, defined at C:\Users\Jerry\AppData\Local\Programs\Python\Python38\lib\site-packages\kyros\websocket.py:169> exception=AttributeError("'Queue' object has no attribute 'pop'")> Traceback (most recent call last): File "C:\Users\Jerry\AppData\Local\Programs\Python\Python38\lib\site-packages\kyros\websocket.py", line 179, in receiver raw_message = self.websocket.messages.pop() AttributeError: 'Queue' object has no attribute 'pop'

Resolved by changing websocket.py from pop() to get() and adding await

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.