-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathServiceMethods.php
More file actions
220 lines (181 loc) · 5.77 KB
/
ServiceMethods.php
File metadata and controls
220 lines (181 loc) · 5.77 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<?php
namespace GreenApi\RestApi\tools;
use GreenApi\RestApi\GreenApiClient;
use stdClass;
class ServiceMethods {
/**
* @param GreenApiClient $greenApi
*/
private $greenApi;
public function __construct( GreenApiClient $greenApi ) {
$this->greenApi = $greenApi;
}
/**
* The method checks WhatsApp account availability on a phone number.
*
* @param int $phoneNumber
*
* @return stdClass
* @link https://green-api.com/en/docs/api/service/CheckWhatsapp/
*/
public function checkWhatsapp( int $phoneNumber ): stdClass {
$requestBody = [
'phoneNumber' => $phoneNumber,
];
return $this->greenApi->request( 'POST',
'{{host}}/waInstance{{idInstance}}/CheckWhatsapp/{{apiTokenInstance}}', $requestBody );
}
/**
* The method returns a user or a group chat avatar.
*
* @param string $chatId
*
* @return stdClass
* @link https://green-api.com/en/docs/api/service/GetAvatar/
*/
public function getAvatar( string $chatId ): stdClass {
$requestBody = [
'chatId' => $chatId,
];
return $this->greenApi->request( 'POST',
'{{host}}/waInstance{{idInstance}}/GetAvatar/{{apiTokenInstance}}', $requestBody );
}
/**
* The method is aimed for getting information on a contact.
*
* @param string $chatId
*
* @return stdClass
* @link https://green-api.com/en/docs/api/service/GetContactInfo/
*/
public function getContactInfo( string $chatId ): stdClass {
$requestBody = [
'chatId' => $chatId,
];
return $this->greenApi->request( 'POST',
'{{host}}/waInstance{{idInstance}}/GetContactInfo/{{apiTokenInstance}}', $requestBody );
}
/**
* The method is aimed for getting a list of the current account contacts. Send contacts of all recipients
* whom the account connected with. Parameter "contact name" "name" takes on a value based on the
* below criteria: If the account is recorded in the phonebook, then we get the name from the book;
* If the account is not recorded in the phonebook, then we get the name from WhatsApp account;
* If the account is not recorded in the phone book and WhatsApp account name is not assigned, then we get an empty
* field.
*
* @return stdClass
* @link https://green-api.com/en/docs/api/service/GetContacts/
*/
public function getContacts(): stdClass {
return $this->greenApi->request( 'GET',
'{{host}}/waInstance{{idInstance}}/GetContacts/{{apiTokenInstance}}' );
}
/**
* The method archives a chat. You can archive chats that have at least one incoming message.
*
* @param string $chatId
*
* @return stdClass
* @link https://green-api.com/en/docs/api/service/ArchiveChat/
*/
public function archiveChat( string $chatId ): stdClass {
$requestBody = [
'chatId' => $chatId,
];
return $this->greenApi->request( 'POST',
'{{host}}/waInstance{{idInstance}}/ArchiveChat/{{apiTokenInstance}}', $requestBody );
}
/**
* The method is intended for sending a typing or audio recording notification to a chat.
*
* @param string $chatId
* @param int|null $typingTime
* @param string|null $typingType
*
* @return stdClass
* @link https://green-api.com/en/docs/api/service/SendTyping/
*/
public function sendTyping( string $chatId, ?int $typingTime = null, ?string $typingType = null ): stdClass {
$requestBody = [
'chatId' => $chatId,
];
if ( $typingTime !== null ) {
$requestBody['typingTime'] = $typingTime;
}
if ( $typingType !== null ) {
$requestBody['typingType'] = $typingType;
}
return $this->greenApi->request( 'POST',
'{{host}}/waInstance{{idInstance}}/sendTyping/{{apiTokenInstance}}', $requestBody );
}
/**
* The method deletes a message from a chat.
*
* @param string $chatId
* @param string $idMessage
*
* @return stdClass
* @link https://green-api.com/en/docs/api/service/DeleteMessage/
*/
public function deleteMessage( string $chatId, string $idMessage, bool $onlySenderDelete = false ): stdClass {
$requestBody = [
'chatId' => $chatId,
'idMessage' => $idMessage,
'onlySenderDelete' => $onlySenderDelete,
];
return $this->greenApi->request( 'POST',
'{{host}}/waInstance{{idInstance}}/DeleteMessage/{{apiTokenInstance}}', $requestBody );
}
/**
* The method edits a message in a chat.
*
* @param string $chatId
* @param string $idMessage
* @param string $message
*
* @return stdClass
* @link https://green-api.com/en/docs/api/service/EditMessage/
*/
public function editMessage( string $chatId, string $idMessage, string $message ): stdClass {
$requestBody = [
'chatId' => $chatId,
'idMessage' => $idMessage,
'message' => $message,
];
return $this->greenApi->request( 'POST',
'{{host}}/waInstance{{idInstance}}/EditMessage/{{apiTokenInstance}}', $requestBody );
}
/**
* The method unarchives a chat.
*
* @param string $chatId
*
* @return stdClass
* @link https://green-api.com/en/docs/api/service/unarchiveChat/
*/
public function unarchiveChat( string $chatId ): stdClass {
$requestBody = [
'chatId' => $chatId,
];
return $this->greenApi->request( 'POST',
'{{host}}/waInstance{{idInstance}}/UnarchiveChat/{{apiTokenInstance}}', $requestBody );
}
/**
* The method is aimed for changing settings of disappearing messages in chats. The standard settings of the
* application are used: 0 (off), 86400 (24 hours), 604800 (7 days), 7776000 (90 days).
*
* @param string $chatId
* @param int $ephemeralExpiration
*
* @return stdClass
* @link https://green-api.com/en/docs/api/service/SetDisappearingChat/
*/
public function setDisappearingChat( string $chatId, int $ephemeralExpiration ): stdClass {
$requestBody = [
'chatId' => $chatId,
'ephemeralExpiration' => $ephemeralExpiration,
];
return $this->greenApi->request( 'POST',
'{{host}}/waInstance{{idInstance}}/SetDisappearingChat/{{apiTokenInstance}}', $requestBody );
}
}