Skip to content

Commit

Permalink
Add templates interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Chupocabra committed Jun 24, 2024
1 parent a05cf2c commit 8a20b86
Show file tree
Hide file tree
Showing 6 changed files with 755 additions and 3 deletions.
39 changes: 36 additions & 3 deletions src/Bot/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
namespace RetailCrm\Mg\Bot;

use Psr\Http\Message\ResponseInterface;
use RetailCrm\Common\Url;
use RetailCrm\Common\Serializer;
use RetailCrm\Mg\Bot\Model\ModelAdapter;
use RetailCrm\Common\Url;
use RetailCrm\Mg\Bot\Model\Entity\Bot;
use RetailCrm\Mg\Bot\Model\Entity\Channel\Channel;
use RetailCrm\Mg\Bot\Model\Entity\Chat\Chat;
Expand All @@ -22,13 +21,15 @@
use RetailCrm\Mg\Bot\Model\Entity\Customer;
use RetailCrm\Mg\Bot\Model\Entity\Dialog;
use RetailCrm\Mg\Bot\Model\Entity\Message\Message;
use RetailCrm\Mg\Bot\Model\Entity\Template\Template;
use RetailCrm\Mg\Bot\Model\Entity\User;
use RetailCrm\Mg\Bot\Model\ModelAdapter;
use RetailCrm\Mg\Bot\Model\Request\UploadFileByUrlRequest;
use RetailCrm\Mg\Bot\Model\Response\AssignResponse;
use RetailCrm\Mg\Bot\Model\Response\UnassignResponse;
use RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse;
use RetailCrm\Mg\Bot\Model\Response\FullFileResponse;
use RetailCrm\Mg\Bot\Model\Response\MessageSendResponse;
use RetailCrm\Mg\Bot\Model\Response\UnassignResponse;
use RetailCrm\Mg\Bot\Model\Response\UploadFileResponse;

/**
Expand Down Expand Up @@ -460,6 +461,38 @@ public function messageDelete(string $request)
return $adapter->getResponseModel($response);
}


/**
* Returns templates list
*
* @return array
* @throws \Exception
*/
public function templates()

Check failure on line 471 in src/Bot/Client.php

View workflow job for this annotation

GitHub Actions / test (8.0)

Method RetailCrm\Mg\Bot\Client::templates() return type has no value type specified in iterable type array.

Check failure on line 471 in src/Bot/Client.php

View workflow job for this annotation

GitHub Actions / test (8.1)

Method RetailCrm\Mg\Bot\Client::templates() return type has no value type specified in iterable type array.
{
$response = $this->client->makeRequest(
'/templates',
HttpClient::METHOD_GET
);

$adapter = new ModelAdapter(Template::class);

return $adapter->getResponseList($response);
}

public function templateSend(string $templateId, Model\Request\TemplateSendRequest $request)

Check failure on line 483 in src/Bot/Client.php

View workflow job for this annotation

GitHub Actions / test (8.0)

Method RetailCrm\Mg\Bot\Client::templateSend() has no return typehint specified.

Check failure on line 483 in src/Bot/Client.php

View workflow job for this annotation

GitHub Actions / test (8.1)

Method RetailCrm\Mg\Bot\Client::templateSend() has no return typehint specified.
{
$response = $this->client->makeRequest(
sprintf('/templates/%d/send', $templateId),
HttpClient::METHOD_POST,
$request
);

$adapter = new ModelAdapter(MessageSendResponse::class);

return $adapter->getResponseModel($response);
}

/**
* Returns filtered users list
*
Expand Down
Loading

0 comments on commit 8a20b86

Please sign in to comment.