Skip to content

Commit efb030b

Browse files
authored
Merge pull request #7 from green-api/dev
v0.0.8
2 parents 57776f6 + 45c8689 commit efb030b

File tree

12 files changed

+156
-210
lines changed

12 files changed

+156
-210
lines changed

.github/workflows/python-app.yml

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: Python package
2+
3+
on:
4+
push:
5+
branches:
6+
- "master"
7+
pull_request:
8+
branches:
9+
- "master"
10+
11+
jobs:
12+
build:
13+
name: ${{ matrix.python-version }}
14+
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
18+
19+
steps:
20+
- uses: actions/checkout@v3
21+
- name: Set up Python ${{ matrix.python-version }}
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: ${{ matrix.python-version }}
25+
- name: Install dependencies
26+
run: |
27+
python -m pip install --upgrade pip
28+
pip install ruff pytest
29+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
30+
- name: Lint with ruff
31+
run: |
32+
# stop the build if there are Python syntax errors or undefined names
33+
ruff --output-format=github --select=E9,F63,F7,F82 --target-version=py38 .
34+
# default set of ruff rules with GitHub Annotations
35+
ruff --output-format=github --target-version=py38 .
36+
- name: Test with pytest
37+
run: |
38+
pytest

.github/workflows/python-publish.yml

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

.gitignore

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ parts/
2020
sdist/
2121
var/
2222
wheels/
23-
pip-wheel-metadata/
2423
share/python-wheels/
2524
*.egg-info/
2625
.installed.cfg
@@ -50,6 +49,7 @@ coverage.xml
5049
*.py,cover
5150
.hypothesis/
5251
.pytest_cache/
52+
cover/
5353

5454
# Translations
5555
*.mo
@@ -72,6 +72,7 @@ instance/
7272
docs/_build/
7373

7474
# PyBuilder
75+
.pybuilder/
7576
target/
7677

7778
# Jupyter Notebook
@@ -82,7 +83,9 @@ profile_default/
8283
ipython_config.py
8384

8485
# pyenv
85-
.python-version
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
8689

8790
# pipenv
8891
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
@@ -91,7 +94,22 @@ ipython_config.py
9194
# install all needed dependencies.
9295
#Pipfile.lock
9396

94-
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
97+
# poetry
98+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102+
#poetry.lock
103+
104+
# pdm
105+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106+
#pdm.lock
107+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108+
# in version control.
109+
# https://pdm.fming.dev/#use-with-ide
110+
.pdm.toml
111+
112+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
95113
__pypackages__/
96114

97115
# Celery stuff
@@ -127,3 +145,16 @@ dmypy.json
127145

128146
# Pyre type checker
129147
.pyre/
148+
149+
# pytype static type analyzer
150+
.pytype/
151+
152+
# Cython debug symbols
153+
cython_debug/
154+
155+
# PyCharm
156+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
157+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
158+
# and can be added to the global gitignore or merged into this file. For a more nuclear
159+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160+
#.idea/

.vscode/launch.json

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

.vscode/tasks.json

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

examples/echo.py

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
from datetime import datetime
21
import json
2+
from datetime import datetime
33

44
import whatsapp_api_webhook_server_python.webhooksHandler as handler
55

66

77
def onEvent(webhookHandler: handler.WebhooksHandler, typeWebhook: str, body):
88
if typeWebhook == 'incomingMessageReceived':
9-
onIncomingMessageReceived(webhookHandler, body)
10-
elif typeWebhook == 'deviceInfo':
11-
onDeviceInfo(webhookHandler, body)
9+
onIncomingMessageReceived(webhookHandler, body)
10+
elif typeWebhook == 'deviceInfo':
11+
onDeviceInfo(webhookHandler, body)
1212
elif typeWebhook == 'incomingCall':
1313
onIncomingCall(webhookHandler, body)
1414
elif typeWebhook == 'incomingMessageReceived':
@@ -24,60 +24,68 @@ def onEvent(webhookHandler: handler.WebhooksHandler, typeWebhook: str, body):
2424
elif typeWebhook == 'statusInstanceChanged':
2525
onStatusInstanceChanged(webhookHandler, body)
2626

27-
def onIncomingMessageReceived(webhookHandler: handler.WebhooksHandler, body: object):
27+
28+
def onIncomingMessageReceived(webhookHandler: handler.WebhooksHandler,
29+
body: object):
2830
idMessage = body['idMessage']
2931
eventDate = datetime.fromtimestamp(body['timestamp'])
3032
senderData = body['senderData']
3133
messageData = body['messageData']
3234
TextOut = idMessage + ': ' \
33-
+ 'At ' + str(eventDate) + ' Incoming from ' \
34-
+ json.dumps(senderData, ensure_ascii=False) \
35-
+ ' message = ' + json.dumps(messageData, ensure_ascii=False)
35+
+ 'At ' + str(eventDate) + ' Incoming from ' \
36+
+ json.dumps(senderData, ensure_ascii=False) \
37+
+ ' message = ' + json.dumps(messageData, ensure_ascii=False)
3638
webhookHandler.set_status(200)
3739
print(TextOut)
3840

