Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ define( "ID_INSTANCE", getenv("ID_INSTANCE" ));
define( "API_TOKEN_INSTANCE", getenv("API_TOKEN_INSTANCE") );
```

### Sending a typing notification

```
$result = $greenApi->serviceMethods->sendTyping('11001234567@c.us', 5000);
```

Example url: [sendTyping.php](https://github.com/green-api/whatsapp-api-client-php/blob/master/examples/sendTyping.php)

### Sending an audio recording notification

```
$result = $greenApi->serviceMethods->sendTyping('11001234567@c.us', 5000, 'recording');
```

Example url: [sendTyping.php](https://github.com/green-api/whatsapp-api-client-php/blob/master/examples/sendTyping.php)

### Sending an image via URL

```
Expand Down Expand Up @@ -120,6 +136,7 @@ This method will be called when an incoming message is received. Next, process m
| Description | Module |
|----------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------|
| Example of sending text | [sendTextMessage.php](https://github.com/green-api/whatsapp-api-client-php/blob/master/examples/sendTextMessage.php) |
| Example of sending typing or audio recording notification | [sendTyping.php](https://github.com/green-api/whatsapp-api-client-php/blob/master/examples/sendTyping.php) |
| Example of sending a picture by URL | [sendPictureByLink.php](https://github.com/green-api/whatsapp-api-client-php/blob/master/examples/sendPictureByLink.php) |
| Example of sending a picture by uploading from the disk | [sendPictureByUpload.php](https://github.com/green-api/whatsapp-api-client-php/blob/master/examples/sendPictureByUpload.php) |
| Example of a group creation and sending a message to the group | [createGroupAndSendMessage.php](https://github.com/green-api/whatsapp-api-client-php/blob/master/examples/createGroupAndSendMessage.php) |
Expand Down Expand Up @@ -179,6 +196,7 @@ This method will be called when an incoming message is received. Next, process m
| `serviceMethods.archiveChat` | The method archives the chat | [ArchiveChat](https://green-api.com/en/docs/api/service/archiveChat/) |
| `serviceMethods.unarchiveChat` | The method unarchives the chat | [UnarchiveChat](https://green-api.com/en/docs/api/service/unarchiveChat/) |
| `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/) |
| `serviceMethods.sendTyping` | The method is designed to send a typing or audio recording notification to a chat | [SendTyping](https://green-api.com/en/docs/api/service/SendTyping/) |
| `webhooks.startReceivingNotifications` | The method is designed to start receiving new notifications | |
| `webhooks.stopReceivingNotifications` | The method is designed to stop receiving new notifications | |
| `statuses.sendTextStatus` | The method is aimed for sending a text status | [SendTextStatus](https://green-api.com/en/docs/api/statuses/SendTextStatus/) |
Expand Down
18 changes: 18 additions & 0 deletions README_RUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ define( "ID_INSTANCE", getenv("ID_INSTANCE" ));
define( "API_TOKEN_INSTANCE", getenv("API_TOKEN_INSTANCE") );
```

### Отправка уведомления о наборе текста

```
$result = $greenApi->serviceMethods->sendTyping('11001234567@c.us', 5000);
```

Ссылка на пример: [sendTyping.php](https://github.com/green-api/whatsapp-api-client-php/blob/master/examples/sendTyping.php)

### Отправка уведомления о записи аудио

```
$result = $greenApi->serviceMethods->sendTyping('11001234567@c.us', 5000, 'recording');
```

Ссылка на пример: [sendTyping.php](https://github.com/green-api/whatsapp-api-client-php/blob/master/examples/sendTyping.php)

### Отправка картинки по URL

```
Expand Down Expand Up @@ -118,6 +134,7 @@ body | тело сообщения (json)
| Описание | Модуль |
|------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------|
| Пример отправки текста | [sendTextMessage.php](https://github.com/green-api/whatsapp-api-client-php/blob/master/examples/sendTextMessage.php) |
| Пример отправки уведомления о наборе текста или записи аудио | [sendTyping.php](https://github.com/green-api/whatsapp-api-client-php/blob/master/examples/sendTyping.php) |
| Пример отправки картинки по URL | [sendPictureByLink.php](https://github.com/green-api/whatsapp-api-client-php/blob/master/examples/sendPictureByLink.php) |
| Пример отправки картинки загрузкой с диска | [sendPictureByUpload.php](https://github.com/green-api/whatsapp-api-client-php/blob/master/examples/sendPictureByUpload.php) |
| Пример создание группы и отправка сообщения в группу | [createGroupAndSendMessage.php](https://github.com/green-api/whatsapp-api-client-php/blob/master/examples/createGroupAndSendMessage.php) |
Expand Down Expand Up @@ -177,6 +194,7 @@ body | тело сообщения (json)
| `serviceMethods.archiveChat` | Метод архивирует чат | [ArchiveChat](https://green-api.com/docs/api/service/archiveChat/) |
| `serviceMethods.unarchiveChat` | Метод разархивирует чат | [UnarchiveChat](https://green-api.com/docs/api/service/unarchiveChat/) |
| `serviceMethods.setDisappearingChat` | Метод предназначен для изменения настроек исчезающих сообщений в чатах | [SetDisappearingChat](https://green-api.com/docs/api/service/SetDisappearingChat/) |
| `serviceMethods.sendTyping` | Метод предназначен для отправки уведомления о наборе текста или записи аудио в чат | [SendTyping](https://green-api.com/docs/api/service/SendTyping/) |
| `webhooks.startReceivingNotifications` | Метод предназначен для старта получения новых уведомлений | |
| `webhooks.stopReceivingNotifications` | Метод предназначен для остановки получения новых уведомлений | |
| `statuses.sendTextStatus` | Метод предназначен для отправки текстового статуса | [SendTextStatus](https://green-api.com/docs/api/statuses/SendTextStatus/) |
Expand Down
17 changes: 17 additions & 0 deletions examples/sendTyping.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
require './vendor/autoload.php';

use GreenApi\RestApi\GreenApiClient;

define( "ID_INSTANCE", "1101712345" );
define( "API_TOKEN_INSTANCE", "d75b3a66374942c5b3c019c698abc2067e151558acbd412345" );

$greenApi = new GreenApiClient( ID_INSTANCE, API_TOKEN_INSTANCE );

$result = $greenApi->serviceMethods->sendTyping(
'11001234567@c.us',
5000,
'recording'
);

print_r( $result );
45 changes: 38 additions & 7 deletions src/tools/Sending.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function sendButtons(
* @return stdClass
* @link https://green-api.com/en/docs/api/sending/SendContact/
*/
public function sendContact( string $chatId, array $contact, string $quotedMessageId = null ): stdClass {
public function sendContact( string $chatId, array $contact, string $quotedMessageId = null, ?int $typingTime = null ): stdClass {

$requestBody = [
'chatId' => $chatId,
Expand All @@ -80,6 +80,10 @@ public function sendContact( string $chatId, array $contact, string $quotedMessa
$requestBody['quotedMessageId'] = $quotedMessageId;
}

if ( $typingTime !== null ) {
$requestBody['typingTime'] = $typingTime;
}

return $this->greenApi->request( 'POST',
'{{host}}/waInstance{{idInstance}}/SendContact/{{apiTokenInstance}}', $requestBody );
}
Expand All @@ -101,7 +105,7 @@ public function sendContact( string $chatId, array $contact, string $quotedMessa
* @link https://green-api.com/en/docs/api/sending/SendFileByUpload/
*/
public function sendFileByUpload(
string $chatId, string $path, string $fileName = null, string $caption = null, string $quotedMessageId = null
string $chatId, string $path, string $fileName = null, string $caption = null, string $quotedMessageId = null, ?int $typingTime = null, ?string $typingType = null
): stdClass {

if ( ! $fileName ) {
Expand All @@ -122,6 +126,14 @@ public function sendFileByUpload(
$requestBody['quotedMessageId'] = $quotedMessageId;
}

if ( $typingTime !== null ) {
$requestBody['typingTime'] = $typingTime;
}

if ( $typingType !== null ) {
$requestBody['typingType'] = $typingType;
}

return $this->greenApi->request( 'POST',
'{{media}}/waInstance{{idInstance}}/SendFileByUpload/{{apiTokenInstance}}', $requestBody, true );
}
Expand All @@ -146,7 +158,7 @@ public function sendFileByUpload(
*/
public function sendFileByUrl(
string $chatId, string $urlFile, string $fileName = null, string $caption = null, string $quotedMessageId = null,
bool $archiveChat = false
bool $archiveChat = false, ?int $typingTime = null, ?string $typingType = null
): stdClass {

if ( ! $fileName ) {
Expand All @@ -171,6 +183,14 @@ public function sendFileByUrl(
$requestBody['archiveChat'] = $archiveChat;
}

if ( $typingTime !== null ) {
$requestBody['typingTime'] = $typingTime;
}

if ( $typingType !== null ) {
$requestBody['typingType'] = $typingType;
}

return $this->greenApi->request( 'POST',
'{{host}}/waInstance{{idInstance}}/SendFileByUrl/{{apiTokenInstance}}', $requestBody );
}
Expand Down Expand Up @@ -271,8 +291,8 @@ public function sendListMessage(
* @link https://green-api.com/en/docs/api/sending/SendLocation/
*/
public function sendLocation(
string $chatId, float $latitude, float $longitude, string $nameLocation = null, string $address = null,
string $quotedMessageId = null
string $chatId, float $latitude, float $longitude, string $nameLocation = null, string $address = null,
string $quotedMessageId = null, ?int $typingTime = null
): stdClass {

$requestBody = [
Expand All @@ -290,6 +310,9 @@ public function sendLocation(
if ( $quotedMessageId ) {
$requestBody['quotedMessageId'] = $quotedMessageId;
}
if ( $typingTime !== null ) {
$requestBody['typingTime'] = $typingTime;
}

return $this->greenApi->request( 'POST',
'{{host}}/waInstance{{idInstance}}/SendLocation/{{apiTokenInstance}}', $requestBody );
Expand All @@ -311,7 +334,7 @@ public function sendLocation(
* @link https://green-api.com/en/docs/api/sending/SendMessage/
*/
public function sendMessage(
string $chatId, string $message, string $quotedMessageId = null, bool $archiveChat = false
string $chatId, string $message, string $quotedMessageId = null, bool $archiveChat = false, ?int $typingTime = null
): stdClass {

$requestBody = [
Expand All @@ -327,6 +350,10 @@ public function sendMessage(
$requestBody['archiveChat'] = $archiveChat;
}

if ( $typingTime !== null ) {
$requestBody['typingTime'] = $typingTime;
}

return $this->greenApi->request( 'POST',
'{{host}}/waInstance{{idInstance}}/SendMessage/{{apiTokenInstance}}', $requestBody );
}
Expand Down Expand Up @@ -387,14 +414,18 @@ public function sendTemplateButtons(
* @return stdClass
* @link https://green-api.com/en/docs/api/sending/ForwardMessages/
*/
public function forwardMessages( string $chatId, string $chatIdFrom, array $messages ): stdClass {
public function forwardMessages( string $chatId, string $chatIdFrom, array $messages, ?int $typingTime = null ): stdClass {

$requestBody = [
'chatId' => $chatId,
'chatIdFrom' => $chatIdFrom,
'messages' => $messages
];

if ( $typingTime !== null ) {
$requestBody['typingTime'] = $typingTime;
}

return $this->greenApi->request( 'POST',
'{{host}}/waInstance{{idInstance}}/ForwardMessages/{{apiTokenInstance}}', $requestBody );
}
Expand Down
28 changes: 28 additions & 0 deletions src/tools/ServiceMethods.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,34 @@ public function archiveChat( string $chatId ): stdClass {
}


/**
* 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.
*
Expand Down