-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathserviceMethods.py
More file actions
168 lines (129 loc) · 4.46 KB
/
serviceMethods.py
File metadata and controls
168 lines (129 loc) · 4.46 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
164
165
166
167
168
from typing import Optional, TYPE_CHECKING
from ..response import Response
if TYPE_CHECKING:
from ..API import GreenApi
class ServiceMethods:
def __init__(self, api: "GreenApi"):
self.api = api
def checkWhatsapp(self, phoneNumber: int) -> Response:
"""
The method checks WhatsApp account availability on a phone
number.
https://green-api.com/en/docs/api/service/CheckWhatsapp/
"""
request_body = locals()
request_body.pop("self")
return self.api.request(
"POST", (
"{{host}}/waInstance{{idInstance}}/"
"checkWhatsapp/{{apiTokenInstance}}"
), request_body
)
def getAvatar(self, chatId: str) -> Response:
"""
The method returns a user or a group chat avatar.
https://green-api.com/en/docs/api/service/GetAvatar/
"""
request_body = locals()
request_body.pop("self")
return self.api.request(
"POST", (
"{{host}}/waInstance{{idInstance}}/"
"getAvatar/{{apiTokenInstance}}"
), request_body
)
def getContacts(self) -> Response:
"""
The method is aimed for getting a list of the current account
contacts.
https://green-api.com/en/docs/api/service/GetContacts/
"""
return self.api.request(
"GET", (
"{{host}}/waInstance{{idInstance}}/"
"getContacts/{{apiTokenInstance}}"
)
)
def getContactInfo(self, chatId: str) -> Response:
"""
The method is aimed for getting information on a contact.
https://green-api.com/en/docs/api/service/GetContactInfo/
"""
request_body = locals()
request_body.pop("self")
return self.api.request(
"POST", (
"{{host}}/waInstance{{idInstance}}/"
"getContactInfo/{{apiTokenInstance}}"
), request_body
)
def deleteMessage(self, chatId: str, idMessage: str) -> Response:
"""
The method deletes a message from a chat.
https://green-api.com/en/docs/api/service/deleteMessage/
"""
request_body = locals()
request_body.pop("self")
return self.api.request(
"POST", (
"{{host}}/waInstance{{idInstance}}/"
"deleteMessage/{{apiTokenInstance}}"
), request_body
)
def editMessage(self, chatId: str, idMessage: str, message: str) -> Response:
"""
The method edits a message in chat.
https://green-api.com/en/docs/api/service/editMessage/
"""
request_body = locals()
request_body.pop("self")
return self.api.request(
"POST", (
"{{host}}/waInstance{{idInstance}}/"
"editMessage/{{apiTokenInstance}}"
), request_body
)
def archiveChat(self, chatId: str) -> Response:
"""
The method archives a chat.
https://green-api.com/en/docs/api/service/archiveChat/
"""
request_body = locals()
request_body.pop("self")
return self.api.request(
"POST", (
"{{host}}/waInstance{{idInstance}}/"
"archiveChat/{{apiTokenInstance}}"
), request_body
)
def unarchiveChat(self, chatId: str) -> Response:
"""
The method unarchives a chat.
https://green-api.com/en/docs/api/service/unarchiveChat/
"""
request_body = locals()
request_body.pop("self")
return self.api.request(
"POST", (
"{{host}}/waInstance{{idInstance}}/"
"unarchiveChat/{{apiTokenInstance}}"
), request_body
)
def setDisappearingChat(
self, chatId: str, ephemeralExpiration: Optional[int] = None
) -> Response:
"""
The method is aimed for changing settings of disappearing
messages in chats.
https://green-api.com/en/docs/api/service/SetDisappearingChat/
"""
request_body = locals()
if ephemeralExpiration is None:
request_body.pop("ephemeralExpiration")
request_body.pop("self")
return self.api.request(
"POST", (
"{{host}}/waInstance{{idInstance}}/"
"setDisappearingChat/{{apiTokenInstance}}"
), request_body
)