Skip to content

Commit

Permalink
Version updated
Browse files Browse the repository at this point in the history
Tests updated
docs/README.md updated
Minor typo fixes
  • Loading branch information
karmaplush committed Jun 3, 2024
1 parent 749f8c3 commit 556b3f6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
33 changes: 33 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,39 @@ def call_support_operator_handler(notification: Notification) -> None:
bot.run_forever()
```

### Получение уведомлений при помощи webhook

По умолчанию бот читает уведомления, используя long polling метод. Получение уведомлений также возможно с помощью webhook-сервера:

```python
from whatsapp_chatbot_python import GreenAPIBot, Notification

bot = GreenAPIBot(
"1101000001",
"d75b3a66374942c5b3c019c698abc2067e151558acbd412345",
# Укажите значение `webhook_mode` равное True (False по-умолчанию)
webhook_mode = True,
# Укажите хост вебхук-сервера ("0.0.0.0" по-умолчанию)
webhook_host = "0.0.0.0",
# Укажите порт вебхук-сервера (8080 по-умолчанию)
webhook_port = 8080,
# При необходимости, укажите заголовок авторизации (:str), который
# установлен в консоли инстанса. Если указать None, то
# заголовок авторизации не будет проверяться вебхук-сервером
webhook_auth_header = None,
)


@bot.router.outgoing_message()
def outgoint_message_handler(notification: Notification) -> None:
print("Outgoint message received")

if __name__ == "__main__":
bot.run_forever()

```
Для того, чтобы этот режим работал корректно, укажите корректный URL вебхук-севрера в настройках инстанса. В качестве вебхук-сервера используется [whatsapp-api-webhook-server-python-v2](https://github.com/green-api/whatsapp-api-webhook-server-python-v2) (`python >= 3.8`)

## Документация по методам сервиса

[Документация по методам сервиса](https://green-api.com/docs/api/)
Expand Down
15 changes: 8 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
name="whatsapp-chatbot-python",
version="0.9.1",
description=(
"This library helps you easily create"
" a Python chatbot with WhatsApp API."
"This library helps you easily create a Python chatbot with WhatsApp API."
),
long_description=long_description,
long_description_content_type="text/markdown",
Expand Down Expand Up @@ -37,12 +36,14 @@
"Topic :: Communications :: Chat",
"Topic :: Software Development",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Libraries :: Application Frameworks"
"Topic :: Software Development :: Libraries :: Application Frameworks",
],
license=(
"Creative Commons Attribution-NoDerivatives 4.0 International"
" (CC BY-ND 4.0)"
"Creative Commons Attribution-NoDerivatives 4.0 International" " (CC BY-ND 4.0)"
),
install_requires=["whatsapp-api-client-python==0.0.45"],
python_requires=">=3.7"
install_requires=[
"whatsapp-api-client-python==0.0.45",
"whatsapp-api-webhook-server-python-v2==0.1.0",
],
python_requires=">=3.7",
)
14 changes: 7 additions & 7 deletions tests/test_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
"messageData": {
"typeMessage": "textMessage",
"textMessageData": {
"textMessage": "Hello"
}
}
"textMessage": "Hello",
},
},
}


Expand Down Expand Up @@ -44,12 +44,12 @@ def handler(_):

self.assertEqual(len(bot.router.message.handlers), 2)

@patch("whatsapp_chatbot_python.bot.Bot._update_settings")
def create_bot(self, mock__update_settings: MagicMock) -> GreenAPIBot:
mock__update_settings.return_value = None
@patch("whatsapp_chatbot_python.bot.Bot._Bot__init_instance_settings")
def create_bot(self, mock__init_instance_settings: MagicMock) -> GreenAPIBot:
mock__init_instance_settings.return_value = None

return GreenAPIBot("", "", delete_notifications_at_startup=False)


if __name__ == '__main__':
if __name__ == "__main__":
unittest.main()
5 changes: 4 additions & 1 deletion whatsapp_chatbot_python/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ def __init__(
- `bot_debug_mode: bool` - (default: `False`)
Debug mode (extended logging) for bot
- `settings: dict | None` - (default: `None`)
dict for updating instance settings if provided
- `delete_notifications_at_startup: bool` - (default: `True`) Remove all
notifications from notification queue on bot startup. If `bot_debug_mode`
is `True` - this arg will be setted as `True` when bot object init
Expand All @@ -57,7 +60,7 @@ def __init__(
- `webhook_host: str` - (default: `"0.0.0.0"`) Host for webhook server.
- `webhook_post: int` - (default: `8080`) Port for webhook server.
- `webhook_port: int` - (default: `8080`) Port for webhook server.
- `webhook_auth_header: str | None` - (default: `None`) Check that the
authorization header matches the specified value.
Expand Down

0 comments on commit 556b3f6

Please sign in to comment.