diff --git a/.gitignore b/.gitignore index b6e4761..2dc53ca 100644 --- a/.gitignore +++ b/.gitignore @@ -20,7 +20,6 @@ parts/ sdist/ var/ wheels/ -pip-wheel-metadata/ share/python-wheels/ *.egg-info/ .installed.cfg @@ -50,6 +49,7 @@ coverage.xml *.py,cover .hypothesis/ .pytest_cache/ +cover/ # Translations *.mo @@ -72,6 +72,7 @@ instance/ docs/_build/ # PyBuilder +.pybuilder/ target/ # Jupyter Notebook @@ -82,7 +83,9 @@ profile_default/ ipython_config.py # pyenv -.python-version +# For a library or package, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# .python-version # pipenv # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. @@ -91,7 +94,22 @@ ipython_config.py # install all needed dependencies. #Pipfile.lock -# PEP 582; used by e.g. github.com/David-OConnor/pyflow +# poetry +# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. +# This is especially recommended for binary packages to ensure reproducibility, and is more +# commonly ignored for libraries. +# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control +#poetry.lock + +# pdm +# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. +#pdm.lock +# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it +# in version control. +# https://pdm.fming.dev/#use-with-ide +.pdm.toml + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm __pypackages__/ # Celery stuff @@ -127,3 +145,16 @@ dmypy.json # Pyre type checker .pyre/ + +# pytype static type analyzer +.pytype/ + +# Cython debug symbols +cython_debug/ + +# PyCharm +# JetBrains specific template is maintained in a separate JetBrains.gitignore that can +# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore +# and can be added to the global gitignore or merged into this file. For a more nuclear +# option (not recommended) you can uncomment the following to ignore the entire idea folder. +.idea/ diff --git a/LICENSE b/LICENSE index ba6c28c..bbf5362 100644 --- a/LICENSE +++ b/LICENSE @@ -311,4 +311,4 @@ other arrangements, understandings, or agreements concerning use of licensed material. For the avoidance of doubt, this paragraph does not form part of the public licenses. -Creative Commons may be contacted at creativecommons.org. \ No newline at end of file +Creative Commons may be contacted at creativecommons.org. diff --git a/README.md b/README.md index bf0bd9b..ecfe11a 100644 --- a/README.md +++ b/README.md @@ -6,121 +6,146 @@ ![](https://img.shields.io/github/actions/workflow/status/green-api/whatsapp-api-client-python/python-package.yml) ![](https://img.shields.io/pypi/dm/whatsapp-api-client-python) -- [Документация на русском языке](README_RUS.md) +- [Документация на русском языке](https://github.com/green-api/whatsapp-api-client-python/blob/master/README_RUS.md). -Python library for intagration with WhatsAPP messanger via API of [green-api.com](https://green-api.com/en/) service. To use the library you have to get a registration token and an account id in the [personal area](https://console.green-api.com). There is a free developer account tariff plan. +whatsapp-api-client-python is a library for integration with WhatsApp messenger using the API +service [green-api.com](https://green-api.com/en/). You should get a registration token and an account ID in +your [personal cabinet](https://console.green-api.com/) to use the library. There is a free developer account tariff. ## API -You can find REST API documentation by [url](https://green-api.com/en/docs/api/). The library is a wrapper for REST API, so the documentation at the above url applies to the library as well. +The documentation for the REST API can be found at the [link](https://green-api.com/en/docs/). The library is a wrapper +for the REST API, so the documentation at the link above also applies. + +## Authorization + +To send a message or perform other GREEN API methods, the WhatsApp account in the phone app must be authorized. To +authorize the account, go to your [cabinet](https://console.green-api.com/) and scan the QR code using the WhatsApp app. ## Installation ```shell -pip install whatsapp-api-client-python +python -m pip install whatsapp-api-client-python ``` -## Import +## Import ``` from whatsapp_api_client_python import API ``` -## Authorization - -To send a message or to exacute some other Green-API method, you have to have the WhatsApp account in the phone application to be authorized. To authorize your account please go to the [personal area](https://console.green-api.com) and scan a QR-code using the WhatsApp application. ## Examples ### How to initialize an object -```python -greenAPI = API.GreenApi(ID_INSTANCE, API_TOKEN_INSTANCE) +``` +greenAPI = API.GreenApi( + "1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345" +) ``` ### Sending a text message to a WhatsApp number -```python -result = greenAPI.sending.sendMessage('79001234567@g.us', 'Message text') -``` +Link to example: [sendTextMessage.py]( +https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendTextMessage.py +). -Example url: [sendTextMessage.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendTextMessage.py) - -Please note that keys can be obtained from environment variables: -```python -from os import environ +``` +response = greenAPI.sending.sendMessage("11001234567@c.us", "Message text") -ID_INSTANCE = environ['ID_INSTANCE'] -API_TOKEN_INSTANCE = environ['API_TOKEN_INSTANCE'] +print(response.data) ``` ### Sending an image via URL -```python -result = greenAPI.sending.sendFileByUrl('120363025955348359@g.us', - 'https://www.google.ru/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png', - 'googlelogo_color_272x92dp.png', 'Google logo') -``` +Link to example: [sendPictureByLink.py]( +https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendPictureByLink.py +). -Example url: [sendPictureByLink.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendPictureByLink.py) +``` +response = greenAPI.sending.sendFileByUrl( + "11001234567@c.us", + "https://green-api.com/green-api-logo_2.png", + "green-api-logo_2.png", + "GREEN API logo" +) + +print(response.data) +``` ### Sending an image by uploading from the disk -```python -result = greenAPI.sending.sendFileByUpload('120363025955348359@g.us', - 'C:\Games\PicFromDisk.png', - 'PicFromDisk.png', 'Picture from disk') -``` +Link to example: [sendPictureByUpload.py]( +https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendPictureByUpload.py +). -Example url: [sendPictureByUpload.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendPictureByUpload.py) +``` +response = greenAPI.sending.sendFileByUpload( + "11001234567@c.us", + "data/green-api-logo_2.png", + "green-api-logo_2.png", + "GREEN API logo" +) + +print(response.data) +``` ### Group creation and sending a message to the group -```python -chatIds = [ - "79001234567@c.us" -] -resultCreate = greenAPI.groups.createGroup('GroupName', - chatIds) - -if resultCreate.code == 200: - resultSend = greenAPI.sending.sendMessage(resultCreate.data['chatId'], - 'Message text') -``` +**Attention**. If one tries to create a group with a non-existent number, WhatsApp may block the sender's number. The +number in the example is non-existent. -IMPORTANT: If one tries to create a group with a non-existent number, WhatsApp -may block the sender's number. The number in the example is non-existent. +Link to example: [createGroupAndSendMessage.py]( +https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/createGroupAndSendMessage.py +). -Example url: [createGroupAndSendMessage.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/createGroupAndSendMessage.py) +``` +create_group_response = greenAPI.groups.createGroup( + "Group Name", ["11001234567@c.us"] +) +if create_group_response.code == 200: + send_message_response = greenAPI.sending.sendMessage( + create_group_response.data["chatId"], "Message text" + ) +``` ### Receive incoming messages by HTTP API -The general concept of receiving data in the Green API is described [here](https://green-api.com/en/docs/api/receiving/) -To start receiving messages by the HTTP API you need to execute the library method: +Link to example: [receiveNotification.py]( +https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/receiveNotification.py +). + +The general concept of receiving data in the GREEN API is described [here]( +https://green-api.com/en/docs/api/receiving/ +). To start receiving notifications by the HTTP API you need to execute the library method: -```python +``` greenAPI.webhooks.startReceivingNotifications(onEvent) ``` -onEvent - your method which should contain parameters: -Parameter | Description ------ | ----- -typewebhook | received message type (string) -body | message body (json) +onEvent - your function which should contain parameters: -Message body types and formats [here](https://green-api.com/en/docs/api/receiving/notifications-format/) +| Parameter | Description | +|-------------|----------------------------------| +| typeWebhook | received notification type (str) | +| body | notification body (dict) | -This method will be called when an incoming message is received. Next, process messages according to the business logic of your system. +Notification body types and formats can be found [here]( +https://green-api.com/en/docs/api/receiving/notifications-format/ +). -## Examples list +This method will be called when an incoming notification is received. Next, process notifications according to the +business logic of your system. -Description | Module ------ | ----- -Example of sending text | [sendTextMessage.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendTextMessage.py) -Example of sending a picture by URL | [sendPictureByLink.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendPictureByLink.py) -Example of sending a picture by uploading from the disk | [sendPictureByUpload.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendPictureByUpload.py) -Example of a group creation and sending a message to the group | [createGroupAndSendMessage.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/createGroupAndSendMessage.py) -Example of incoming webhooks receiving | [receiveNotification.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/receiveNotification.py) +## Examples list +| Description | Module | +|----------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------| +| Example of sending text | [sendTextMessage.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendTextMessage.py) | +| Example of sending a picture by URL | [sendPictureByLink.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendPictureByLink.py) | +| Example of sending a picture by uploading from the disk | [sendPictureByUpload.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendPictureByUpload.py) | +| Example of a group creation and sending a message to the group | [createGroupAndSendMessage.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/createGroupAndSendMessage.py) | +| Example of incoming webhooks receiving | [receiveNotification.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/receiveNotification.py) | ## The full list of the library methods @@ -177,20 +202,15 @@ Example of incoming webhooks receiving | [receiveNotification.py](https://github ## Service methods documentation -[https://green-api.com/en/docs/api/](https://green-api.com/en/docs/api/) +[https://green-api.com/en/docs/api/](https://green-api.com/en/docs/api/). ## External products -* [requests](https://requests.readthedocs.io) - for http requests +- [requests](https://requests.readthedocs.io/en/latest/) - for HTTP requests. ## License -[![CC BY-ND 4.0][cc-by-nd-shield]][cc-by-nd] - -This work is licensed under a -[Creative Commons Attribution-NoDerivatives 4.0 International License][cc-by-nd]. - -[cc-by-nd]: https://creativecommons.org/licenses/by-nd/4.0/ -[cc-by-nd-shield]: https://img.shields.io/badge/License-CC%20BY--ND%204.0-lightgrey.svg - -Please see file [LICENSE](LICENSE) \ No newline at end of file +Licensed under [ +Creative Commons Attribution-NoDerivatives 4.0 International (CC BY-ND 4.0) +](https://creativecommons.org/licenses/by-nd/4.0/) terms. +Please see file [LICENSE](https://github.com/green-api/whatsapp-api-client-python/blob/master/LICENSE). diff --git a/README_RUS.md b/README_RUS.md index 1b4ba62..7b821ff 100644 --- a/README_RUS.md +++ b/README_RUS.md @@ -6,116 +6,132 @@ ![](https://img.shields.io/github/actions/workflow/status/green-api/whatsapp-api-client-python/python-package.yml) ![](https://img.shields.io/pypi/dm/whatsapp-api-client-python) -- [English documentation](README.md) - -Python библиотека для интеграции с мессенджером WhatsAPP через API сервиса [green-api.com](https://green-api.com/). Чтобы воспользоваться библиотекой нужно получить регистрационный токен и id аккаунта в [личном кабинете](https://console.green-api.com). Есть бесплатный тариф аккаунта разработчика. +whatsapp-api-client-python - библиотека для интеграции с мессенджером WhatsApp через API +сервиса [green-api.com](https://green-api.com/). Чтобы воспользоваться библиотекой, нужно получить регистрационный токен +и ID аккаунта в [личном кабинете](https://console.green-api.com/). Есть бесплатный тариф аккаунта разработчика. ## API -Документация к REST API находится по [ссылке](https://green-api.com/docs/api/). Библиотека является оберткой к REST API, поэтому документация по ссылке выше применима и к самой библиотеке. +Документация к REST API находится по [ссылке](https://green-api.com/docs/api/). Библиотека является обёрткой к REST API, +поэтому документация по ссылке выше применима и к самой библиотеке. + +## Авторизация + +Чтобы отправить сообщение или выполнить другие методы GREEN API, аккаунт WhatsApp в приложении телефона должен быть в +авторизованном состоянии. Для авторизации аккаунта перейдите в [личный кабинет](https://console.green-api.com/) и +сканируйте QR-код с использованием приложения WhatsApp. ## Установка ```shell -pip install whatsapp-api-client-python +python -m pip install whatsapp-api-client-python ``` -## Авторизация +## Импорт -Чтобы отправить сообщение или выполнить другой метод Green-API, аккаунт WhatsApp в приложении телефона должен быть в авторизованном состоянии. Для авторизации аккаунта перейдите в [личный кабинет](https://console.green-api.com) и сканируйте QR-код с использованием приложения WhatsApp. +``` +from whatsapp_api_client_python import API +``` ## Примеры ### Как инициализировать объект -```python -greenAPI = API.GreenApi(ID_INSTANCE, API_TOKEN_INSTANCE) +``` +greenAPI = API.GreenApi( + "1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345" +) ``` ### Отправка текстового сообщения на номер WhatsApp -```python -result = greenAPI.sending.sendMessage('79001234567@g.us', 'Message text') -``` +Ссылка на пример: [sendTextMessage.py](examples/sendTextMessage.py). -Ссылка на пример: [sendTextMessage.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendTextMessage.py) - -Обратите внимание, что ключи можно получать из переменных среды: -```python -from os import environ +``` +response = greenAPI.sending.sendMessage("11001234567@c.us", "Message text") -ID_INSTANCE = environ['ID_INSTANCE'] -API_TOKEN_INSTANCE = environ['API_TOKEN_INSTANCE'] +print(response.data) ``` ### Отправка картинки по URL -```python -result = greenAPI.sending.sendFileByUrl('120363025955348359@g.us', - 'https://www.google.ru/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png', - 'googlelogo_color_272x92dp.png', 'Google logo') -``` +Ссылка на пример: [sendPictureByLink.py](examples/sendPictureByLink.py). -Ссылка на пример: [sendPictureByLink.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendPictureByLink.py) +``` +response = greenAPI.sending.sendFileByUrl( + "11001234567@c.us", + "https://green-api.com/green-api-logo_2.png", + "green-api-logo_2.png", + "GREEN API logo" +) + +print(response.data) +``` ### Отправка картинки загрузкой с диска -```python -result = greenAPI.sending.sendFileByUpload('120363025955348359@g.us', - 'C:\\Games\\PicFromDisk.png', - 'PicFromDisk.png', 'Picture from disk') -``` +Ссылка на пример: [sendPictureByUpload.py](examples/sendPictureByUpload.py). -Ссылка на пример: [sendPictureByUpload.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendPictureByUpload.py) +``` +response = greenAPI.sending.sendFileByUpload( + "11001234567@c.us", + "data/green-api-logo_2.png", + "green-api-logo_2.png", + "GREEN API logo" +) + +print(response.data) +``` ### Создание группы и отправка сообщения в эту группу -```python -chatIds = [ - "79001234567@c.us" -] -resultCreate = greenAPI.groups.createGroup('GroupName', - chatIds) +**Важно**. Если попытаться создать группу с несуществующим номером WhatsApp, то может заблокировать номер отправителя. +Номер в примере не существует. -if resultCreate.code == 200: - resultSend = greenAPI.sending.sendMessage(resultCreate.data['chatId'], - 'Message text') -``` +Ссылка на пример: [createGroupAndSendMessage.py](examples/createGroupAndSendMessage.py). -ВАЖНО: Если попытаться создать группу с несуществующим номером WhatsApp -может заблокировать номер отправителя. Номер в примере не существует. +``` +create_group_response = greenAPI.groups.createGroup( + "Group Name", ["11001234567@c.us"] +) +if create_group_response.code == 200: + send_message_response = greenAPI.sending.sendMessage( + create_group_response.data["chatId"], "Message text" + ) +``` -Ссылка на пример: [createGroupAndSendMessage.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/createGroupAndSendMessage.py) +### Получение входящих уведомлений через HTTP API -### Получение входящих сообщений через HTTP API +Ссылка на пример: [receiveNotification.py](examples/receiveNotification.py). -Общая концепция получения данных в Green API описана [здесь](https://green-api.com/docs/api/receiving/) -Для старта получения сообщений через HTTP API требуется выполнить метод библиотеки: +Общая концепция получения данных в GREEN API описана [здесь](https://green-api.com/docs/api/receiving/). Для старта +получения уведомлений через HTTP API требуется выполнить метод библиотеки: -```python +``` greenAPI.webhooks.startReceivingNotifications(onEvent) ``` -onEvent - ваш метод, который должен содержать параметры: -Параметр | Описание ------ | ----- -typeWebhook | тип полученного сообщения (строка) -body | тело сообщения (json) +onEvent - ваша функция, которая должен содержать параметры: -Типы и форматы тел сообщений [здесь](https://green-api.com/docs/api/receiving/notifications-format/) +| Параметр | Описание | +|-------------|-----------------------------------| +| typeWebhook | тип полученного уведомления (str) | +| body | тело уведомления (dict) | -Этот метод будет вызываться при получении входящего сообщения. Далее обрабатываете сообщения согласно бизнес-логике вашей системы. +Типы и форматы тел уведомлений находятся [здесь](https://green-api.com/docs/api/receiving/notifications-format/). -## Список примеров +Эта функция будет вызываться при получении входящего уведомления. Далее обрабатываете уведомления согласно бизнес-логике +вашей системы. -Описание | Модуль ------ | ----- -Пример отправки текста | [sendTextMessage.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendTextMessage.py) -Пример отправки картинки по URL | [sendPictureByLink.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendPictureByLink.py) -Пример отправки картинки загрузкой с диска | [sendPictureByUpload.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendPictureByUpload.py) -Пример создание группы и отправка сообщения в группу | [createGroupAndSendMessage.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/createGroupAndSendMessage.py) -Пример получения входящих уведомлений | [receiveNotification.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/receiveNotification.py) +## Список примеров +| Описание | Модуль | +|------------------------------------------------------|-----------------------------------------------------------------------| +| Пример отправки текста | [sendTextMessage.py](examples/sendTextMessage.py) | +| Пример отправки картинки по URL | [sendPictureByLink.py](examples/sendPictureByLink.py) | +| Пример отправки картинки загрузкой с диска | [sendPictureByUpload.py](examples/sendPictureByUpload.py) | +| Пример создание группы и отправка сообщения в группу | [createGroupAndSendMessage.py](examples/createGroupAndSendMessage.py) | +| Пример получения входящих уведомлений | [receiveNotification.py](examples/receiveNotification.py) | ## Полный список методов библиотеки @@ -172,22 +188,15 @@ body | тело сообщения (json) ## Документация по методам сервиса -[https://green-api.com/docs/api/](https://green-api.com/docs/api/) +[https://green-api.com/docs/api/](https://green-api.com/docs/api/). ## Сторонние продукты -* [requests](https://requests.readthedocs.io) - для http запросов +- [requests](https://requests.readthedocs.io/en/latest/) - для HTTP запросов. ## Лицензия -Лицензировано на условиях MIT. Смотрите файл [LICENSE](LICENSE) - -[![CC BY-ND 4.0][cc-by-nd-shield]][cc-by-nd] - -Эта работа распространяется под лицензией -[Creative Commons Attribution-NoDerivatives 4.0 International License][cc-by-nd]. - -[cc-by-nd]: https://creativecommons.org/licenses/by-nd/4.0/ -[cc-by-nd-shield]: https://img.shields.io/badge/License-CC%20BY--ND%204.0-lightgrey.svg - -Пожалуйста, смотрите файл [LICENSE](LICENSE) +Лицензировано на условиях [ +Creative Commons Attribution-NoDerivatives 4.0 International (CC BY-ND 4.0) +](https://creativecommons.org/licenses/by-nd/4.0/). +[LICENSE](LICENSE). diff --git a/examples/__init__.py b/examples/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/examples/createGroupAndSendMessage.py b/examples/createGroupAndSendMessage.py index 2323eae..236fda8 100644 --- a/examples/createGroupAndSendMessage.py +++ b/examples/createGroupAndSendMessage.py @@ -1,27 +1,27 @@ -from whatsapp_api_client_python import API as API +from whatsapp_api_client_python import API -ID_INSTANCE = '1101000001' -API_TOKEN_INSTANCE = '3e03ea9ff3324e228ae3dfdf4d48e409bfa1b1ad0b0c46bf8c' +greenAPI = API.GreenApi( + "1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345" +) -greenAPI = API.GreenApi(ID_INSTANCE, API_TOKEN_INSTANCE) def main(): - chatIds = [ - "11001234567@c.us" - ] - resultCreate = greenAPI.groups.createGroup('GroupName', - chatIds) + create_group_response = greenAPI.groups.createGroup( + "Group Name", ["11001234567@c.us"] + ) + if create_group_response.code == 200: + print(create_group_response.data) - if resultCreate.code == 200: - print(resultCreate.data) - resultSend = greenAPI.sending.sendMessage(resultCreate.data['chatId'], - 'Message text') - if resultSend.code == 200: - print(resultSend.data) + send_message_response = greenAPI.sending.sendMessage( + create_group_response.data["chatId"], "Message text" + ) + if send_message_response.code == 200: + print(send_message_response.data) else: - print(resultSend.error) + print(send_message_response.error) else: - print(resultCreate.error) + print(create_group_response.error) -if __name__ == "__main__": - main() \ No newline at end of file + +if __name__ == '__main__': + main() diff --git a/examples/data/green-api-logo_2.png b/examples/data/green-api-logo_2.png new file mode 100644 index 0000000..8717c3b Binary files /dev/null and b/examples/data/green-api-logo_2.png differ diff --git a/examples/receiveNotification.py b/examples/receiveNotification.py index 1a8e7b4..05edbf5 100644 --- a/examples/receiveNotification.py +++ b/examples/receiveNotification.py @@ -1,11 +1,12 @@ -from datetime import datetime import json -from whatsapp_api_client_python import API as API +from datetime import datetime + +from whatsapp_api_client_python import API -ID_INSTANCE = '1101000001' -API_TOKEN_INSTANCE = '3e03ea9ff3324e228ae3dfdf4d48e409bfa1b1ad0b0c46bf8c' +greenAPI = API.GreenApi( + "1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345" +) -greenAPI = API.GreenApi(ID_INSTANCE, API_TOKEN_INSTANCE) def main(): greenAPI.webhooks.startReceivingNotifications(onEvent) diff --git a/examples/sendPictureByLink.py b/examples/sendPictureByLink.py index 00f3c94..03521f3 100644 --- a/examples/sendPictureByLink.py +++ b/examples/sendPictureByLink.py @@ -1,15 +1,20 @@ -from whatsapp_api_client_python import API as API +from whatsapp_api_client_python import API -ID_INSTANCE = '1101000001' -API_TOKEN_INSTANCE = '3e03ea9ff3324e228ae3dfdf4d48e409bfa1b1ad0b0c46bf8c' +greenAPI = API.GreenApi( + "1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345" +) -greenAPI = API.GreenApi(ID_INSTANCE, API_TOKEN_INSTANCE) def main(): - result = greenAPI.sending.sendFileByUrl('11001234567@c.us', - 'https://www.google.ru/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png', - 'googlelogo_color_272x92dp.png', 'Google logo') - print(result.data) + response = greenAPI.sending.sendFileByUrl( + "11001234567@c.us", + "https://green-api.com/green-api-logo_2.png", + "green-api-logo_2.png", + "GREEN API logo" + ) -if __name__ == "__main__": - main() \ No newline at end of file + print(response.data) + + +if __name__ == '__main__': + main() diff --git a/examples/sendPictureByUpload.py b/examples/sendPictureByUpload.py index 56854cd..8921108 100644 --- a/examples/sendPictureByUpload.py +++ b/examples/sendPictureByUpload.py @@ -1,15 +1,20 @@ -from whatsapp_api_client_python import API as API +from whatsapp_api_client_python import API -ID_INSTANCE = '1101000001' -API_TOKEN_INSTANCE = '3e03ea9ff3324e228ae3dfdf4d48e409bfa1b1ad0b0c46bf8c' +greenAPI = API.GreenApi( + "1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345" +) -greenAPI = API.GreenApi(ID_INSTANCE, API_TOKEN_INSTANCE) def main(): - result = greenAPI.sending.sendFileByUpload('11001234567@c.us', - "C:\\Games\\PicFromDisk.png", - 'PicFromDisk.png', 'Picture from disk') - print(result.data) + response = greenAPI.sending.sendFileByUpload( + "11001234567@c.us", + "data/green-api-logo_2.png", + "green-api-logo_2.png", + "GREEN API logo" + ) -if __name__ == "__main__": - main() \ No newline at end of file + print(response.data) + + +if __name__ == '__main__': + main() diff --git a/examples/sendTextMessage.py b/examples/sendTextMessage.py index 9260ff5..fd72930 100644 --- a/examples/sendTextMessage.py +++ b/examples/sendTextMessage.py @@ -1,13 +1,15 @@ -from whatsapp_api_client_python import API as API +from whatsapp_api_client_python import API -ID_INSTANCE = '1101000001' -API_TOKEN_INSTANCE = '3e03ea9ff3324e228ae3dfdf4d48e409bfa1b1ad0b0c46bf8c' +greenAPI = API.GreenApi( + "1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345" +) -greenAPI = API.GreenApi(ID_INSTANCE, API_TOKEN_INSTANCE) def main(): - result = greenAPI.sending.sendMessage('11001234567@c.us', 'Message text') - print(result.data) + response = greenAPI.sending.sendMessage("11001234567@c.us", "Message text") -if __name__ == "__main__": - main() \ No newline at end of file + print(response.data) + + +if __name__ == '__main__': + main() diff --git a/setup.py b/setup.py index ad3d304..c6344d8 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setup( name="whatsapp-api-client-python", - version="0.0.36", + version="0.0.37", description=( "This library helps you easily create" " a Python application with WhatsApp API." @@ -15,7 +15,7 @@ author="GREEN API", author_email="support@green-api.com", url="https://github.com/green-api/whatsapp-api-client-python", - packages=find_packages(exclude=["examples", "tests"]), + packages=find_packages(exclude=["tests"]), classifiers=[ "Development Status :: 5 - Production/Stable", "Environment :: Console",