41+
3942
def onIncomingCall(webhookHandler: handler.WebhooksHandler, body):
4043
idMessage = body['idMessage']
4144
eventDate = datetime.fromtimestamp(body['timestamp'])
4245
fromWho = body['from']
4346
TextOut = idMessage + ': ' \
44-
+ 'Call from ' + fromWho \
45-
+ ' at ' + str(eventDate)
47+
+ 'Call from ' + fromWho \
48+
+ ' at ' + str(eventDate)
4649
webhookHandler.set_status(200)
4750
print(TextOut)
4851

52+
4953
def onDeviceInfo(webhookHandler: handler.WebhooksHandler, body):
5054
eventDate = datetime.fromtimestamp(body['timestamp'])
5155
deviceData = body['deviceData']
5256
TextOut = 'At ' + str(eventDate) + ': ' \
53-
+ json.dumps(deviceData, ensure_ascii=False)
57+
+ json.dumps(deviceData, ensure_ascii=False)
5458
webhookHandler.set_status(200)
5559
print(TextOut)
5660

61+
5762
def onOutgoingMessageReceived(webhookHandler: handler.WebhooksHandler, body):
5863
idMessage = body['idMessage']
5964
eventDate = datetime.fromtimestamp(body['timestamp'])
6065
senderData = body['senderData']
6166
messageData = body['messageData']
6267
TextOut = idMessage + ': ' \
63-
+ 'At ' + str(eventDate) + ' Outgoing from ' \
64-
+ json.dumps(senderData, ensure_ascii=False) \
65-
+ ' message = ' + json.dumps(messageData, ensure_ascii=False)
68+
+ 'At ' + str(eventDate) + ' Outgoing from ' \
69+
+ json.dumps(senderData, ensure_ascii=False) \
70+
+ ' message = ' + json.dumps(messageData, ensure_ascii=False)
6671
webhookHandler.set_status(200)
6772
print(TextOut)
6873

69-
def onOutgoingAPIMessageReceived(webhookHandler: handler.WebhooksHandler, body):
74+
75+
def onOutgoingAPIMessageReceived(webhookHandler: handler.WebhooksHandler,
76+
body):
7077
idMessage = body['idMessage']
7178
eventDate = datetime.fromtimestamp(body['timestamp'])
7279
senderData = body['senderData']
7380
messageData = body['messageData']
7481
TextOut = idMessage + ': ' \
75-
+ 'At ' + str(eventDate) + ' API outgoing from ' \
76-
+ json.dumps(senderData, ensure_ascii=False) + \
77-
' message = ' + json.dumps(messageData, ensure_ascii=False)
82+
+ 'At ' + str(eventDate) + ' API outgoing from ' \
83+
+ json.dumps(senderData, ensure_ascii=False) + \
84+
' message = ' + json.dumps(messageData, ensure_ascii=False)
7885
webhookHandler.set_status(200)
7986
print(TextOut)
8087

88+
8189
def onOutgoingMessageStatus(webhookHandler: handler.WebhooksHandler, body):
8290
idMessage = body['idMessage']
8391
status = body['status']
@@ -86,24 +94,28 @@ def onOutgoingMessageStatus(webhookHandler: handler.WebhooksHandler, body):
8694
webhookHandler.set_status(200)
8795
print(TextOut)
8896

97+
8998
def onStateInstanceChanged(webhookHandler: handler.WebhooksHandler, body):
9099
eventDate = datetime.fromtimestamp(body['timestamp'])
91100
stateInstance = body['stateInstance']
92101
TextOut = 'At ' + str(eventDate) + ' state instance = ' \
93-
+ json.dumps(stateInstance, ensure_ascii=False)
102+
+ json.dumps(stateInstance, ensure_ascii=False)
94103
webhookHandler.set_status(200)
95104
print(TextOut)
96105

106+
97107
def onStatusInstanceChanged(webhookHandler: handler.WebhooksHandler, body):
98108
eventDate = datetime.fromtimestamp(body['timestamp'])
99109
statusInstance = body['statusInstance']
100110
TextOut = 'At ' + str(eventDate) + ' status instance = ' \
101-
+ json.dumps(statusInstance, ensure_ascii=False)
111+
+ json.dumps(statusInstance, ensure_ascii=False)
102112
webhookHandler.set_status(200)
103113
print(TextOut)
104114

115+
105116
def main():
106117
handler.startServer(None, 80, onEvent)
107118

119+
108120
if __name__ == "__main__":
109-
main()
121+
main()

0 commit comments

Comments
 (0)