Skip to content

Commit

Permalink
updated hook.py and setup.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalebu committed May 20, 2022
1 parent 13d7a6f commit 2b0a19e
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 52 deletions.
49 changes: 5 additions & 44 deletions heyoo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
22 changes: 14 additions & 8 deletions hook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
40 changes: 40 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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",
],
)

0 comments on commit 2b0a19e

Please sign in to comment.