Skip to content

Commit aad8bb7

Browse files
committed
Updated category Account
1 parent 11fbc11 commit aad8bb7

File tree

3 files changed

+122
-79
lines changed

3 files changed

+122
-79
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ Example of incoming webhooks receiving | [receiveNotification.py](https://github
123123

124124
| API method | Description | Documentation link |
125125
|----------------------------------------|--------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------|
126-
| `account.getSettings` | The method is designed to get the current settings of the account | [GetSettings](https://green-api.com/en/docs/api/account/GetSettings/) |
127-
| `account.setSettings` | The method is designed to set the account settings | [SetSettings](https://green-api.com/en/docs/api/account/SetSettings/) |
128-
| `account.getStateInstance` | The method is designed to get the state of the account | [GetStateInstance](https://green-api.com/en/docs/api/account/GetStateInstance/) |
129-
| `account.getStatusInstance` | The method is designed to get the socket connection state of the account instance with WhatsApp | [GetStatusInstance](https://green-api.com/en/docs/api/account/GetStatusInstance/) |
126+
| `account.get_settings` | The method is designed to get the current settings of the account | [GetSettings](https://green-api.com/en/docs/api/account/GetSettings/) |
127+
| `account.set_settings` | The method is designed to set the account settings | [SetSettings](https://green-api.com/en/docs/api/account/SetSettings/) |
128+
| `account.get_state_instance` | The method is designed to get the state of the account | [GetStateInstance](https://green-api.com/en/docs/api/account/GetStateInstance/) |
129+
| `account.get_status_instance` | The method is designed to get the socket connection state of the account instance with WhatsApp | [GetStatusInstance](https://green-api.com/en/docs/api/account/GetStatusInstance/) |
130130
| `account.reboot` | The method is designed to restart the account | [Reboot](https://green-api.com/en/docs/api/account/Reboot/) |
131131
| `account.logout` | The method is designed to unlogin the account | [Logout](https://green-api.com/en/docs/api/account/Logout/) |
132132
| `account.qr` | The method is designed to get a QR code | [QR](https://green-api.com/en/docs/api/account/QR/) |
133-
| `account.setProfilePicture` | The method is designed to set the avatar of the account | [SetProfilePicture](https://green-api.com/en/docs/api/account/SetProfilePicture/) |
133+
| `account.set_profile_picture` | The method is designed to set the avatar of the account | [SetProfilePicture](https://green-api.com/en/docs/api/account/SetProfilePicture/) |
134134
| `device.getDeviceInfo` | The method is designed to get information about the device (phone) on which the WhatsApp Business application is running | [GetDeviceInfo](https://green-api.com/en/docs/api/phone/GetDeviceInfo/) |
135135
| `groups.createGroup` | The method is designed to create a group chat | [CreateGroup](https://green-api.com/en/docs/api/groups/CreateGroup/) |
136136
| `groups.updateGroupName` | The method changes the name of the group chat | [UpdateGroupName](https://green-api.com/en/docs/api/groups/UpdateGroupName/) |

README_RUS.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,14 @@ body | тело сообщения (json)
118118

119119
| Метод API | Описание | Documentation link |
120120
|----------------------------------------|---------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------|
121-
| `account.getSettings` | Метод предназначен для получения текущих настроек аккаунта | [GetSettings](https://green-api.com/docs/api/account/GetSettings/) |
122-
| `account.setSettings` | Метод предназначен для установки настроек аккаунта | [SetSettings](https://green-api.com/docs/api/account/SetSettings/) |
123-
| `account.getStateInstance` | Метод предназначен для получения состояния аккаунта | [GetStateInstance](https://green-api.com/docs/api/account/GetStateInstance/) |
124-
| `account.getStatusInstance` | Метод предназначен для получения состояния сокета соединения инстанса аккаунта с WhatsApp | [GetStatusInstance](https://green-api.com/docs/api/account/GetStatusInstance/) |
121+
| `account.get_settings` | Метод предназначен для получения текущих настроек аккаунта | [GetSettings](https://green-api.com/docs/api/account/GetSettings/) |
122+
| `account.set_settings` | Метод предназначен для установки настроек аккаунта | [SetSettings](https://green-api.com/docs/api/account/SetSettings/) |
123+
| `account.get_state_instance` | Метод предназначен для получения состояния аккаунта | [GetStateInstance](https://green-api.com/docs/api/account/GetStateInstance/) |
124+
| `account.get_status_instance` | Метод предназначен для получения состояния сокета соединения инстанса аккаунта с WhatsApp | [GetStatusInstance](https://green-api.com/docs/api/account/GetStatusInstance/) |
125125
| `account.reboot` | Метод предназначен для перезапуска аккаунта | [Reboot](https://green-api.com/docs/api/account/Reboot/) |
126126
| `account.logout` | Метод предназначен для разлогинивания аккаунта | [Logout](https://green-api.com/docs/api/account/Logout/) |
127127
| `account.qr` | Метод предназначен для получения QR-кода | [QR](https://green-api.com/docs/api/account/QR/) |
128-
| `account.setProfilePicture` | Метод предназначен для установки аватара аккаунта | [SetProfilePicture](https://green-api.com/docs/api/account/SetProfilePicture/) |
128+
| `account.set_profile_picture` | Метод предназначен для установки аватара аккаунта | [SetProfilePicture](https://green-api.com/docs/api/account/SetProfilePicture/) |
129129
| `device.getDeviceInfo` | Метод предназначен для получения информации об устройстве (телефоне), на котором запущено приложение WhatsApp Business | [GetDeviceInfo](https://green-api.com/docs/api/phone/GetDeviceInfo/) |
130130
| `groups.createGroup` | Метод предназначен для создания группового чата | [CreateGroup](https://green-api.com/docs/api/groups/CreateGroup/) |
131131
| `groups.updateGroupName` | Метод изменяет наименование группового чата | [UpdateGroupName](https://green-api.com/docs/api/groups/UpdateGroupName/) |
Lines changed: 112 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,120 @@
1-
import os.path
2-
from whatsapp_api_client_python.response import Response
1+
from pathlib import Path
2+
from typing import Optional, TYPE_CHECKING
3+
4+
from ..response import Response
5+
6+
if TYPE_CHECKING:
7+
from ..API import GreenApi
38

49

510
class Account:
6-
def __init__(self, greenApi) -> None:
7-
self.greenApi = greenApi
8-
9-
def getSettings(self) -> Response:
10-
'The method is aimed for getting the '\
11-
'current account settings.'
12-
13-
return self.greenApi.request('GET',
14-
'{{host}}/waInstance{{idInstance}}'
15-
'/getSettings/{{apiTokenInstance}}')
16-
17-
def getStateInstance(self) -> Response:
18-
'The method is aimed for getting the account state.'
19-
20-
return self.greenApi.request('GET',
21-
'{{host}}/waInstance{{idInstance}}'
22-
'/getStateInstance/{{apiTokenInstance}}')
23-
24-
def getStatusInstance(self) -> Response:
25-
'The method is aimed for getting the status of the account instance '\
26-
'socket connection with WhatsApp.'
27-
28-
return self.greenApi.request('GET',
29-
'{{host}}/waInstance{{idInstance}}'
30-
'/getStatusInstance/{{apiTokenInstance}}')
11+
def __init__(self, api: "GreenApi"):
12+
self.api = api
13+
14+
def get_settings(self) -> Response:
15+
"""
16+
The method is aimed for getting the current account settings.
17+
"""
18+
19+
return self.api.request(
20+
"GET", (
21+
"{{host}}/waInstance{{idInstance}}/"
22+
"GetSettings/{{apiTokenInstance}}"
23+
)
24+
)
25+
26+
def set_settings(
27+
self,
28+
countryInstance: Optional[str] = None,
29+
webhookUrl: Optional[str] = None,
30+
webhookUrlToken: Optional[str] = None,
31+
delaySendMessagesMilliseconds: Optional[int] = None,
32+
markIncomingMessagesReaded: Optional[str] = None,
33+
markIncomingMessagesReadedOnReply: Optional[str] = None,
34+
outgoingWebhook: Optional[str] = None,
35+
outgoingMessageWebhook: Optional[str] = None,
36+
stateWebhook: Optional[str] = None,
37+
incomingWebhook: Optional[str] = None,
38+
deviceWebhook: Optional[str] = None,
39+
statusInstanceWebhook: Optional[str] = None,
40+
sendFromUTC: Optional[str] = None,
41+
sendToUTC: Optional[str] = None
42+
) -> Response:
43+
"""The method is aimed for setting account settings."""
44+
45+
parameters = locals()
46+
request_body = parameters.copy()
47+
48+
del request_body["self"]
49+
50+
for key, value in parameters.items():
51+
if value is None:
52+
del request_body[key]
53+
54+
return self.api.request(
55+
"POST", (
56+
"{{host}}/waInstance{{idInstance}}/"
57+
"SetSettings/{{apiTokenInstance}}"
58+
), request_body
59+
)
60+
61+
def get_state_instance(self) -> Response:
62+
"""The method is aimed for getting the account state."""
63+
64+
return self.api.request(
65+
"GET", (
66+
"{{host}}/waInstance{{idInstance}}/"
67+
"getStateInstance/{{apiTokenInstance}}"
68+
)
69+
)
70+
71+
def get_status_instance(self) -> Response:
72+
"""
73+
The method is aimed for getting the status of the account
74+
instance socket connection with WhatsApp.
75+
"""
76+
77+
return self.api.request(
78+
"GET", (
79+
"{{host}}/waInstance{{idInstance}}/"
80+
"getStatusInstance/{{apiTokenInstance}}"
81+
)
82+
)
83+
84+
def reboot(self) -> Response:
85+
"""The method is aimed for rebooting an account."""
86+
87+
return self.api.request(
88+
"GET", (
89+
"{{host}}/waInstance{{idInstance}}/Reboot/{{apiTokenInstance}}"
90+
)
91+
)
3192

3293
def logout(self) -> Response:
33-
'The method is aimed for logging out an account.'
34-
35-
return self.greenApi.request('GET',
36-
'{{host}}/waInstance{{idInstance}}'
37-
'/Logout/{{apiTokenInstance}}')
94+
"""The method is aimed for logging out an account."""
95+
96+
return self.api.request(
97+
"GET", (
98+
"{{host}}/waInstance{{idInstance}}/Logout/{{apiTokenInstance}}"
99+
)
100+
)
38101

39102
def qr(self) -> Response:
40-
'The method is aimed for getting QR code. To authorize your account, '\
41-
'you have to scan a QR code from application WhatsApp Business'\
42-
'on your phone. You can also get a QR code and authorize your'\
43-
'account in your profile.'
44-
45-
return self.greenApi.request('GET',
46-
'{{host}}/waInstance{{idInstance}}'
47-
'/QR/{{apiTokenInstance}}')
103+
"""The method is aimed for getting QR code."""
48104

49-
def reboot(self) -> Response:
50-
'The method is aimed for rebooting an account.'
51-
52-
return self.greenApi.request('GET',
53-
'{{host}}/waInstance{{idInstance}}'
54-
'/Reboot/{{apiTokenInstance}}')
55-
56-
def setProfilePicture(self, path) -> Response:
57-
'The method is aimed for setting an account picture.'
58-
59-
pathParts = os.path.split(path)
60-
file = pathParts[1]
61-
62-
files = [
63-
('file',(file, open(path,'rb'),'image/jpeg'))
64-
]
65-
66-
return self.greenApi.request('POST',
67-
'{{host}}/waInstance{{idInstance}}'
68-
'/SetProfilePicture/{{apiTokenInstance}}', None, files)
69-
70-
def setSettings(self, requestBody) -> Response:
71-
'The method is aimed for setting account settings. '\
72-
'When this method is requested, the account is rebooted.'
73-
74-
return self.greenApi.request('POST',
75-
'{{host}}/waInstance{{idInstance}}'
76-
'/SetSettings/{{apiTokenInstance}}',
77-
requestBody)
105+
return self.api.request(
106+
"GET", "{{host}}/waInstance{{idInstance}}/qr/{{apiTokenInstance}}"
107+
)
108+
109+
def set_profile_picture(self, file: str) -> Response:
110+
"""The method is aimed for setting an account picture."""
111+
112+
file_name = Path(file).name
113+
files = {"file": (file_name, open(file, "rb"), "image/jpeg")}
114+
115+
return self.api.request(
116+
"POST", (
117+
"{{host}}/waInstance{{idInstance}}/"
118+
"SetSettings/{{apiTokenInstance}}"
119+
), files=files
120+
)

0 commit comments

Comments
 (0)