Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,20 @@ response = greenAPI.sending.sendPoll(
print(response.data)
```

### Sending a text status

Link to example: [sendTextStatus.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/statusesMethods/sendTextStatus.py).

```
response = greenAPI.statuses.sendTextStatus(
"I sent this status using Green Api Python SDK!",
"#54c774",
"NORICAN_REGULAR"
)

print(response.data)
```

## Examples list

| Description | Module |
Expand All @@ -179,6 +193,7 @@ print(response.data)
| 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) |
| Example of sending a polling message | [sendPoll.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendPoll.py) |
| Example of sending a text status | [sendTextStatus.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/sendTextStatus.py) |

## The full list of the library methods

Expand All @@ -204,6 +219,13 @@ print(response.data)
| `groups.removeAdmin` | The method deprives the participant of group chat administration rights | [RemoveAdmin](https://green-api.com/en/docs/api/groups/RemoveAdmin/) |
| `groups.setGroupPicture` | The method sets the avatar of the group | [SetGroupPicture](https://green-api.com/en/docs/api/groups/SetGroupPicture/) |
| `groups.leaveGroup` | The method logs the user of the current account out of the group chat | [LeaveGroup](https://green-api.com/en/docs/api/groups/LeaveGroup/) |
| `statuses.sendTextStatus` | The method is aimed for sending a text status | [SendTextStatus](https://green-api.com/en/docs/api/statuses/SendTextStatus/) |
| `statuses.sendVoiceStatus` | The method is aimed for sending a voice status | [SendVoiceStatus](https://green-api.com/en/docs/api/statuses/SendVoiceStatus/) |
| `statuses.sendMediaStatus` | The method is aimed for sending a pictures or video status | [SendMediaStatus](https://green-api.com/en/docs/api/statuses/SendMediaStatus/) |
| `statuses.deleteStatus` | The method is aimed for deleting a certain status | [DeleteStatus](https://green-api.com/en/docs/api/statuses/DeleteStatus/) |
| `statuses.getStatusStatistic` | The method returns an array of recipients marked sent/delivered/read for a given status | [GetStatusStatistic](https://green-api.com/en/docs/api/statuses/GetStatusStatistic/) |
| `statuses.getOutgoingStatuses` | The method returns the outgoing statuses of the account | [GetOutgoingStatuses](https://green-api.com/en/docs/api/statuses/GetOutgoingStatuses/) |
| `statuses.getIncomingStatuses` | The method returns the incoming statuses of the account | [GetIncomingStatuses](https://green-api.com/en/docs/api/statuses/GetIncomingStatuses/) |
| `journals.getChatHistory` | The method returns the chat message history | [GetChatHistory](https://green-api.com/en/docs/api/journals/GetChatHistory/) |
| `journals.getMessage` | The method returns a chat message | [GetMessage](https://green-api.com/en/docs/api/journals/GetMessage/) |
| `journals.lastIncomingMessages` | The method returns the most recent incoming messages of the account | [LastIncomingMessages](https://green-api.com/en/docs/api/journals/LastIncomingMessages/) |
Expand Down
14 changes: 14 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@ response = greenAPI.sending.sendPoll(
print(response.data)
```

## Отправка текстового статуса

Ссылка на пример: [sendPoll.py](https://github.com/green-api/whatsapp-api-client-python/blob/master/examples/statusesMethods/sendTextStatus.py).

```
response = greenAPI.statuses.sendTextStatus(
"I sent this status using Green Api Python SDK!",
"#54c774",
"NORICAN_REGULAR"
)

print(response.data)
```

## Список примеров

| Описание | Модуль |
Expand Down
1 change: 0 additions & 1 deletion examples/partherMethods/DeleteInstanceAccount.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@ def main():
response = greenAPI.partner.deleteInstanceAccount(1103123456)
print(response.data)


if __name__ == '__main__':
main()
13 changes: 13 additions & 0 deletions examples/statusesMethods/deleteStatus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from whatsapp_api_client_python import API

greenAPI = API.GreenAPI(
"1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345"
)


def main():
response = greenAPI.statuses.deleteStatus('BAE54F518532FCB1')
print(response.data)

if __name__ == '__main__':
main()
19 changes: 19 additions & 0 deletions examples/statusesMethods/getStatuses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from whatsapp_api_client_python import API

greenAPI = API.GreenAPI(
"1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345"
)


def main():
response = greenAPI.statuses.getIncomingStatuses(1400) # minutes argument is Optional
print(response.data)

response = greenAPI.statuses.getOutgoingStatuses(1400) # minutes argument is Optional
print(response.data)

response = greenAPI.statuses.getStatusStatistic('BAE54F518532FCB1')
print(response.data)

if __name__ == '__main__':
main()
17 changes: 17 additions & 0 deletions examples/statusesMethods/sendMediaStatus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from whatsapp_api_client_python import API

greenAPI = API.GreenAPI(
"1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345"
)


def main():
response = greenAPI.statuses.sendMediaStatus(
"https://example.com/file.mp4",
"test.mp4"
"#54c774")

print(response.data)

if __name__ == '__main__':
main()
17 changes: 17 additions & 0 deletions examples/statusesMethods/sendTextStatus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from whatsapp_api_client_python import API

greenAPI = API.GreenAPI(
"1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345"
)


def main():
response = greenAPI.statuses.sendTextStatus(
"I sent this status using Green Api Python SDK!",
"#54c774",
"NORICAN_REGULAR")

print(response.data)

if __name__ == '__main__':
main()
17 changes: 17 additions & 0 deletions examples/statusesMethods/sendVoiceStatus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from whatsapp_api_client_python import API

greenAPI = API.GreenAPI(
"1101000001", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345"
)


def main():
response = greenAPI.statuses.sendVoiceStatus(
"https://example.com/file.mp3",
"test.mp3"
"#54c774")

print(response.data)

if __name__ == '__main__':
main()
13 changes: 13 additions & 0 deletions tests/test_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def test_methods(self, mock_request):
*self.account_methods,
*self.device_methods,
*self.group_methods,
*self.status_methods,
*self.log_methods,
*self.queue_methods,
*self.read_mark_methods,
Expand Down Expand Up @@ -68,6 +69,18 @@ def group_methods(self) -> typing.List[Response]:
api.groups.leaveGroup("")
]

@property
def status_methods(self) -> typing.List[Response]:
return [
api.statuses.sendTextStatus(""),
api.statuses.sendVoiceStatus("", ""),
api.statuses.sendMediaStatus("", ""),
api.statuses.deleteStatus(""),
api.statuses.getStatusStatistic(""),
api.statuses.getIncomingStatuses(),
api.statuses.getOutgoingStatuses()
]

@property
def log_methods(self) -> typing.List[Response]:
return [
Expand Down
5 changes: 3 additions & 2 deletions whatsapp_api_client_python/API.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
sending,
serviceMethods,
webhooks,
partner
partner,
statuses
)


Expand Down Expand Up @@ -63,6 +64,7 @@ def __init__(
self.sending = sending.Sending(self)
self.serviceMethods = serviceMethods.ServiceMethods(self)
self.webhooks = webhooks.Webhooks(self)
self.statuses = statuses.Statuses(self)

self.logger = logging.getLogger("whatsapp-api-client-python")
self.__prepare_logger()
Expand Down Expand Up @@ -176,7 +178,6 @@ def __prepare_session(self) -> None:
self.session.mount("http://", HTTPAdapter(max_retries=retry))
self.session.mount("https://", HTTPAdapter(max_retries=retry))


class GreenAPI(GreenApi):
pass

Expand Down
19 changes: 12 additions & 7 deletions whatsapp_api_client_python/tools/partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,23 @@ def deleteInstanceAccount(self, idInstance: int) -> Response:
https://green-api.com/en/docs/partners/deleteInstanceAccount/
"""

request_body = self.handle_parameters(locals())
request_body = self.__handle_parameters(locals())

return self.api.request(
"POST", (
"{{host}}/partner/"
"deleteInstanceAccount/{{partnerToken}}"
), request_body
)

@classmethod
def __handle_parameters(cls, parameters: dict) -> dict:
handled_parameters = parameters.copy()

handled_parameters.pop("self")

for key, value in parameters.items():
if value is None:
handled_parameters.pop(key)

def handle_parameters(self, parameters: dict) -> dict:
return {
key: value
for key, value in parameters.items()
if value is not None and key != "self"
}
return handled_parameters
Loading
Loading