-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaccount.py
More file actions
163 lines (124 loc) · 4.34 KB
/
account.py
File metadata and controls
163 lines (124 loc) · 4.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
from pathlib import Path
from typing import Dict, TYPE_CHECKING, Union
from ..response import Response
if TYPE_CHECKING:
from ..API import GreenApi
class Account:
def __init__(self, api: "GreenApi"):
self.api = api
def getSettings(self) -> Response:
"""
The method is aimed for getting the current account settings.
https://green-api.com/v3/docs/api/account/GetSettings/
"""
return self.api.request(
"GET", (
"{{host}}/waInstance{{idInstance}}/"
"getSettings/{{apiTokenInstance}}"
)
)
def getAccountSettings(self) -> Response:
"""
The method is aimed to get information about the MAX
account.
https://green-api.com/v3/docs/api/account/GetAccountSettings/
"""
return self.api.request(
"GET", (
"{{host}}/waInstance{{idInstance}}/"
"getAccountSettings/{{apiTokenInstance}}"
)
)
def setSettings(self, requestBody: Dict[str, Union[int, str]]) -> Response:
"""
The method is aimed for setting account settings.
https://green-api.com/v3/docs/api/account/SetSettings/
"""
return self.api.request(
"POST", (
"{{host}}/waInstance{{idInstance}}/"
"setSettings/{{apiTokenInstance}}"
), requestBody
)
def getStateInstance(self) -> Response:
"""
The method is aimed for getting the account state.
https://green-api.com/v3/docs/api/account/GetStateInstance/
"""
return self.api.request(
"GET", (
"{{host}}/waInstance{{idInstance}}/"
"getStateInstance/{{apiTokenInstance}}"
)
)
def reboot(self) -> Response:
"""
The method is aimed for rebooting an account.
https://green-api.com/v3/docs/api/account/Reboot/
"""
return self.api.request(
"GET", (
"{{host}}/waInstance{{idInstance}}/reboot/{{apiTokenInstance}}"
)
)
def logout(self) -> Response:
"""
The method is aimed for logging out an account.
https://green-api.com/v3/docs/api/account/Logout/
"""
return self.api.request(
"GET", (
"{{host}}/waInstance{{idInstance}}/logout/{{apiTokenInstance}}"
)
)
def qr(self) -> Response:
"""
The method is aimed for getting QR code.
https://green-api.com/en/docs/api/account/QR/
"""
return self.api.request(
"GET", (
"{{host}}/waInstance{{idInstance}}/qr/{{apiTokenInstance}}"
)
)
def setProfilePicture(self, path: str) -> Response:
"""
The method is aimed for setting an account picture.
https://green-api.com/v3/docs/api/account/SetProfilePicture/
"""
file_name = Path(path).name
files = {"file": (file_name, open(path, "rb"), "image/jpeg")}
return self.api.request(
"POST", (
"{{host}}/waInstance{{idInstance}}/"
"setProfilePicture/{{apiTokenInstance}}"
), files=files
)
def startAuthorization(self, phoneNumber: int) -> Response:
"""
The method is deprecated. Please use QR.
The method is designed to receive SMS for instance authorization.
https://green-api.com/v3/docs/api/account/StartAuthorization/
"""
request_body = locals()
request_body.pop("self")
return self.api.request(
"POST", (
"{{host}}/waInstance{{idInstance}}/"
"startAuthorization/{{apiTokenInstance}}"
), request_body
)
def sendAuthorizationCode(self, code: str) -> Response:
"""
The method is deprecated. Please use QR.
The method is designed to authorize an instance by SMS.
https://green-api.com/v3/docs/api/account/SendAuthorizationCode/
"""
request_body = locals()
request_body.pop("self")
return self.api.request(
"POST", (
"{{host}}/waInstance{{idInstance}}/"
"sendAuthorizationCode/{{apiTokenInstance}}"
), request_body
)