Skip to content

Commit c51a1a8

Browse files
authored
Merge pull request #17 from green-api/SW-5093
SW-5093: Need to add support for sending and receiving status methods to PHP SDK
2 parents 8c135b6 + 777b10f commit c51a1a8

5 files changed

Lines changed: 262 additions & 7 deletions

File tree

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ This method will be called when an incoming message is received. Next, process m
136136
| `account.reboot` | The method is designed to restart the account | [Reboot](https://green-api.com/en/docs/api/account/Reboot/) |
137137
| `account.logout` | The method is designed to unlogin the account | [Logout](https://green-api.com/en/docs/api/account/Logout/) |
138138
| `account.qr` | The method is designed to get a QR code | [QR](https://green-api.com/en/docs/api/account/QR/) |
139-
| `account.getAuthorizationCode` | The method is designed to authorize an instance by phone number | [GetAuthorizationCode](https://green-api.com/en/docs/api/account/GetAuthorizationCode/) |
139+
| `account.getAuthorizationCode` | The method is designed to authorize an instance by phone number | [GetAuthorizationCode](https://green-api.com/en/docs/api/account/GetAuthorizationCode/) |
140140
| `account.setProfilePicture` | The method is designed to set the avatar of the account | [SetProfilePicture](https://green-api.com/en/docs/api/account/SetProfilePicture/) |
141141
| `groups.createGroup` | The method is designed to create a group chat | [CreateGroup](https://green-api.com/en/docs/api/groups/CreateGroup/) |
142142
| `groups.updateGroupName` | The method changes the name of the group chat | [UpdateGroupName](https://green-api.com/en/docs/api/groups/UpdateGroupName/) |
@@ -170,13 +170,19 @@ This method will be called when an incoming message is received. Next, process m
170170
| `serviceMethods.getAvatar` | The method returns the avatar of the correspondent or group chat | [GetAvatar](https://green-api.com/en/docs/api/service/GetAvatar/) |
171171
| `serviceMethods.getContacts` | The method is designed to get a list of contacts of the current account | [GetContacts](https://green-api.com/en/docs/api/service/GetContacts/) |
172172
| `serviceMethods.getContactInfo` | The method is designed to obtain information about the contact | [GetContactInfo](https://green-api.com/en/docs/api/service/GetContactInfo/) |
173-
| `serviceMethods.editMessage` | The method edits a message in a chat | [EditMessage](https://green-api.com/en/docs/api/service/editMessage/) |
173+
| `serviceMethods.editMessage` | The method edits a message in a chat | [EditMessage](https://green-api.com/en/docs/api/service/editMessage/) |
174174
| `serviceMethods.deleteMessage` | The method deletes the message from chat | [DeleteMessage](https://green-api.com/en/docs/api/service/deleteMessage/) |
175175
| `serviceMethods.archiveChat` | The method archives the chat | [ArchiveChat](https://green-api.com/en/docs/api/service/archiveChat/) |
176176
| `serviceMethods.unarchiveChat` | The method unarchives the chat | [UnarchiveChat](https://green-api.com/en/docs/api/service/unarchiveChat/) |
177177
| `serviceMethods.setDisappearingChat` | The method is designed to change the settings of disappearing messages in chats | [SetDisappearingChat](https://green-api.com/en/docs/api/service/SetDisappearingChat/) |
178-
| `webhooks.startReceivingNotifications` | The method is designed to start receiving new notifications | |
179-
| `webhooks.stopReceivingNotifications` | The method is designed to stop receiving new notifications | |
178+
| `webhooks.startReceivingNotifications` | The method is designed to start receiving new notifications | |
179+
| `webhooks.stopReceivingNotifications` | The method is designed to stop receiving new notifications | |
180+
| `statuses.sendTextStatus` | The method is aimed for sending a text status | [SendTextStatus](https://green-api.com/en/docs/api/statuses/SendTextStatus/) |
181+
| `statuses.sendVoiceStatus` | The method is aimed for sending a voice status | [SendVoiceStatus](https://green-api.com/en/docs/api/statuses/SendVoiceStatus/) |
182+
| `statuses.sendMediaStatus` | The method is aimed for sending a pictures or video status | [SendMediaStatus](https://green-api.com/en/docs/api/statuses/SendMediaStatus/) |
183+
| `statuses.getIncomingStatuses` | The method returns the incoming status messages of the instance | [GetIncomingStatuses](https://green-api.com/en/docs/api/statuses/GetIncomingStatuses/) |
184+
| `statuses.getOutgoingStatuses` | The method returns the outgoing statuses of the account | [GetOutgoingStatuses](https://green-api.com/en/docs/api/statuses/GetOutgoingStatuses/) |
185+
| `statuses.getStatusStatistic` | The method returns an array of recipients marked sent/delivered/read for a given status | [GetStatusStatistic](https://green-api.com/en/docs/api/statuses/GetStatusStatistic/) |
180186

181187
## Service methods documentation
182188

README_RUS.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,19 @@ body | тело сообщения (json)
168168
| `serviceMethods.getAvatar` | Метод возвращает аватар корреспондента или группового чата | [GetAvatar](https://green-api.com/docs/api/service/GetAvatar/) |
169169
| `serviceMethods.getContacts` | Метод предназначен для получения списка контактов текущего аккаунта | [GetContacts](https://green-api.com/docs/api/service/GetContacts/) |
170170
| `serviceMethods.getContactInfo` | Метод предназначен для получения информации о контакте | [GetContactInfo](https://green-api.com/docs/api/service/GetContactInfo/) |
171-
| `serviceMethods.editMessage` | Метод редактирует сообщение в чате | [EditMessage](https://green-api.com/docs/api/service/editMessage/) |
171+
| `serviceMethods.editMessage` | Метод редактирует сообщение в чате | [EditMessage](https://green-api.com/docs/api/service/editMessage/) |
172172
| `serviceMethods.deleteMessage` | Метод удаляет сообщение из чата | [DeleteMessage](https://green-api.com/docs/api/service/deleteMessage/) |
173173
| `serviceMethods.archiveChat` | Метод архивирует чат | [ArchiveChat](https://green-api.com/docs/api/service/archiveChat/) |
174174
| `serviceMethods.unarchiveChat` | Метод разархивирует чат | [UnarchiveChat](https://green-api.com/docs/api/service/unarchiveChat/) |
175175
| `serviceMethods.setDisappearingChat` | Метод предназначен для изменения настроек исчезающих сообщений в чатах | [SetDisappearingChat](https://green-api.com/docs/api/service/SetDisappearingChat/) |
176-
| `webhooks.startReceivingNotifications` | Метод предназначен для старта получения новых уведомлений | |
177-
| `webhooks.stopReceivingNotifications` | Метод предназначен для остановки получения новых уведомлений | |
176+
| `webhooks.startReceivingNotifications` | Метод предназначен для старта получения новых уведомлений | |
177+
| `webhooks.stopReceivingNotifications` | Метод предназначен для остановки получения новых уведомлений | |
178+
| `statuses.sendTextStatus` | Метод предназначен для отправки текстового статуса | [SendTextStatus](https://green-api.com/docs/api/statuses/SendTextStatus/) |
179+
| `statuses.sendVoiceStatus` | Метод предназначен для отправки голосового статуса | [SendVoiceStatus](https://green-api.com/docs/api/statuses/SendVoiceStatus/) |
180+
| `statuses.sendMediaStatus` | Метод предназначен для отправки медиа-файлов | [SendMediaStatus](https://green-api.com/docs/api/statuses/SendMediaStatus/) |
181+
| `statuses.getIncomingStatuses` | Метод возвращает крайние входящие статусы аккаунта | [GetIncomingStatuses](https://green-api.com/docs/api/statuses/GetIncomingStatuses/) |
182+
| `statuses.getOutgoingStatuses` | Метод возвращает крайние отправленные статусы аккаунта | [GetOutgoingStatuses](https://green-api.com/docs/api/statuses/GetOutgoingStatuses/) |
183+
| `statuses.getStatusStatistic` | Метод возвращает массив получателей со статусами, отмеченных как отправлено/доставлено/прочитано, для данного статуса | [GetStatusStatistic](https://green-api.com/docs/api/statuses/GetStatusStatistic/) |
178184

179185
## Документация по методам сервиса
180186

examples/statusesExample.php

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
require './vendor/autoload.php';
3+
4+
use GreenApi\RestApi\GreenApiClient;
5+
6+
define( "ID_INSTANCE", "1101712345" );
7+
define( "API_TOKEN_INSTANCE", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345" );
8+
9+
// Initialize the GREEN-API client
10+
$greenApi = new GreenApiClient(ID_INSTANCE, API_TOKEN_INSTANCE);
11+
12+
// Example 1: Send a text status
13+
$textStatusResult = $greenApi->statuses->sendTextStatus(
14+
"Hello from Green-API!", // message
15+
"#FF0000", // background color (red)
16+
"SERIF", // font
17+
["70000001234@c.us"] // participants
18+
);
19+
print_r("Text Status Result:\n");
20+
print_r("Status Code: " . $textStatusResult->code . "\n");
21+
print_r($textStatusResult->data);
22+
echo "\n\n";
23+
sleep(1); // 1 second delay
24+
25+
// Example 2: Send a voice status
26+
$voiceStatusResult = $greenApi->statuses->sendVoiceStatus(
27+
"https://example.com/voice.mp3", // URL to voice file
28+
"voice_message.mp3", // file name
29+
"#00FF00", // background color (green)
30+
["70000001234@c.us"] // participants
31+
);
32+
print_r("Voice Status Result:\n");
33+
print_r("Status Code: " . $voiceStatusResult->code . "\n");
34+
print_r($voiceStatusResult->data);
35+
echo "\n\n";
36+
sleep(1); // 1 second delay
37+
38+
// Example 3: Send a media status (photo or video)
39+
$mediaStatusResult = $greenApi->statuses->sendMediaStatus(
40+
"https://example.com/image.jpg", // URL to media file
41+
"sunset.jpg", // file name
42+
"Beautiful sunset!", // caption
43+
["70000001234@c.us"] // participants
44+
);
45+
print_r("Media Status Result:\n");
46+
print_r("Status Code: " . $mediaStatusResult->code . "\n");
47+
print_r($mediaStatusResult->data);
48+
echo "\n\n";
49+
sleep(1); // 1 second delay
50+
51+
// Example 4: Get incoming statuses (last 24 hours by default)
52+
$incomingStatuses = $greenApi->statuses->getIncomingStatuses();
53+
print_r("Incoming Statuses (24h):\n");
54+
print_r("Status Code: " . $incomingStatuses->code . "\n");
55+
56+
print_r($incomingStatuses->data);
57+
echo "\n\n";
58+
sleep(1); // 1 second delay
59+
60+
// Example 5: Get incoming statuses for specific time period (60 minutes)
61+
$incomingStatuses60min = $greenApi->statuses->getIncomingStatuses(60);
62+
print_r("Incoming Statuses (60 minutes):\n");
63+
print_r("Status Code: " . $incomingStatuses60min->code . "\n");
64+
print_r($incomingStatuses60min->data);
65+
echo "\n\n";
66+
sleep(1); // 1 second delay
67+
68+
// Example 6: Get outgoing statuses (last 24 hours by default)
69+
$outgoingStatuses = $greenApi->statuses->getOutgoingStatuses();
70+
print_r("Outgoing Statuses (24h):\n");
71+
print_r("Status Code: " . $outgoingStatuses->code . "\n");
72+
print_r($outgoingStatuses->data);
73+
echo "\n\n";
74+
sleep(1); // 1 second delay
75+
76+
// Example 7: Get outgoing statuses for specific time period (120 minutes)
77+
$outgoingStatuses120min = $greenApi->statuses->getOutgoingStatuses(120);
78+
print_r("Outgoing Statuses (120 minutes):\n");
79+
print_r("Status Code: " . $outgoingStatuses120min->code . "\n");
80+
print_r($outgoingStatuses120min->data);
81+
echo "\n\n";
82+
sleep(1); // 1 second delay
83+
84+
// Example 8: Get status statistics for a specific message
85+
// Note: Replace with an actual message ID from your status
86+
$statusStatistics = $greenApi->statuses->getStatusStatistic("3EB0C767D097B7C7C81");
87+
print_r("Status Statistics:\n");
88+
print_r("Status Code: " . $statusStatistics->code . "\n");
89+
print_r($statusStatistics->data);
90+
echo "\n\n";

src/GreenApiClient.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use GreenApi\RestApi\tools\Sending;
1919
use GreenApi\RestApi\tools\ServiceMethods;
2020
use GreenApi\RestApi\tools\Webhooks;
21+
use GreenApi\RestApi\tools\Statuses;
2122
use stdClass;
2223

2324
class GreenApiClient {
@@ -62,6 +63,10 @@ class GreenApiClient {
6263
* @var Webhooks
6364
*/
6465
public $webhooks;
66+
/**
67+
* @var Statuses
68+
*/
69+
public $statuses;
6570

6671
public function __construct( $idInstance, $apiTokenInstance, $host = "https://api.green-api.com", $media = "https://media.green-api.com" ) {
6772

@@ -79,6 +84,7 @@ public function __construct( $idInstance, $apiTokenInstance, $host = "https://ap
7984
$this->sending = new Sending( $this );
8085
$this->serviceMethods = new ServiceMethods( $this );
8186
$this->webhooks = new Webhooks( $this );
87+
$this->statuses = new Statuses( $this );
8288
}
8389

8490
/**

0 commit comments

Comments
 (0)