wabc-py 0.1.0
A modern, easy to use, feature-rich ready API wrapper for WhatsApp Business Cloud written in Python
License: MIT license
Requires Python: >=3.6
Keywords: whatsapp

===========
wabc-py
===========

A modern, easy to use, feature-rich ready API wrapper for `WhatsApp Business Cloud`_ written in Python.


* Documentation: https://leandcesar.github.io/whatsapp/
* GitHub: https://github.com/leandcesar/whatsapp/
* PyPI: https://pypi.org/project/wabc-py/
* Free and open source software: MIT license


Features
--------

* Full `Send Messages`_ Support (text, audio, contacts, documents, images, interactive, location, sticker, and videos)
* Full `Webhook Notification`_ Parsing Support

Installing
----------

Stable release
~~~~~~~~~~~~~~

To install wabc-py, run this command in your terminal:

.. code-block:: console

    $ pip install whatsapp

This is the preferred method to install wabc-py, as it will always install the most recent stable release.

If you don't have `pip`_ installed, this `Python installation guide`_ can guide
you through the process.

From sources
~~~~~~~~~~~~

The sources for wabc-py can be downloaded from the `Github repo`_.

You can either clone the public repository:

.. code-block:: console

    $ git clone git://github.com/leandcesar/whatsapp

Or download the `tarball`_:

.. code-block:: console

    $ curl -OJL https://github.com/leandcesar/whatsapp/tarball/master

Once you have a copy of the source, you can install it with:

.. code-block:: console

    $ python setup.py install

Quick Example
-------------

Mirror Bot
~~~~~~~~~~

.. code:: py

    from whatsapp import Bot, Ctx

    class MirrorBot(Bot):
        def before_event_message(self, ctx: Ctx):
            ctx.read()

        def on_event_message_audio(self, ctx: Ctx):
            ctx.send(audio_id=ctx.message.audio.id)

        def on_event_message_document(self, ctx: Ctx):
            ctx.send(
                document_id=ctx.message.document.id,
                caption=ctx.message.document.caption,
            )

        def on_event_message_image(self, ctx: Ctx):
            ctx.send(
                image_id=ctx.message.image.id,
                caption=ctx.message.image.caption,
            )

        def on_event_message_sticker(self, ctx: Ctx):
            ctx.send(sticker_id=ctx.message.sticker.id)

        def on_event_message_text(self, ctx: Ctx):
            ctx.send(text=ctx.message.text.body)

        def on_event_message_video(self, ctx: Ctx):
            ctx.send(
                video_id=ctx.message.video.id,
                caption=ctx.message.video.caption,
            )

Run using Flask
~~~~~~~~~~~~~~~

.. code:: py

    from flask import Flask, request
    from whatsapp import Bot

    app = Flask(__name__)
    bot = Bot()
    bot.start(phone_id="PHONE_ID", token="ACCESS_TOKEN")

    @app.get("/")
    async def ping():
        if request.args.get("hub.verify_token") == "VERIFY_TOKEN":
            return request.args.get("hub.challenge")
        return "Invalid verify token"

    @app.post("/")
    def root():
        data = request.get_json()
        bot.handle(data)
        return "Success"

Run using Fast API
~~~~~~~~~~~~~~~~~~

.. code:: py

    from fastapi import FastAPI, Request
    from whatsapp import Bot

    app = FastAPI()
    bot = Bot()
    bot.start(phone_id="PHONE_ID", token="ACCESS_TOKEN")

    @app.get("/")
    async def ping(
        token: str = Query(alias="hub.verify_token"),
        challenge: str = Query(alias="hub.challenge"),
    ):
        if token == VERIFY_TOKEN:
            return challenge
        return "Invalid verify token"

    @app.post("/")
    async def root(request: Request):
        data = await request.json()
        bot.handle(data)
        return "Success"

Useful Links
------------

* `Get Started with the WhatsApp Business Cloud API`_

Credits
-------

This package was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ project template.


.. _`WhatsApp Business Cloud`: https://developers.facebook.com/docs/whatsapp/cloud-api
.. _`Send Messages`: https://developers.facebook.com/docs/whatsapp/cloud-api/reference/messages
.. _`Webhook Notification`: https://developers.facebook.com/docs/whatsapp/cloud-api/webhooks/components
.. _`pip`: https://pip.pypa.io
.. _`Python installation guide`: http://docs.python-guide.org/en/latest/starting/installation/
.. _`Github repo`: https://github.com/leandcesar/whatsapp
.. _`tarball`: https://github.com/leandcesar/whatsapp/tarball/master
.. _`Get Started with the WhatsApp Business Cloud API`: https://developers.facebook.com/docs/whatsapp/cloud-api/get-started
.. _`Cookiecutter`: https://github.com/audreyr/cookiecutter
.. _`audreyr/cookiecutter-pypackage`: https://github.com/audreyr/cookiecutter-pypackage


=======
History
=======

0.1.0 (2022-12-19)
------------------

* First release on PyPI.