Skip to content

Commit b5ac6f4

Browse files
authored
Merge pull request #8 from Amele9/master
New tests and some refactoring
2 parents 2d7c255 + 0681760 commit b5ac6f4

17 files changed

Lines changed: 233 additions & 122 deletions

.github/workflows/python-app.yml

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,45 @@
1-
# This workflow will install Python dependencies, run tests and lint with a single version of Python
2-
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
3-
41
name: Python application
52

63
on:
7-
push:
8-
branches: [ "master" ]
9-
pull_request:
10-
branches: [ "master" ]
4+
- pull_request
5+
- push
116

127
permissions:
138
contents: read
149

1510
jobs:
1611
build:
12+
name: ${{ matrix.python-version }}
1713

18-
runs-on: ubuntu-latest
1914
env:
2015
ID_INSTANCE: ${{ secrets.ID_INSTANCE }}
2116
API_TOKEN_INSTANCE: ${{ secrets.API_TOKEN_INSTANCE }}
17+
18+
runs-on: ${{ matrix.os }}
19+
strategy:
20+
matrix:
21+
os:
22+
- ubuntu-latest
23+
python-version:
24+
- "3.7"
25+
- "3.8"
26+
- "3.9"
27+
- "3.10"
28+
2229
steps:
23-
- uses: actions/checkout@v3
24-
- name: Set up Python 3.10
25-
uses: actions/setup-python@v3
26-
with:
27-
python-version: "3.10"
28-
- name: Install dependencies
29-
run: |
30-
python -m pip install --upgrade pip
31-
pip install flake8 pytest
32-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
33-
- name: Lint with flake8
34-
run: |
35-
# stop the build if there are Python syntax errors or undefined names
36-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
37-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
38-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
39-
- name: Test with pytest
40-
run: |
41-
pytest
30+
- uses: actions/checkout@v3
31+
- name: Set up Python ${{ matrix.python-version }}
32+
uses: actions/setup-python@v4
33+
with:
34+
python-version: ${{ matrix.python-version }}
35+
- name: Install dependencies
36+
run: |
37+
python -m pip install --upgrade pip
38+
pip install flake8 pytest
39+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
40+
- name: Lint with flake8
41+
run: |
42+
python${{ matrix.python-version }} -m flake8 --extend-ignore E999 .
43+
- name: Test with pytest
44+
run: |
45+
pytest

examples/bot_example.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from os import environ
2+
3+
from whatsapp_api_client_python import GreenAPI, Bot
4+
5+
ID_INSTANCE = environ["ID_INSTANCE"]
6+
API_TOKEN_INSTANCE = environ["API_TOKEN_INSTANCE"]
7+
8+
greenAPI = GreenAPI(ID_INSTANCE, API_TOKEN_INSTANCE)
9+
10+
bot = Bot(greenAPI)
11+
12+
13+
@bot.handler(type_webhook="incomingMessageReceived")
14+
def handler(body: dict) -> None:
15+
greenAPI.read_mark.read_chat(
16+
chatId=body["senderData"]["chatId"],
17+
idMessage=body["idMessage"]
18+
)
19+
20+
21+
@bot.message(message_text="Hello")
22+
def message_handler(body: dict) -> str:
23+
sender_name = body["senderData"]["senderName"]
24+
25+
return f"Hello, {sender_name}."
26+
27+
28+
bot.run_forever()

examples/create_group_and_send_message.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@ def main():
1515
chatIds=["79001234567@c.us"]
1616
)
1717

18-
print(create_group_response.data)
18+
print(create_group_response)
1919

20-
chatId = create_group_response.data["chatId"]
2120
send_message_response = greenAPI.sending.send_message(
22-
chatId=chatId,
21+
chatId=create_group_response["chatId"],
2322
message="Any message"
2423
)
2524

26-
print(send_message_response.data)
25+
print(send_message_response)
2726

2827

2928
if __name__ == "__main__":

examples/send_file_by_upload.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
def main():
1313
response = greenAPI.sending.send_file_by_upload(
1414
chatId="79001234567@c.us",
15-
path="C:\\Games\\PicFromDisk.png"
15+
file="C:\\Games\\PicFromDisk.png"
1616
)
1717

18-
print(response.data)
18+
print(response)
1919

2020

2121
if __name__ == "__main__":

examples/send_file_by_url.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,14 @@
1212
def main():
1313
response = greenAPI.sending.send_file_by_url(
1414
chatId="79001234567@c.us",
15-
urlFile="https://www.google.com/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png",
15+
urlFile=(
16+
"https://www.google.com/images/branding/"
17+
"googlelogo/2x/googlelogo_color_272x92dp.png"
18+
),
1619
fileName="googlelogo_color_272x92dp.png"
1720
)
1821

19-
print(response.data)
22+
print(response)
2023

2124

2225
if __name__ == "__main__":

examples/send_message.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
from os import environ
2-
31
from whatsapp_api_client_python import GreenAPI
42

5-
ID_INSTANCE = '1101000001'
6-
API_TOKEN_INSTANCE = '3e03ea9ff3324e228ae3dfdf4d48e409bfa1b1ad0b0c46bf8c'
3+
ID_INSTANCE = "1101000001"
4+
API_TOKEN_INSTANCE = "3e03ea9ff3324e228ae3dfdf4d48e409bfa1b1ad0b0c46bf8c"
75

86
greenAPI = GreenAPI(ID_INSTANCE, API_TOKEN_INSTANCE)
97

@@ -14,7 +12,7 @@ def main():
1412
message="Any message"
1513
)
1614

17-
print(response.data)
15+
print(response)
1816

1917

2018
if __name__ == "__main__":

examples/webhook_example.py

Lines changed: 0 additions & 28 deletions
This file was deleted.

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
requests
1+
requests==2.28.1

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="whatsapp_api_client_python",
8-
version="0.0.29",
8+
version="0.0.30",
99
install_requires=["requests"],
1010
author="Ivan Sadovy",
1111
author_email="sadiv@bk.ru",
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010

1111

1212
class GreenAPITestCase(unittest.TestCase):
13-
def test_getSettings(self):
14-
response = greenAPI.account.get_settings()
13+
def test_GetStateInstance(self):
14+
response = greenAPI.account.get_state_instance()
1515

16-
self.assertEqual(response.status_code, 200, response.error)
16+
self.assertTrue(response)
1717

18-
def test_getStateInstance(self):
19-
response = greenAPI.account.get_state_instance()
18+
def test_CheckWhatsapp(self):
19+
response = greenAPI.service_methods.check_whatsapp(79001234567)
2020

21-
self.assertEqual(response.status_code, 200, response.error)
21+
self.assertTrue(response)
2222

2323

2424
if __name__ == '__main__':

0 commit comments

Comments
 (0)