Skip to content

Commit

Permalink
Merge pull request #24 from green-api/dev
Browse files Browse the repository at this point in the history
v0.8.0
  • Loading branch information
Amele9 authored Nov 28, 2023
2 parents 63ed29e + 3e439f3 commit b4ef1ce
Show file tree
Hide file tree
Showing 9 changed files with 274 additions and 48 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11" ]
python-version: [ "3.7", "3.8", "3.9", "3.10", "3.11", "3.12" ]

steps:
- uses: actions/checkout@v3
Expand All @@ -30,9 +30,9 @@ jobs:
- name: Lint with ruff
run: |
# stop the build if there are Python syntax errors or undefined names
ruff --format=github --select=E9,F63,F7,F82 --target-version=py37 .
ruff --output-format=github --select=E9,F63,F7,F82 --target-version=py37 .
# default set of ruff rules with GitHub Annotations
ruff --format=github --target-version=py37 .
ruff --output-format=github --target-version=py37 .
- name: Test with pytest
run: |
pytest
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ bot = GreenAPIBot(
)
```

### How to enable debug mode

```
bot = GreenAPIBot(
"1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345",
bot_debug_mode=True
)
```

You can also enable API debug mode:

```
bot = GreenAPIBot(
"1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345",
debug_mode=True, bot_debug_mode=True
)
```

### How to set up an instance

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

### FAQ

- How to call API methods?

```
bot.api.account.getSettings()
```

Or

```
notification.api.account.getSettings()
```

- How do I disable error raising?

```
bot = GreenAPIBot(
"1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345",
raise_errors=False
)
```

- How do I subscribe only to text messages?

You need to import the required constants first:

```
from whatsapp_chatbot_python.filters import TEXT_TYPES
```

Then add this filter: `type_message=TEXT_TYPES`.

- How do I get the message text and sender ID?

This data is in the notification object (`notification`):

```
@bot.router.message()
def message_handler(notification: Notification) -> None:
print(notification.sender)
print(notification.message_text)
```

### Example of a bot

As an example, a bot was created to support the GREEN API. Command list:
Expand Down
64 changes: 63 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,24 @@ bot = GreenAPIBot(
)
```

### Как включить режим отладки

```
bot = GreenAPIBot(
"1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345",
bot_debug_mode=True
)
```

Также можно включить режим отладки API:

```
bot = GreenAPIBot(
"1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345",
debug_mode=True, bot_debug_mode=True
)
```

### Как настроить инстанс

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

### Часто задаваемые вопросы

- Как вызвать методы API?

```
bot.api.account.getSettings()
```

Или

```
notification.api.account.getSettings()
```

- Как отключить вызов ошибок?

```
bot = GreenAPIBot(
"1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345",
raise_errors=False
)
```

- Как подписаться только на текстовые сообщения?

Нужно сначала импортировать нужные константы:

```
from whatsapp_chatbot_python.filters import TEXT_TYPES
```

Затем добавить этот фильтр: `type_message=TEXT_TYPES`.

- Как получить текст сообщения и ID отправителя?

Эти данные есть в объекте уведомления (`notification`):

```
@bot.router.message()
def message_handler(notification: Notification) -> None:
print(notification.sender)
print(notification.message_text)
```

### Пример бота

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

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

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

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
whatsapp-api-client-python==0.0.41
whatsapp-api-client-python==0.0.43
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.12",
"Topic :: Communications",
"Topic :: Communications :: Chat",
"Topic :: Software Development",
Expand All @@ -42,6 +43,6 @@
"Creative Commons Attribution-NoDerivatives 4.0 International"
" (CC BY-ND 4.0)"
),
install_requires=["whatsapp-api-client-python==0.0.41"],
install_requires=["whatsapp-api-client-python==0.0.43"],
python_requires=">=3.7"
)
Loading

0 comments on commit b4ef1ce

Please sign in to comment.