Skip to content

Commit 7957b87

Browse files
authored
Merge pull request #16 from green-api/SW-1320
Updated category `Account`
2 parents 11fbc11 + 8707192 commit 7957b87

File tree

4 files changed

+97
-79
lines changed

4 files changed

+97
-79
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ Example of incoming webhooks receiving | [receiveNotification.py](https://github
141141
| `groups.removeAdmin` | The method deprives the participant of group chat administration rights | [RemoveAdmin](https://green-api.com/en/docs/api/groups/RemoveAdmin/) |
142142
| `groups.setGroupPicture` | The method sets the avatar of the group | [SetGroupPicture](https://green-api.com/en/docs/api/groups/SetGroupPicture/) |
143143
| `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/) |
144-
| `journals.get_chat_history` | The method returns the chat message history | [GetChatHistory](https://green-api.com/en/docs/api/journals/GetChatHistory/) |
145-
| `journals.get_message` | The method returns a chat message | [GetMessage](https://green-api.com/en/docs/api/journals/GetMessage/) |
146-
| `journals.last_incoming_messages` | The method returns the most recent incoming messages of the account | [LastIncomingMessages](https://green-api.com/en/docs/api/journals/LastIncomingMessages/) |
147-
| `journals.last_outgoing_messages` | The method returns the last sent messages of the account | [LastOutgoingMessages](https://green-api.com/en/docs/api/journals/LastOutgoingMessages/) |
144+
| `journals.getChatHistory` | The method returns the chat message history | [GetChatHistory](https://green-api.com/en/docs/api/journals/GetChatHistory/) |
145+
| `journals.getMessage` | The method returns a chat message | [GetMessage](https://green-api.com/en/docs/api/journals/GetMessage/) |
146+
| `journals.lastIncomingMessages` | The method returns the most recent incoming messages of the account | [LastIncomingMessages](https://green-api.com/en/docs/api/journals/LastIncomingMessages/) |
147+
| `journals.lastOutgoingMessages` | The method returns the last sent messages of the account | [LastOutgoingMessages](https://green-api.com/en/docs/api/journals/LastOutgoingMessages/) |
148148
| `queues.showMessagesQueue` | The method is designed to get the list of messages that are in the queue to be sent | [ShowMessagesQueue](https://green-api.com/en/docs/api/queues/ShowMessagesQueue/) |
149149
| `queues.clearMessagesQueue` | The method is designed to clear the queue of messages to be sent | [ClearMessagesQueue](https://green-api.com/en/docs/api/queues/ClearMessagesQueue/) |
150150
| `marking.readChat` | The method is designed to mark chat messages as read | [ReadChat](https://green-api.com/en/docs/api/marks/ReadChat/) |

README_RUS.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ body | тело сообщения (json)
136136
| `groups.removeAdmin` | Метод лишает участника прав администрирования группового чата | [RemoveAdmin](https://green-api.com/docs/api/groups/RemoveAdmin/) |
137137
| `groups.setGroupPicture` | Метод устанавливает аватар группы | [SetGroupPicture](https://green-api.com/docs/api/groups/SetGroupPicture/) |
138138
| `groups.leaveGroup` | Метод производит выход пользователя текущего аккаунта из группового чата | [LeaveGroup](https://green-api.com/docs/api/groups/LeaveGroup/) |
139-
| `journals.get_chat_history` | Метод возвращает историю сообщений чата | [GetChatHistory](https://green-api.com/docs/api/journals/GetChatHistory/) |
140-
| `journals.get_message` | Метод возвращает сообщение чата | [GetMessage](https://green-api.com/docs/api/journals/GetMessage/) |
141-
| `journals.last_incoming_messages` | Метод возвращает крайние входящие сообщения аккаунта | [LastIncomingMessages](https://green-api.com/docs/api/journals/LastIncomingMessages/) |
142-
| `journals.last_outgoing_messages` | Метод возвращает крайние отправленные сообщения аккаунта | [LastOutgoingMessages](https://green-api.com/docs/api/journals/LastOutgoingMessages/) |
139+
| `journals.getChatHistory` | Метод возвращает историю сообщений чата | [GetChatHistory](https://green-api.com/docs/api/journals/GetChatHistory/) |
140+
| `journals.getMessage` | Метод возвращает сообщение чата | [GetMessage](https://green-api.com/docs/api/journals/GetMessage/) |
141+
| `journals.lastIncomingMessages` | Метод возвращает крайние входящие сообщения аккаунта | [LastIncomingMessages](https://green-api.com/docs/api/journals/LastIncomingMessages/) |
142+
| `journals.lastOutgoingMessages` | Метод возвращает крайние отправленные сообщения аккаунта | [LastOutgoingMessages](https://green-api.com/docs/api/journals/LastOutgoingMessages/) |
143143
| `queues.showMessagesQueue` | Метод предназначен для получения списка сообщений, находящихся в очереди на отправку | [ShowMessagesQueue](https://green-api.com/docs/api/queues/ShowMessagesQueue/) |
144144
| `queues.clearMessagesQueue` | Метод предназначен для очистки очереди сообщений на отправку | [ClearMessagesQueue](https://green-api.com/docs/api/queues/ClearMessagesQueue/) |
145145
| `marking.readChat` | Метод предназначен для отметки сообщений в чате прочитанными | [ReadChat](https://green-api.com/docs/api/marks/ReadChat/) |
Lines changed: 83 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,95 @@
1-
import os.path
2-
from whatsapp_api_client_python.response import Response
1+
from pathlib import Path
2+
from typing import Dict, TYPE_CHECKING, Union
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-
11+
def __init__(self, api: "GreenApi"):
12+
self.api = api
13+
914
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-
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 setSettings(self, requestBody: Dict[str, Union[int, str]]) -> Response:
27+
"""The method is aimed for setting account settings."""
28+
29+
return self.api.request(
30+
"POST", (
31+
"{{host}}/waInstance{{idInstance}}/"
32+
"setSettings/{{apiTokenInstance}}"
33+
), requestBody
34+
)
35+
1736
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}}')
37+
"""The method is aimed for getting the account state."""
38+
39+
return self.api.request(
40+
"GET", (
41+
"{{host}}/waInstance{{idInstance}}/"
42+
"getStateInstance/{{apiTokenInstance}}"
43+
)
44+
)
2345

2446
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}}')
47+
"""
48+
The method is aimed for getting the status of the account
49+
instance socket connection with WhatsApp.
50+
"""
51+
52+
return self.api.request(
53+
"GET", (
54+
"{{host}}/waInstance{{idInstance}}/"
55+
"getStatusInstance/{{apiTokenInstance}}"
56+
)
57+
)
58+
59+
def reboot(self) -> Response:
60+
"""The method is aimed for rebooting an account."""
61+
62+
return self.api.request(
63+
"GET", (
64+
"{{host}}/waInstance{{idInstance}}/reboot/{{apiTokenInstance}}"
65+
)
66+
)
3167

3268
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}}')
69+
"""The method is aimed for logging out an account."""
70+
71+
return self.api.request(
72+
"GET", (
73+
"{{host}}/waInstance{{idInstance}}/logout/{{apiTokenInstance}}"
74+
)
75+
)
3876

3977
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}}')
78+
"""The method is aimed for getting QR code."""
4879

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)
80+
return self.api.request(
81+
"GET", "{{host}}/waInstance{{idInstance}}/qr/{{apiTokenInstance}}"
82+
)
83+
84+
def setProfilePicture(self, path: str) -> Response:
85+
"""The method is aimed for setting an account picture."""
86+
87+
file_name = Path(path).name
88+
files = {"file": (file_name, open(path, "rb"), "image/jpeg")}
89+
90+
return self.api.request(
91+
"POST", (
92+
"{{host}}/waInstance{{idInstance}}/"
93+
"setProfilePicture/{{apiTokenInstance}}"
94+
), files=files
95+
)

whatsapp_api_client_python/tools/journals.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Journals:
1010
def __init__(self, api: "GreenApi"):
1111
self.api = api
1212

13-
def get_chat_history(
13+
def getChatHistory(
1414
self, chatId: str, count: Optional[int] = None
1515
) -> Response:
1616
"""The method returns the chat message history."""
@@ -23,11 +23,11 @@ def get_chat_history(
2323
return self.api.request(
2424
"POST", (
2525
"{{host}}/waInstance{{idInstance}}/"
26-
"GetChatHistory/{{apiTokenInstance}}"
26+
"getChatHistory/{{apiTokenInstance}}"
2727
), request_body
2828
)
2929

30-
def get_message(self, chatId: str, idMessage: str) -> Response:
30+
def getMessage(self, chatId: str, idMessage: str) -> Response:
3131
"""The method returns the chat message."""
3232

3333
request_body = locals()
@@ -40,7 +40,7 @@ def get_message(self, chatId: str, idMessage: str) -> Response:
4040
), request_body
4141
)
4242

43-
def last_incoming_messages(
43+
def lastIncomingMessages(
4444
self, minutes: Optional[int] = None
4545
) -> Response:
4646
"""
@@ -58,7 +58,7 @@ def last_incoming_messages(
5858
), request_body
5959
)
6060

61-
def last_outgoing_messages(
61+
def lastOutgoingMessages(
6262
self, minutes: Optional[int] = None
6363
) -> Response:
6464
"""
@@ -72,6 +72,6 @@ def last_outgoing_messages(
7272
return self.api.request(
7373
"GET", (
7474
"{{host}}/waInstance{{idInstance}}/"
75-
"LastOutgoingMessages/{{apiTokenInstance}}"
75+
"lastOutgoingMessages/{{apiTokenInstance}}"
7676
), request_body
7777
)

0 commit comments

Comments
 (0)