Skip to content

Commit

Permalink
Add templates interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Neur0toxine authored Jun 25, 2024
2 parents a05cf2c + 33e816c commit 1fc8ccd
Show file tree
Hide file tree
Showing 6 changed files with 765 additions and 3 deletions.
49 changes: 46 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,16 @@
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\ModelInterface;
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 +462,47 @@ public function messageDelete(string $request)
return $adapter->getResponseModel($response);
}


/**
* Returns templates list
*
* @return Template[]
* @throws \Exception
*/
public function templates(): array
{
$response = $this->client->makeRequest(
'/templates',
HttpClient::METHOD_GET
);

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

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

/**
* Send a template message
*
* @param string $templateId
* @param Model\Request\TemplateSendRequest $request Request parameters
*
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
* @throws \Exception
*/
public function templateSend(string $templateId, Model\Request\TemplateSendRequest $request): ModelInterface
{
$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 1fc8ccd

Please sign in to comment.