diff --git a/heyoo/__init__.py b/heyoo/__init__.py index 697d77c..743d289 100644 --- a/heyoo/__init__.py +++ b/heyoo/__init__.py @@ -2,52 +2,8 @@ Unofficial python wrapper for the WhatsApp Cloud API. """ -import json import requests -# curl -X POST \ -# 'https://graph.facebook.com/v13.0/FROM_PHONE_NUMBER_ID/messages' \ -# -H 'Authorization: Bearer ACCESS_TOKEN' \ -# -d '{ -# "messaging_product": "whatsapp", -# "recipient_type": "individual", -# "to": "PHONE_NUMBER", -# "type": "interactive", -# "interactive": { -# "type": "list", -# "header": { -# "type": "text", -# "text": "HEADER_TEXT" -# }, -# "body": { -# "text": "BODY_TEXT" -# }, -# "footer": { -# "text": "FOOTER_TEXT" -# }, -# "action": { -# "button": "BUTTON_TEXT", -# "sections": [ -# { -# "title": "SECTION_2_TITLE", -# "rows": [ -# { -# "id": "SECTION_2_ROW_1_ID", -# "title": "SECTION_2_ROW_1_TITLE", -# "description": "SECTION_2_ROW_1_DESCRIPTION" -# }, -# { -# "id": "SECTION_2_ROW_2_ID", -# "title": "SECTION_2_ROW_2_TITLE", -# "description": "SECTION_2_ROW_2_DESCRIPTION" -# } -# ] -# } -# ] -# } -# } -# }' - class WhatsApp(object): def __init__(self, token=None): @@ -224,6 +180,11 @@ def get_message_timestamp(self, data): if "messages" in data: return data["messages"][0]["timestamp"] + def get_interactive_response(self, data): + data = self.preprocess(data) + if "messages" in data: + return data["messages"][0]["interactive"]["list_reply"] + def get_message_type(self, data): data = self.preprocess(data) if "messages" in data: diff --git a/hook.py b/hook.py index 2714856..57a3f3b 100644 --- a/hook.py +++ b/hook.py @@ -27,14 +27,20 @@ def hook(): new_message = messenger.get_mobile(data) if new_message: mobile = messenger.get_mobile(data) - message = messenger.get_message(data) - name = messenger.get_name(data) - print(f"{name} with this {mobile} number sent {message}") - # messenger.send_message(f"Hi {name}, nice to connect with you", mobile) - response = messenger.send_image( - image_url="https://i.imgur.com/Fh7XVYY.jpeg", recipient_id=mobile - ) - print(response) + message_type = messenger.get_message_type(data) + + if message_type == "text": + message = messenger.get_message(data) + name = messenger.get_name(data) + print(f"{name} with this {mobile} number sent {message}") + messenger.send_message(f"Hi {name}, nice to connect with you", mobile) + + elif message_type == "interactive": + message_response = messenger.get_interactive_response(data) + print(message_response) + + else: + pass else: delivery = messenger.get_delivery(data) if delivery: diff --git a/setup.py b/setup.py index e69de29..c8cc15f 100644 --- a/setup.py +++ b/setup.py @@ -0,0 +1,40 @@ +from os import path +from setuptools import setup + +# read the contents of your description file + +this_directory = path.abspath(path.dirname(__file__)) +with open(path.join(this_directory, "description.md"), encoding="utf-8") as f: + long_description = f.read() + +setup( + name="heyoo", + version="0.0.1", + description="Opensource python wrapper to WhatsApp Cloud API", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://github.com/Neurotech-HQ/heyoo", + download_url="", + author="Jordan Kalebu", + author_email="isaackeinstein@gmail.com", + license="MIT", + packages=["heyoo"], + keywords=[ + "heyoo", + "heyoo-libary", + "WhatsApp Cloud API Wrapper", + "PyWhatsApp", + "WhatsApp API in Python", + ], + python_requires=">=3.6", + classifiers=[ + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Topic :: Software Development :: Build Tools", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + ], +) \ No newline at end of file