Skip to content

Commit b4ef1ce

Browse files
authored
Merge pull request #24 from green-api/dev
v0.8.0
2 parents 63ed29e + 3e439f3 commit b4ef1ce

9 files changed

Lines changed: 274 additions & 48 deletions

File tree

.github/workflows/python-package.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
runs-on: ubuntu-latest
1515
strategy:
1616
matrix:
17-
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11" ]
17+
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11", "3.12" ]
1818

1919
steps:
2020
- uses: actions/checkout@v3
@@ -30,9 +30,9 @@ jobs:
3030
- name: Lint with ruff
3131
run: |
3232
# stop the build if there are Python syntax errors or undefined names
33-
ruff --format=github --select=E9,F63,F7,F82 --target-version=py37 .
33+
ruff --output-format=github --select=E9,F63,F7,F82 --target-version=py37 .
3434
# default set of ruff rules with GitHub Annotations
35-
ruff --format=github --target-version=py37 .
35+
ruff --output-format=github --target-version=py37 .
3636
- name: Test with pytest
3737
run: |
3838
pytest

README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,24 @@ bot = GreenAPIBot(
4646
)
4747
```
4848

49+
### How to enable debug mode
50+
51+
```
52+
bot = GreenAPIBot(
53+
"1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345",
54+
bot_debug_mode=True
55+
)
56+
```
57+
58+
You can also enable API debug mode:
59+
60+
```
61+
bot = GreenAPIBot(
62+
"1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345",
63+
debug_mode=True, bot_debug_mode=True
64+
)
65+
```
66+
4967
### How to set up an instance
5068

5169
To start receiving incoming notifications, you need to set up an instance. Open the personal cabinet page at
@@ -314,6 +332,50 @@ def password_handler(notification: Notification) -> None:
314332
bot.run_forever()
315333
```
316334

335+
### FAQ
336+
337+
- How to call API methods?
338+
339+
```
340+
bot.api.account.getSettings()
341+
```
342+
343+
Or
344+
345+
```
346+
notification.api.account.getSettings()
347+
```
348+
349+
- How do I disable error raising?
350+
351+
```
352+
bot = GreenAPIBot(
353+
"1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345",
354+
raise_errors=False
355+
)
356+
```
357+
358+
- How do I subscribe only to text messages?
359+
360+
You need to import the required constants first:
361+
362+
```
363+
from whatsapp_chatbot_python.filters import TEXT_TYPES
364+
```
365+
366+
Then add this filter: `type_message=TEXT_TYPES`.
367+
368+
- How do I get the message text and sender ID?
369+
370+
This data is in the notification object (`notification`):
371+
372+
```
373+
@bot.router.message()
374+
def message_handler(notification: Notification) -> None:
375+
print(notification.sender)
376+
print(notification.message_text)
377+
```
378+
317379
### Example of a bot
318380

319381
As an example, a bot was created to support the GREEN API. Command list:

docs/README.md

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,24 @@ bot = GreenAPIBot(
4545
)
4646
```
4747

48+
### Как включить режим отладки
49+
50+
```
51+
bot = GreenAPIBot(
52+
"1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345",
53+
bot_debug_mode=True
54+
)
55+
```
56+
57+
Также можно включить режим отладки API:
58+
59+
```
60+
bot = GreenAPIBot(
61+
"1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345",
62+
debug_mode=True, bot_debug_mode=True
63+
)
64+
```
65+
4866
### Как настроить инстанс
4967

5068
Чтобы начать получать входящие уведомления, нужно настроить инстанс. Открываем страницу личного кабинета
@@ -313,6 +331,50 @@ def password_handler(notification: Notification) -> None:
313331
bot.run_forever()
314332
```
315333

334+
### Часто задаваемые вопросы
335+
336+
- Как вызвать методы API?
337+
338+
```
339+
bot.api.account.getSettings()
340+
```
341+
342+
Или
343+
344+
```
345+
notification.api.account.getSettings()
346+
```
347+
348+
- Как отключить вызов ошибок?
349+
350+
```
351+
bot = GreenAPIBot(
352+
"1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345",
353+
raise_errors=False
354+
)
355+
```
356+
357+
- Как подписаться только на текстовые сообщения?
358+
359+
Нужно сначала импортировать нужные константы:
360+
361+
```
362+
from whatsapp_chatbot_python.filters import TEXT_TYPES
363+
```
364+
365+
Затем добавить этот фильтр: `type_message=TEXT_TYPES`.
366+
367+
- Как получить текст сообщения и ID отправителя?
368+
369+
Эти данные есть в объекте уведомления (`notification`):
370+
371+
```
372+
@bot.router.message()
373+
def message_handler(notification: Notification) -> None:
374+
print(notification.sender)
375+
print(notification.message_text)
376+
```
377+
316378
### Пример бота
317379

318380
В качестве примера был создан бот для поддержки GREEN API. Список команд:
@@ -327,7 +389,7 @@ bot.run_forever()
327389
Чтобы отправить место (локацию), нужно использовать метод `sending.sendLocation` из `notification.api`.
328390
Чтобы отправить сообщение с файлом, нужно использовать метод `notification.answer_with_file`.
329391

330-
В этом примере бот отвечает только на комманды из списка выше.
392+
В этом примере бот отвечает только на команды из списка выше.
331393

332394
Ссылка на пример: [full.py](../examples/full.py).
333395

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
whatsapp-api-client-python==0.0.41
1+
whatsapp-api-client-python==0.0.43

setup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@
2626
"Operating System :: OS Independent",
2727
"Programming Language :: Python",
2828
"Programming Language :: Python :: 3",
29+
"Programming Language :: Python :: 3 :: Only",
2930
"Programming Language :: Python :: 3.7",
3031
"Programming Language :: Python :: 3.8",
3132
"Programming Language :: Python :: 3.9",
3233
"Programming Language :: Python :: 3.10",
3334
"Programming Language :: Python :: 3.11",
34-
"Programming Language :: Python :: 3 :: Only",
35+
"Programming Language :: Python :: 3.12",
3536
"Topic :: Communications",
3637
"Topic :: Communications :: Chat",
3738
"Topic :: Software Development",
@@ -42,6 +43,6 @@
4243
"Creative Commons Attribution-NoDerivatives 4.0 International"
4344
" (CC BY-ND 4.0)"
4445
),
45-
install_requires=["whatsapp-api-client-python==0.0.41"],
46+
install_requires=["whatsapp-api-client-python==0.0.43"],
4647
python_requires=">=3.7"
4748
)

0 commit comments

Comments
 (0)