1
0
Fork 0
mirror of synced 2025-04-01 12:16:14 +03:00

Merge pull request #2 from Neur0toxine/master

Response models, unit-tests, Travis, fix for packages versions for PHP 7.0
This commit is contained in:
Alex Lushpai 2019-06-28 09:37:13 +03:00 committed by GitHub
commit 226b61845b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
70 changed files with 7577 additions and 1521 deletions

View file

@ -1,3 +1,3 @@
MG_BOT_URL=""
MG_BOT_URL="https://mg-test.retailcrm.pro/"
MG_BOT_KEY=""
MG_BOT_DBG=""

13
.gitignore vendored
View file

@ -61,6 +61,7 @@ cmake-build-release/
# IntelliJ
out/
.idea/
# mpeltonen/sbt-idea plugin
.idea_modules/
@ -184,3 +185,15 @@ $RECYCLE.BIN/
# Windows shortcuts
*.lnk
/.php_cs.cache
# phpDocumentor
phpDocumentor.phar
phpDocumentor.phar.pubkey
mg-bot-api-client-php.pages/*
build/*
# Test report
test-report.xml
# GraphViz Dot
dot/*

View file

@ -8,9 +8,10 @@ php:
- '7.0'
- '7.1'
- '7.2'
- '7.3'
before_script:
- flags="-o"
- composer install $flags
script: make test
script: make travis

View file

@ -1,6 +1,7 @@
ROOT_DIR=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
SRC_DIR=$(ROOT_DIR)/src
BIN_DIR=$(ROOT_DIR)/bin
export PATH := $(PATH):$(ROOT_DIR)/dot
deps:
@echo "==> Installing dependencies"
@ -10,6 +11,10 @@ deps:
test:
@echo "==> Running tests"
@cd $(ROOT_DIR)
ifeq ($(wildcard .env), )
@echo "==> Creating .env file for testing purposes..."
@cp .env.dist .env
endif
@php -d memory_limit=-1 $(BIN_DIR)/phpunit -c phpunit.xml.dist --log-junit $(ROOT_DIR)/test-report.xml
@echo "==> Testing complete"
@ -17,3 +22,6 @@ stan:
@echo "==> Running analysis"
@php $(BIN_DIR)/phpstan analyse -l 4 -c $(ROOT_DIR)/phpstan.neon $(SRC_DIR)
@echo "==> Analysis complete"
travis: test stan
@echo "==> Completed"

View file

@ -1,32 +0,0 @@
extensions:
- php
source:
- src
exclude:
- tests/
- vendor/
- bin/
- docs/
charset:
- auto
- UTF-8
- Windows-1251
title: retailCRM PHP MG Bot API client
templateTheme: bootstrap
groups: auto
accessLevels:
- public
- protected
internal: true
php: false
tree: true
deprecated: true
todo: true
destination: ../mg-bot-api-client-php.pages/
download: false

View file

@ -15,18 +15,37 @@
"php": ">=7.0",
"ext-curl": "*",
"ext-json": "*",
"jms/serializer": "1.13.*",
"symfony/validator": "^4.2",
"doctrine/annotations": "^1.6",
"doctrine/cache": "^1.8"
"jms/serializer": "1.14.*",
"symfony/validator": "3.*",
"doctrine/annotations": "1.4.*",
"doctrine/cache": "1.6.*",
"guzzlehttp/guzzle": "6.*",
"doctrine/instantiator": "1.0.*",
"symfony/translation": "3.*",
"symfony/dependency-injection": "3.*",
"symfony/config": "3.*",
"symfony/finder": "3.4.*",
"symfony/filesystem": "3.*"
},
"require-dev": {
"phpunit/phpunit": "6.5.*",
"phpmd/phpmd": "2.6.*",
"phpstan/phpstan": "0.9.*",
"phpmd/phpmd": "2.*",
"squizlabs/php_codesniffer": "3.4.*",
"symfony/dotenv": "^4.2",
"friendsofphp/php-cs-fixer": "^2.14"
"symfony/dotenv": "3.*",
"friendsofphp/php-cs-fixer": "2.*",
"phpunit/phpunit": "6.*",
"nette/bootstrap": "2.*",
"nette/neon": "2.*",
"nette/php-generator": "3.0.*",
"phpstan/phpstan": "0.9.*",
"ocramius/package-versions": "1.2.*",
"nette/finder": "2.4.*",
"symfony/console": "3.*",
"symfony/debug": "3.*",
"symfony/event-dispatcher": "3.*",
"symfony/options-resolver": "3.4.*",
"symfony/process": "3.4.*",
"symfony/stopwatch": "3.4.*",
"myclabs/deep-copy": "1.6.*"
},
"support": {
"email": "support@retailcrm.ru"

1560
composer.lock generated

File diff suppressed because it is too large Load diff

View file

@ -13,13 +13,14 @@
namespace RetailCrm\Mg\Bot;
use RetailCrm\Common\Exception\CurlException;
use Psr\Http\Message\ResponseInterface;
use RetailCrm\Common\Exception\InvalidJsonException;
use RetailCrm\Common\Url;
use RetailCrm\Common\Serializer;
use RetailCrm\Mg\Bot\Model;
use Exception;
use InvalidArgumentException;
use RetailCrm\Mg\Bot\Model\Request\UploadFileByUrlRequest;
use RetailCrm\Mg\Bot\Model\Response\FullFileResponse;
use RetailCrm\Mg\Bot\Model\Response\ListResponse;
use RetailCrm\Mg\Bot\Model\Response\UploadFileResponse;
/**
* PHP version 7.0
@ -33,313 +34,500 @@ use InvalidArgumentException;
*/
class Client
{
/**
* @internal
*/
const VERSION = 'v1';
/**
* @internal
*/
const ERROR_ONLY_RESPONSE = 'ErrorOnlyResponse';
/**
* @var HttpClient
*/
protected $client;
/**
* Init
*
* @param string $url api url
* @param string $token api key
* @param bool $debug debug flag
* @param string $url MG API URL
* @param string $token MG API Key
* @param bool $debug Enable or disable debug mode - will log all requests to STDOUT (default: false)
* @param \GuzzleHttp\HandlerStack $handler GuzzleHttp::HandlerStack instance (default: null)
*/
public function __construct($url, $token, $debug = false)
public function __construct($url, $token, $debug = false, $handler = null)
{
$url = sprintf("%sapi/bot/%s", Url::normalizeUrl($url), self::VERSION);
$this->client = new Request($url, $token, $debug);
$this->client = new HttpClient($url, $token, $debug ? STDOUT : null, $handler);
}
/**
* @param string $path
* @param string $method
* @param object|null $request Request parameters
* @param string $responseType
* @param bool $arrayOfObjects
*
* @return object|null
* @throws \Exception
*/
private function submitRequest(
$path,
$method,
$request,
$responseType,
$arrayOfObjects = false
) {
$response = $this->client->makeRequest(
$path,
$method,
$request
);
$statusCode = $response->getStatusCode();
$data = json_decode((string) $response->getBody(), true);
if (json_last_error() == JSON_ERROR_NONE) {
if ($arrayOfObjects) {
return new ListResponse($responseType, $data, $statusCode);
} else {
$obj = Serializer::deserialize($data, $responseType, Serializer::S_ARRAY);
if ($statusCode >= 400
&& method_exists($obj, 'setErrors')
&& method_exists($obj, 'getErrors')
&& count(call_user_func([$obj, 'getErrors'])) == 0
) {
call_user_func_array([$obj, 'setErrors'], [['Status Code ' . $response->getStatusCode()]]);
}
if (method_exists($obj, 'setStatusCode')) {
call_user_func_array([$obj, 'setStatusCode'], [$statusCode]);
}
return $obj;
}
} else {
throw new InvalidJsonException('Received invalid JSON', 1);
}
}
/**
* @param bool $fromRoot
* @param string ...$classes
*
* @return string
*/
private static function concatClasspath($fromRoot, ...$classes)
{
$path = '';
foreach ($classes as $class) {
if (empty($path) && !$fromRoot) {
$path .= $class;
} else {
$path .= '\\' . $class;
}
}
return $path;
}
/**
* @param string ...$classes
*
* @return string
*/
private static function getEntityClass(...$classes)
{
return static::concatClasspath(true, 'RetailCrm', 'Mg', 'Bot', 'Model', 'Entity', ...$classes);
}
/**
* @param string ...$classes
*
* @return string
*/
private static function getResponseClass(...$classes)
{
return static::concatClasspath(true, 'RetailCrm', 'Mg', 'Bot', 'Model', 'Response', ...$classes);
}
/**
* Returns filtered bots list
*
* @param Model\Request\BotsRequest $request
* @param Model\Request\BotsRequest $request Request parameters
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @throws \Exception
*/
public function bots(Model\Request\BotsRequest $request)
{
return $this->client->makeRequest('/bots', Request::METHOD_GET, $request, Serializer::S_ARRAY);
return $this->submitRequest(
'/bots',
HttpClient::METHOD_GET,
$request,
static::getEntityClass('Bot'),
true
);
}
/**
* Edit bot info
*
* @param Model\Request\InfoRequest $request
* @param Model\Request\InfoRequest $request Request parameters
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws CurlException
* @throws Exception
*
* @return Response
* @return \RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse|object
* @throws \Exception
*/
public function info(Model\Request\InfoRequest $request)
{
return $this->client->makeRequest('/my/info', Request::METHOD_PATCH, $request);
return $this->submitRequest(
'/my/info',
HttpClient::METHOD_PATCH,
$request,
static::getResponseClass(self::ERROR_ONLY_RESPONSE)
);
}
/**
* Returns filtered channels list
*
* @param Model\Request\ChannelsRequest $request
* @param Model\Request\ChannelsRequest $request Request parameters
*
* @return Response
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @throws \Exception
*/
public function channels(Model\Request\ChannelsRequest $request)
{
return $this->client->makeRequest('/channels', Request::METHOD_GET, $request, Serializer::S_ARRAY);
return $this->submitRequest(
'/channels',
HttpClient::METHOD_GET,
$request,
static::getEntityClass('Channel', 'Channel'),
true
);
}
/**
* Returns filtered chats list
*
* @param Model\Request\ChatsRequest $request
* @param Model\Request\ChatsRequest $request Request parameters
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @throws \Exception
*/
public function chats(Model\Request\ChatsRequest $request)
{
return $this->client->makeRequest('/chats', Request::METHOD_GET, $request, Serializer::S_ARRAY);
return $this->submitRequest(
'/chats',
HttpClient::METHOD_GET,
$request,
static::getEntityClass('Chat', 'Chat'),
true
);
}
/**
* Returns filtered commands list
*
* @param Model\Request\CommandsRequest $request
* @param Model\Request\CommandsRequest $request Request parameters
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @throws \Exception
*/
public function commands(Model\Request\CommandsRequest $request)
{
return $this->client->makeRequest('/my/commands', Request::METHOD_GET, $request, Serializer::S_ARRAY);
return $this->submitRequest(
'/my/commands',
HttpClient::METHOD_GET,
$request,
static::getEntityClass('Command'),
true
);
}
/**
* Edit commands for exact bot
*
* @param Model\Request\CommandEditRequest $request
* @param Model\Request\CommandEditRequest $request Request parameters
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
* @return \RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse|object
* @throws \Exception
*/
public function commandEdit(Model\Request\CommandEditRequest $request)
{
return $this->client->makeRequest(
return $this->submitRequest(
sprintf("/my/commands/%s", $request->getName()),
Request::METHOD_PUT,
$request
HttpClient::METHOD_PUT,
$request,
static::getResponseClass(self::ERROR_ONLY_RESPONSE)
);
}
/**
* Delete command for exact bot
*
* @param string $request
* @param string $request Request parameters
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
* @return \RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse|object
* @throws \Exception
*/
public function commandDelete(string $request)
{
return $this->client->makeRequest(sprintf("/my/commands/%s", $request), Request::METHOD_DELETE);
return $this->submitRequest(
sprintf("/my/commands/%s", $request),
HttpClient::METHOD_DELETE,
null,
static::getResponseClass(self::ERROR_ONLY_RESPONSE)
);
}
/**
* Returns filtered customers list
*
* @param Model\Request\CustomersRequest $request
* @param Model\Request\CustomersRequest $request Request parameters
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @throws \Exception
*/
public function customers(Model\Request\CustomersRequest $request)
{
return $this->client->makeRequest('/customers', Request::METHOD_GET, $request, Serializer::S_ARRAY);
return $this->submitRequest(
'/customers',
HttpClient::METHOD_GET,
$request,
static::getEntityClass('Customer'),
true
);
}
/**
* Returns filtered dialogs list
*
* @param Model\Request\DialogsRequest $request
* @param Model\Request\DialogsRequest $request Request parameters
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @throws \Exception
*/
public function dialogs(Model\Request\DialogsRequest $request)
{
return $this->client->makeRequest('/dialogs', Request::METHOD_GET, $request, Serializer::S_ARRAY);
return $this->submitRequest(
'/dialogs',
HttpClient::METHOD_GET,
$request,
static::getEntityClass('Dialog'),
true
);
}
/**
* Assign dialog to exact user
*
* @param Model\Request\DialogAssignRequest $request
* @param Model\Request\DialogAssignRequest $request Request parameters
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
* @return \RetailCrm\Mg\Bot\Model\Response\AssignResponse|object
* @throws \Exception
*/
public function dialogAssign(Model\Request\DialogAssignRequest $request)
{
return $this->client->makeRequest(
return $this->submitRequest(
sprintf("/dialogs/%d/assign", $request->getDialogId()),
Request::METHOD_PATCH,
$request
HttpClient::METHOD_PATCH,
$request,
static::getResponseClass('AssignResponse')
);
}
/**
* Close exact dialog
*
* @param string $request
* @param string $request Request parameters
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
* @return \RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse|object
* @throws \Exception
*/
public function dialogClose(string $request)
{
return $this->client->makeRequest(sprintf("/dialogs/%d/close", $request), Request::METHOD_DELETE);
return $this->submitRequest(
sprintf("/dialogs/%d/close", $request),
HttpClient::METHOD_DELETE,
null,
static::getResponseClass(self::ERROR_ONLY_RESPONSE)
);
}
/**
* Returns filtered members list
*
* @param Model\Request\MembersRequest $request
* @param Model\Request\MembersRequest $request Request parameters
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @throws \Exception
*/
public function members(Model\Request\MembersRequest $request)
{
return $this->client->makeRequest('/members', Request::METHOD_GET, $request, Serializer::S_ARRAY);
return $this->submitRequest(
'/members',
HttpClient::METHOD_GET,
$request,
static::getEntityClass('Chat', 'ChatMember'),
true
);
}
/**
* Returns filtered messages list
*
* @param Model\Request\MessagesRequest $request
* @param Model\Request\MessagesRequest $request Request parameters
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @throws \Exception
*/
public function messages(Model\Request\MessagesRequest $request)
{
return $this->client->makeRequest('/messages', Request::METHOD_GET, $request, Serializer::S_ARRAY);
return $this->submitRequest(
'/messages',
HttpClient::METHOD_GET,
$request,
self::getEntityClass('Message', 'Message'),
true
);
}
/**
* Send a message
*
* @param Model\Request\MessageSendRequest $request
* @param Model\Request\MessageSendRequest $request Request parameters
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
* @return \RetailCrm\Mg\Bot\Model\Response\MessageSendResponse|object
* @throws \Exception
*/
public function messageSend(Model\Request\MessageSendRequest $request)
{
return $this->client->makeRequest('/messages', Request::METHOD_POST, $request);
return $this->submitRequest(
'/messages',
HttpClient::METHOD_POST,
$request,
static::getResponseClass('MessageSendResponse')
);
}
/**
* Edit a message
*
* @param Model\Request\MessageEditRequest $request
* @param Model\Request\MessageEditRequest $request Request parameters
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
* @return \RetailCrm\Mg\Bot\Model\Response\MessageSendResponse|object
* @throws \Exception
*/
public function messageEdit(Model\Request\MessageEditRequest $request)
{
return $this->client->makeRequest('/messages/%d', Request::METHOD_PATCH, $request->getId());
return $this->submitRequest(
sprintf("/messages/%d", $request->getId()),
HttpClient::METHOD_PATCH,
$request,
static::getResponseClass('MessageSendResponse')
);
}
/**
* Delete a message
*
* @param string $request
* @param string $request Request parameters
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
* @return \RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse|object
* @throws \Exception
*/
public function messageDelete(string $request)
{
return $this->client->makeRequest(sprintf("/messages/%d", $request), Request::METHOD_DELETE);
return $this->submitRequest(
sprintf("/messages/%d", $request),
HttpClient::METHOD_DELETE,
null,
static::getResponseClass(self::ERROR_ONLY_RESPONSE)
);
}
/**
* Returns filtered users list
*
* @param Model\Request\UsersRequest $request
* @param Model\Request\UsersRequest $request Request parameters
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
* @return \RetailCrm\Mg\Bot\Model\Response\ListResponse|object
* @throws \Exception
*/
public function users(Model\Request\UsersRequest $request)
{
return $this->client->makeRequest('/users', Request::METHOD_GET, $request, Serializer::S_ARRAY);
return $this->submitRequest(
'/users',
HttpClient::METHOD_GET,
$request,
self::getEntityClass('User'),
true
);
}
/**
* Returns filtered users list
*
* @param string $url File URL
*
* @return \RetailCrm\Mg\Bot\Model\Response\UploadFileResponse|object
* @throws \Exception
*/
public function uploadFileByUrl(string $url)
{
$request = new UploadFileByUrlRequest();
$request->setUrl($url);
return $this->submitRequest(
'/files/upload_by_url',
HttpClient::METHOD_POST,
$request,
self::getResponseClass('UploadFileResponse')
);
}
/**
* @param string $filename
* @return Model\Response\UploadFileResponse|null
*
* @throws \Exception
*/
public function uploadFile(string $filename)
{
$response = $this->client->postFile($filename);
if ($response instanceof ResponseInterface) {
$obj = Serializer::deserialize(
(string) $response->getBody(),
self::getResponseClass('UploadFileResponse')
);
return $obj instanceof UploadFileResponse ? $obj : null;
}
return null;
}
/**
* @param string $fileId
* @return Model\Response\FullFileResponse|null
*
* @throws \Exception
*/
public function getFileById(string $fileId)
{
$obj = $this->submitRequest(
\sprintf('/files/%s', $fileId),
HttpClient::METHOD_GET,
null,
self::getResponseClass('FullFileResponse')
);
return ($obj instanceof FullFileResponse) ? $obj : null;
}
}

291
src/Bot/HttpClient.php Normal file
View file

@ -0,0 +1,291 @@
<?php
/**
* PHP version 7.0
*
* HttpClient
*
* @package RetailCrm\Mg\Bot
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot;
use RetailCrm\Common\Exception\InvalidJsonException;
use RetailCrm\Common\Exception\LimitException;
use InvalidArgumentException;
use RetailCrm\Common\Serializer;
use RetailCrm\Common\Url;
use Symfony\Component\Validator\Validation;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Exception\GuzzleException;
use Psr\Http\Message\ResponseInterface;
use function GuzzleHttp\Psr7\stream_for;
/**
* PHP version 7.0
*
* HttpClient class
*
* @package RetailCrm\Mg\Bot
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class HttpClient
{
/**
* GET HTTP Method constant
*/
const METHOD_GET = 'GET';
/**
* POST HTTP Method constant
*/
const METHOD_POST = 'POST';
/**
* PUT HTTP Method constant
*/
const METHOD_PUT = 'PUT';
/**
* PATCH HTTP Method constant
*/
const METHOD_PATCH = 'PATCH';
/**
* DELETE HTTP Method constant
*/
const METHOD_DELETE = 'DELETE';
protected $basePath;
protected $token;
private $allowedMethods;
private $stdout;
private $client;
/**
* HTTP Client constructor.
* Provide $stdout (for example: STDOUT) to log all requests.
*
* @param string $url MG API URL
* @param string $token MG API Key
* @param null|resource $stdout Output to log all requests (optional, default: null)
* @param \GuzzleHttp\HandlerStack $handler GuzzleHttp::HandlerStack instance (default: null)
*/
public function __construct($url, $token, $stdout = null, $handler = null)
{
if (false === stripos($url, 'https://')) {
throw new InvalidArgumentException('API schema requires HTTPS protocol');
}
$this->basePath = parse_url($url, PHP_URL_PATH);
$this->token = $token;
$this->stdout = $stdout;
$this->client = new Client(array_filter([
'base_uri' => Url::normalizeUrl($url),
'timeout' => 60,
'handler' => $handler
]));
$this->allowedMethods = [
self::METHOD_GET,
self::METHOD_POST,
self::METHOD_PUT,
self::METHOD_PATCH,
self::METHOD_DELETE
];
}
/**
* Make HTTP request
*
* @param string $path Request URL
* @param string $method Request method (default: 'GET')
* @param mixed $request Request model (default: null)
*
* @return ResponseInterface
* @throws \Exception
*/
public function makeRequest($path, $method, $request = null)
{
$getParameters = '';
$this->validateMethod($method);
if (!is_null($request)) {
$this->validateRequest($request);
}
if ($method == self::METHOD_GET && !is_null($request)) {
$getParameters = Url::buildGetParameters(Serializer::serialize($request, Serializer::S_ARRAY));
}
$requestBody = is_null($request) ? null : Serializer::serialize($request, Serializer::S_JSON);
$request = new Request(
$method,
\sprintf("%s%s%s", $this->basePath, $path, $getParameters),
[
'Content-Type' => 'application/json',
'X-Bot-Token' => $this->token
]
);
if (in_array($method, [self::METHOD_POST, self::METHOD_PUT, self::METHOD_PATCH, self::METHOD_DELETE])) {
$request = $request->withBody(stream_for($requestBody));
}
$responseObject = null;
try {
$responseObject = $this->client->send(
$request,
[
'debug' => $this->stdout,
'allow_redirects' => true,
'http_errors' => false,
'verify' => false
]
);
} catch (GuzzleException $exception) {
throw new \Exception($exception->getMessage(), $exception->getCode(), $exception);
}
$statusCode = $responseObject->getStatusCode();
$response = self::parseJSON((string) $responseObject->getBody());
$errorMessage = !empty($response['errorMsg']) ? $response['errorMsg'] : '';
$errorMessage = !empty($response['errors']) ? $this->getErrors($response['errors']) : $errorMessage;
/**
* responses with 400 & 460 http codes contains extended error data
* therefore they are not handled as exceptions
*/
if (in_array($statusCode, [403, 404, 500])) {
throw new \InvalidArgumentException($errorMessage);
}
if ($statusCode == 503) {
throw new LimitException($errorMessage);
}
return $responseObject;
}
/**
* @param string $filename
* @return ResponseInterface|null
*
* @throws \Exception
*/
public function postFile(string $filename)
{
if (!file_exists($filename)) {
throw new \InvalidArgumentException("File doesn't exist");
}
if (filesize($filename) == 0) {
throw new \InvalidArgumentException("Empty file provided");
}
try {
$responseData = $this->client->request(
self::METHOD_POST,
\sprintf("%s/files/upload", $this->basePath),
[
'headers' => [
'X-Bot-Token' => $this->token
],
'body' => fopen($filename, 'r')
]
);
} catch (GuzzleException $exception) {
throw new \Exception($exception->getMessage(), $exception->getCode(), $exception);
}
return isset($responseData) ? $responseData : null;
}
/**
* Validate HTTP method
*
* @param string $method
*/
private function validateMethod($method)
{
if (!in_array($method, $this->allowedMethods, false)) {
throw new InvalidArgumentException(
sprintf(
'Method "%s" is not valid. Allowed methods are %s',
$method,
implode(', ', $this->allowedMethods)
)
);
}
}
/**
* Validate given class
*
* @param string $class
*
* @return void
*/
private function validateRequest($class)
{
if (!is_string($class) && method_exists($class, 'validate')) {
$errors = $class->validate();
} else {
$validator = Validation::createValidatorBuilder()
->enableAnnotationMapping()
->getValidator();
$errors = $validator->validate($class);
}
if ((is_object($errors) && call_user_func([$errors, 'count']) > 0) || is_string($errors)) {
$message = (string) $errors;
throw new InvalidArgumentException($message);
}
}
/**
* @param array $errors
*
* @return string
*/
private function getErrors(array $errors)
{
$errorString = '';
foreach ($errors as $error) {
$errorString .= $error . " ";
}
return $errorString;
}
/**
* @param string $responseBody
*
* @return array
*/
public static function parseJSON($responseBody): array
{
$result = [];
if (!empty($responseBody)) {
$response = json_decode($responseBody, true);
if (!$response && JSON_ERROR_NONE !== ($error = json_last_error())) {
throw new InvalidJsonException("Invalid JSON in the API response body. Error code #$error", $error);
}
$result = $response;
}
return $result;
}
}

View file

@ -0,0 +1,330 @@
<?php
/**
* PHP version 7.0
*
* Bot entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* Bot class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Bot
{
/**
* @var string $id
*
* @Type("string")
* @Accessor(getter="getId",setter="setId")
*/
private $id;
/**
* @var \DateTime $createdAt
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getCreatedAt",setter="setCreatedAt")
* @SkipWhenEmpty()
*/
private $createdAt;
/**
* @var \DateTime $updatedAt
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getUpdatedAt",setter="setUpdatedAt")
* @SkipWhenEmpty()
*/
private $updatedAt;
/**
* @var string $name
*
* @Type("string")
* @Accessor(getter="getName",setter="setName")
* @SkipWhenEmpty()
*/
private $name;
/**
* @var array $events
*
* @Type("array")
* @Accessor(getter="getEvents",setter="setEvents")
* @SkipWhenEmpty()
*/
private $events;
/**
* @var string $clientId
*
* @Type("string")
* @Accessor(getter="getClientId",setter="setClientId")
* @SkipWhenEmpty()
*/
private $clientId;
/**
* @var string $avatarUrl
*
* @Type("string")
* @Accessor(getter="getAvatarUrl",setter="setAvatarUrl")
* @SkipWhenEmpty()
*/
private $avatarUrl;
/**
* @var array $roles
*
* @Type("array")
* @Accessor(getter="getRoles",setter="setRoles")
* @SkipWhenEmpty()
*/
private $roles;
/**
* @var string $deactivatedAt
*
* @Type("string")
* @Accessor(getter="getDeactivatedAt",setter="setDeactivatedAt")
* @SkipWhenEmpty()
*/
private $deactivatedAt;
/**
* @var bool $isActive
*
* @Type("bool")
* @Accessor(getter="getIsActive",setter="setIsActive")
* @SkipWhenEmpty()
*/
private $isActive;
/**
* @var bool $isSelf
*
* @Type("bool")
* @Accessor(getter="getIsSelf",setter="setIsSelf")
* @SkipWhenEmpty()
*/
private $isSelf;
/**
* @var bool $isSystem
*
* @Type("bool")
* @Accessor(getter="getIsSystem",setter="setIsSystem")
* @SkipWhenEmpty()
*/
private $isSystem;
/**
* @return string
*/
public function getId(): string
{
return $this->id;
}
/**
* @param string $id
*/
public function setId(string $id)
{
$this->id = $id;
}
/**
* @return \DateTime
*/
public function getCreatedAt(): \DateTime
{
return $this->createdAt;
}
/**
* @param \DateTime $createdAt
*/
public function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
}
/**
* @return \DateTime
*/
public function getUpdatedAt(): \DateTime
{
return $this->updatedAt;
}
/**
* @param \DateTime $updatedAt
*/
public function setUpdatedAt(\DateTime $updatedAt)
{
$this->updatedAt = $updatedAt;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name)
{
$this->name = $name;
}
/**
* @return array
*/
public function getEvents(): array
{
return $this->events;
}
/**
* @param array $events
*/
public function setEvents(array $events)
{
$this->events = $events;
}
/**
* @return string
*/
public function getClientId(): string
{
return $this->clientId;
}
/**
* @param string $clientId
*/
public function setClientId(string $clientId)
{
$this->clientId = $clientId;
}
/**
* @return string
*/
public function getAvatarUrl(): string
{
return $this->avatarUrl;
}
/**
* @param string $avatarUrl
*/
public function setAvatarUrl(string $avatarUrl)
{
$this->avatarUrl = $avatarUrl;
}
/**
* @return array
*/
public function getRoles(): array
{
return $this->roles;
}
/**
* @param array $roles
*/
public function setRoles(array $roles)
{
$this->roles = $roles;
}
/**
* @return string
*/
public function getDeactivatedAt(): string
{
return $this->deactivatedAt;
}
/**
* @param string $deactivatedAt
*/
public function setDeactivatedAt(string $deactivatedAt)
{
$this->deactivatedAt = $deactivatedAt;
}
/**
* @return bool
*/
public function isActive(): bool
{
return $this->isActive;
}
/**
* @param bool $isActive
*/
public function setIsActive(bool $isActive)
{
$this->isActive = $isActive;
}
/**
* @return bool
*/
public function isSelf(): bool
{
return $this->isSelf;
}
/**
* @param bool $isSelf
*/
public function setIsSelf(bool $isSelf)
{
$this->isSelf = $isSelf;
}
/**
* @return bool
*/
public function isSystem(): bool
{
return $this->isSystem;
}
/**
* @param bool $isSystem
*/
public function setIsSystem(bool $isSystem)
{
$this->isSystem = $isSystem;
}
}

View file

@ -0,0 +1,247 @@
<?php
/**
* PHP version 7.0
*
* Channel entity
*
* @package RetailCrm\Mg\Bot\Model\Entity\Channel
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity\Channel;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* Channel class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Channel
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Channel
{
/**
* @var string $id
*
* @Type("string")
* @Accessor(getter="getId",setter="setId")
*/
private $id;
/**
* @var \DateTime $createdAt
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getCreatedAt",setter="setCreatedAt")
*/
private $createdAt;
/**
* @var \DateTime $updatedAt
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getUpdatedAt",setter="setUpdatedAt")
*/
private $updatedAt;
/**
* @var \DateTime $activatedAt
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getActivatedAt",setter="setActivatedAt")
*/
private $activatedAt;
/**
* @var \DateTime $deactivatedAt
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getDeactivatedAt",setter="setDeactivatedAt")
*/
private $deactivatedAt;
/**
* @var bool $isActive
*
* @Type("bool")
* @Accessor(getter="getIsActive",setter="setIsActive")
*/
private $isActive;
/**
* @var ChannelSettings $settings
*
* @Type("RetailCrm\Mg\Bot\Model\Entity\Channel\ChannelSettings")
* @Accessor(getter="getSettings",setter="setSettings")
*/
private $settings;
/**
* @var string $type
*
* @Type("string")
* @Accessor(getter="getType",setter="setType")
*/
private $type;
/**
* @var string $actions
*
* @Type("string")
* @Accessor(getter="getName",setter="setName")
*/
private $name;
/**
* @return string
*/
public function getId(): string
{
return $this->id;
}
/**
* @param string $id
*/
public function setId(string $id)
{
$this->id = $id;
}
/**
* @return \DateTime
*/
public function getCreatedAt(): \DateTime
{
return $this->createdAt;
}
/**
* @param \DateTime $createdAt
*/
public function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
}
/**
* @return \DateTime
*/
public function getUpdatedAt(): \DateTime
{
return $this->updatedAt;
}
/**
* @param \DateTime $updatedAt
*/
public function setUpdatedAt(\DateTime $updatedAt)
{
$this->updatedAt = $updatedAt;
}
/**
* @return \DateTime
*/
public function getActivatedAt(): \DateTime
{
return $this->activatedAt;
}
/**
* @param \DateTime $activatedAt
*/
public function setActivatedAt(\DateTime $activatedAt)
{
$this->activatedAt = $activatedAt;
}
/**
* @return \DateTime
*/
public function getDeactivatedAt(): \DateTime
{
return $this->deactivatedAt;
}
/**
* @param \DateTime $deactivatedAt
*/
public function setDeactivatedAt(\DateTime $deactivatedAt)
{
$this->deactivatedAt = $deactivatedAt;
}
/**
* @return bool
*/
public function isActive(): bool
{
return $this->isActive;
}
/**
* @param bool $isActive
*/
public function setIsActive(bool $isActive)
{
$this->isActive = $isActive;
}
/**
* @return ChannelSettings
*/
public function getSettings(): ChannelSettings
{
return $this->settings;
}
/**
* @param ChannelSettings $settings
*/
public function setSettings(ChannelSettings $settings)
{
$this->settings = $settings;
}
/**
* @return string
*/
public function getType(): string
{
return $this->type;
}
/**
* @param string $type
*/
public function setType(string $type)
{
$this->type = $type;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name)
{
$this->name = $name;
}
}

View file

@ -0,0 +1,204 @@
<?php
/**
* PHP version 7.0
*
* ChannelSettings entity
*
* @package RetailCrm\Mg\Bot\Model\Entity\Channel
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity\Channel;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* ChannelSettings class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Channel
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ChannelSettings
{
/**
* @var ChannelSettingsStatus $status
*
* @Type("RetailCrm\Mg\Bot\Model\Entity\Channel\ChannelSettingsStatus")
* @Accessor(getter="getStatus",setter="setStatus")
*/
private $status;
/**
* @var bool $spamAllowed
*
* @Type("bool")
* @Accessor(getter="getStatus",setter="setStatus")
*/
private $spamAllowed;
/**
* @var ChannelSettingsItem $text
*
* @Type("RetailCrm\Mg\Bot\Model\Entity\Channel\ChannelSettingsItem")
* @Accessor(getter="getText",setter="setText")
* @SkipWhenEmpty()
*/
private $text;
/**
* @var ChannelSettingsItem $product
*
* @Type("RetailCrm\Mg\Bot\Model\Entity\Channel\ChannelSettingsItem")
* @Accessor(getter="getProduct",setter="setProduct")
* @SkipWhenEmpty()
*/
private $product;
/**
* @var ChannelSettingsItem $order
*
* @Type("RetailCrm\Mg\Bot\Model\Entity\Channel\ChannelSettingsItem")
* @Accessor(getter="getOrder",setter="setOrder")
* @SkipWhenEmpty()
*/
private $order;
/**
* @var ChannelSettingsItem $image
*
* @Type("RetailCrm\Mg\Bot\Model\Entity\Channel\ChannelSettingsItem")
* @Accessor(getter="getImage",setter="setImage")
* @SkipWhenEmpty()
*/
private $image;
/**
* @var ChannelSettingsItem $file
*
* @Type("RetailCrm\Mg\Bot\Model\Entity\Channel\ChannelSettingsItem")
* @Accessor(getter="getFile",setter="setFile")
* @SkipWhenEmpty()
*/
private $file;
/**
* @return ChannelSettingsStatus
*/
public function getStatus(): ChannelSettingsStatus
{
return $this->status;
}
/**
* @param ChannelSettingsStatus $status
*/
public function setStatus(ChannelSettingsStatus $status)
{
$this->status = $status;
}
/**
* @return bool
*/
public function isSpamAllowed(): bool
{
return $this->spamAllowed;
}
/**
* @param bool $spamAllowed
*/
public function setSpamAllowed(bool $spamAllowed)
{
$this->spamAllowed = $spamAllowed;
}
/**
* @return ChannelSettingsItem
*/
public function getText(): ChannelSettingsItem
{
return $this->text;
}
/**
* @param ChannelSettingsItem $text
*/
public function setText(ChannelSettingsItem $text)
{
$this->text = $text;
}
/**
* @return ChannelSettingsItem
*/
public function getProduct(): ChannelSettingsItem
{
return $this->product;
}
/**
* @param ChannelSettingsItem $product
*/
public function setProduct(ChannelSettingsItem $product)
{
$this->product = $product;
}
/**
* @return ChannelSettingsItem
*/
public function getOrder(): ChannelSettingsItem
{
return $this->order;
}
/**
* @param ChannelSettingsItem $order
*/
public function setOrder(ChannelSettingsItem $order)
{
$this->order = $order;
}
/**
* @return ChannelSettingsItem
*/
public function getImage(): ChannelSettingsItem
{
return $this->image;
}
/**
* @param ChannelSettingsItem $image
*/
public function setImage(ChannelSettingsItem $image)
{
$this->image = $image;
}
/**
* @return ChannelSettingsItem
*/
public function getFile(): ChannelSettingsItem
{
return $this->file;
}
/**
* @param ChannelSettingsItem $file
*/
public function setFile(ChannelSettingsItem $file)
{
$this->file = $file;
}
}

View file

@ -0,0 +1,231 @@
<?php
/**
* PHP version 7.0
*
* ChannelSettingsItem entity
*
* @package RetailCrm\Mg\Bot\Model\Entity\Channel
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity\Channel;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* ChannelSettingsItem class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Channel
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ChannelSettingsItem
{
/**
* @var string $creating
*
* @Type("string")
* @Accessor(getter="getCreating",setter="setCreating")
* @SkipWhenEmpty()
*/
private $creating;
/**
* @var string $editing
*
* @Type("string")
* @Accessor(getter="getEditing",setter="setEditing")
* @SkipWhenEmpty()
*/
private $editing;
/**
* @var string $quoting
*
* @Type("string")
* @Accessor(getter="getQuoting",setter="setQuoting")
* @SkipWhenEmpty()
*/
private $quoting;
/**
* @var string $deleting
*
* @Type("string")
* @Accessor(getter="getDeleting",setter="setDeleting")
* @SkipWhenEmpty()
*/
private $deleting;
/**
* @var string $delivered
*
* @Type("string")
* @Accessor(getter="getDelivered",setter="setDelivered")
* @SkipWhenEmpty()
*/
private $delivered;
/**
* @var int $maxCharsCount
*
* @Type("int")
* @Accessor(getter="getMaxCharsCount",setter="setMaxCharsCount")
* @SkipWhenEmpty()
*/
private $maxCharsCount;
/**
* @var int $maxItemsCount
*
* @Type("int")
* @Accessor(getter="getMaxItemsCount",setter="setMaxItemsCount")
* @SkipWhenEmpty()
*/
private $maxItemsCount;
/**
* @var int $noteMaxCharsCount
*
* @Type("int")
* @Accessor(getter="getNoteMaxCharsCount", setter="setNoteMaxCharsCount")
* @SkipWhenEmpty()
*/
private $noteMaxCharsCount;
/**
* @return string
*/
public function getCreating(): string
{
return $this->creating;
}
/**
* @param string $creating
*/
public function setCreating(string $creating)
{
$this->creating = $creating;
}
/**
* @return string
*/
public function getEditing(): string
{
return $this->editing;
}
/**
* @param string $editing
*/
public function setEditing(string $editing)
{
$this->editing = $editing;
}
/**
* @return string
*/
public function getQuoting(): string
{
return $this->quoting;
}
/**
* @param string $quoting
*/
public function setQuoting(string $quoting)
{
$this->quoting = $quoting;
}
/**
* @return string
*/
public function getDeleting(): string
{
return $this->deleting;
}
/**
* @param string $deleting
*/
public function setDeleting(string $deleting)
{
$this->deleting = $deleting;
}
/**
* @return string
*/
public function getDelivered(): string
{
return $this->delivered;
}
/**
* @param string $delivered
*/
public function setDelivered(string $delivered)
{
$this->delivered = $delivered;
}
/**
* @return int
*/
public function getMaxCharsCount(): int
{
return $this->maxCharsCount;
}
/**
* @param int $maxCharsCount
*/
public function setMaxCharsCount(int $maxCharsCount)
{
$this->maxCharsCount = $maxCharsCount;
}
/**
* @return int
*/
public function getMaxItemsCount(): int
{
return $this->maxItemsCount;
}
/**
* @param int $maxItemsCount
*/
public function setMaxItemsCount(int $maxItemsCount)
{
$this->maxItemsCount = $maxItemsCount;
}
/**
* @return int
*/
public function getNoteMaxCharsCount(): int
{
return $this->noteMaxCharsCount;
}
/**
* @param int $noteMaxCharsCount
*/
public function setNoteMaxCharsCount(int $noteMaxCharsCount)
{
$this->noteMaxCharsCount = $noteMaxCharsCount;
}
}

View file

@ -0,0 +1,81 @@
<?php
/**
* PHP version 7.0
*
* ChannelSettingsStatus entity
*
* @package RetailCrm\Mg\Bot\Model\Entity\Channel
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity\Channel;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* ChannelSettingsStatus class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Channel
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ChannelSettingsStatus
{
/**
* @var string $delivered
*
* @Type("string")
* @Accessor(getter="getDelivered",setter="setDelivered")
* @SkipWhenEmpty()
*/
private $delivered;
/**
* @var string $read
*
* @Type("string")
* @Accessor(getter="getRead",setter="setRead")
* @SkipWhenEmpty()
*/
private $read;
/**
* @return string
*/
public function getDelivered(): string
{
return $this->delivered;
}
/**
* @param string $delivered
*/
public function setDelivered(string $delivered)
{
$this->delivered = $delivered;
}
/**
* @return string
*/
public function getRead(): string
{
return $this->read;
}
/**
* @param string $read
*/
public function setRead(string $read)
{
$this->read = $read;
}
}

View file

@ -0,0 +1,298 @@
<?php
/**
* PHP version 7.0
*
* Chat entity
*
* @package RetailCrm\Mg\Bot\Model\Entity\Chat
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity\Chat;
use RetailCrm\Mg\Bot\Model\Entity\Channel\Channel;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\Entity\Customer;
/**
* PHP version 7.0
*
* Chat class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Chat
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Chat
{
/**
* @var string $id
*
* @Type("string")
* @Accessor(getter="getId",setter="setId")
*/
private $id;
/**
* @var \DateTime $createdAt
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getCreatedAt",setter="setCreatedAt")
*/
private $createdAt;
/**
* @var \DateTime $updatedAt
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getUpdatedAt",setter="setUpdatedAt")
*/
private $updatedAt;
/**
* @var string $avatar
*
* @Type("string")
* @Accessor(getter="getAvatar",setter="setAvatar")
*/
private $avatar;
/**
* @var string $name
*
* @Type("string")
* @Accessor(getter="getName",setter="setName")
*/
private $name;
/**
* @var Channel $channel
*
* @Type("RetailCrm\Mg\Bot\Model\Entity\Channel\Channel")
* @Accessor(getter="getChannel",setter="setChannel")
* @SkipWhenEmpty()
*/
private $channel;
/**
* @var array $members
*
* @Type("array")
* @Accessor(getter="getMembers",setter="setMembers")
*/
private $members;
/**
* @var Customer $customer
*
* @Type("RetailCrm\Mg\Bot\Model\Entity\Customer")
* @Accessor(getter="getCustomer",setter="setCustomer")
*/
private $customer;
/**
* @var int $authorId
*
* @Type("int")
* @Accessor(getter="getAuthorId",setter="setAuthorId")
*/
private $authorId;
/**
* @var ChatLastMessage $lastMessage
*
* @Type("ChatLastMessage")
* @Accessor(getter="getLastMessage",setter="setLastMessage")
*/
private $lastMessage;
/**
* @var \DateTime $lastActivity
*
* @Type("DateTime<'Y-m-d\TH:i:sP'>")
* @Accessor(getter="getLastActivity",setter="setLastActivity")
*/
private $lastActivity;
/**
* @return string
*/
public function getId(): string
{
return $this->id;
}
/**
* @param string $id
*/
public function setId(string $id)
{
$this->id = $id;
}
/**
* @return \DateTime
*/
public function getCreatedAt(): \DateTime
{
return $this->createdAt;
}
/**
* @param \DateTime $createdAt
*/
public function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
}
/**
* @return \DateTime
*/
public function getUpdatedAt(): \DateTime
{
return $this->updatedAt;
}
/**
* @param \DateTime $updatedAt
*/
public function setUpdatedAt(\DateTime $updatedAt)
{
$this->updatedAt = $updatedAt;
}
/**
* @return string
*/
public function getAvatar(): string
{
return $this->avatar;
}
/**
* @param string $avatar
*/
public function setAvatar(string $avatar)
{
$this->avatar = $avatar;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name)
{
$this->name = $name;
}
/**
* @return Channel
*/
public function getChannel(): Channel
{
return $this->channel;
}
/**
* @param Channel $channel
*/
public function setChannel(Channel $channel)
{
$this->channel = $channel;
}
/**
* @return array
*/
public function getMembers(): array
{
return $this->members;
}
/**
* @param array $members
*/
public function setMembers(array $members)
{
$this->members = $members;
}
/**
* @return Customer
*/
public function getCustomer(): Customer
{
return $this->customer;
}
/**
* @param Customer $customer
*/
public function setCustomer(Customer $customer)
{
$this->customer = $customer;
}
/**
* @return int
*/
public function getAuthorId(): int
{
return $this->authorId;
}
/**
* @param int $authorId
*/
public function setAuthorId(int $authorId)
{
$this->authorId = $authorId;
}
/**
* @return ChatLastMessage
*/
public function getLastMessage(): ChatLastMessage
{
return $this->lastMessage;
}
/**
* @param ChatLastMessage $lastMessage
*/
public function setLastMessage(ChatLastMessage $lastMessage)
{
$this->lastMessage = $lastMessage;
}
/**
* @return \DateTime
*/
public function getLastActivity(): \DateTime
{
return $this->lastActivity;
}
/**
* @param \DateTime $lastActivity
*/
public function setLastActivity(\DateTime $lastActivity)
{
$this->lastActivity = $lastActivity;
}
}

View file

@ -0,0 +1,106 @@
<?php
/**
* PHP version 7.0
*
* ChatLastMessage entity
*
* @package RetailCrm\Mg\Bot\Model\Entity\Chat
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity\Chat;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* ChatLastMessage class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Chat
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ChatLastMessage
{
/**
* @var int $creating
*
* @Type("int")
* @Accessor(getter="getId",setter="setId")
* @SkipWhenEmpty()
*/
private $id;
/**
* @var \DateTime $time
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getTime",setter="setTime")
* @SkipWhenEmpty()
*/
private $time;
/**
* @var string $type
*
* @Type("string")
* @Accessor(getter="getType",setter="setType")
* @SkipWhenEmpty()
*/
private $type;
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @param int $id
*/
public function setId(int $id)
{
$this->id = $id;
}
/**
* @return \DateTime
*/
public function getTime(): \DateTime
{
return $this->time;
}
/**
* @param \DateTime $time
*/
public function setTime(\DateTime $time)
{
$this->time = $time;
}
/**
* @return string
*/
public function getType(): string
{
return $this->type;
}
/**
* @param string $type
*/
public function setType(string $type)
{
$this->type = $type;
}
}

View file

@ -0,0 +1,204 @@
<?php
/**
* PHP version 7.0
*
* ChatMember entity
*
* @package RetailCrm\Mg\Bot\Model\Entity\Chat
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity\Chat;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* ChatMember class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Chat
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ChatMember
{
/**
* @var string $id
*
* @Type("string")
* @Accessor(getter="getId",setter="setId")
*/
private $id;
/**
* @var \DateTime $createdAt
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getCreatedAt",setter="setCreatedAt")
*/
private $createdAt;
/**
* @var \DateTime $updatedAt
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getUpdatedAt",setter="setUpdatedAt")
* @SkipWhenEmpty()
*/
private $updatedAt;
/**
* @var int $chatId
*
* @Type("int")
* @Accessor(getter="getChatId",setter="setChatId")
* @SkipWhenEmpty()
*/
private $chatId;
/**
* @var int $userId
*
* @Type("int")
* @Accessor(getter="getUserId",setter="setUserId")
* @SkipWhenEmpty()
*/
private $userId;
/**
* @var bool $isAuthor
*
* @Type("bool")
* @Accessor(getter="getIsAuthor",setter="setIsAuthor")
* @SkipWhenEmpty()
*/
private $isAuthor;
/**
* @var string $creating
*
* @Type("string")
* @Accessor(getter="getState",setter="setState")
* @SkipWhenEmpty()
*/
private $state;
/**
* @return string
*/
public function getId(): string
{
return $this->id;
}
/**
* @param string $id
*/
public function setId(string $id)
{
$this->id = $id;
}
/**
* @return \DateTime
*/
public function getCreatedAt(): \DateTime
{
return $this->createdAt;
}
/**
* @param \DateTime $createdAt
*/
public function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
}
/**
* @return \DateTime
*/
public function getUpdatedAt(): \DateTime
{
return $this->updatedAt;
}
/**
* @param \DateTime $updatedAt
*/
public function setUpdatedAt(\DateTime $updatedAt)
{
$this->updatedAt = $updatedAt;
}
/**
* @return int
*/
public function getChatId(): int
{
return $this->chatId;
}
/**
* @param int $chatId
*/
public function setChatId(int $chatId)
{
$this->chatId = $chatId;
}
/**
* @return int
*/
public function getUserId(): int
{
return $this->userId;
}
/**
* @param int $userId
*/
public function setUserId(int $userId)
{
$this->userId = $userId;
}
/**
* @return bool
*/
public function isAuthor(): bool
{
return $this->isAuthor;
}
/**
* @param bool $isAuthor
*/
public function setIsAuthor(bool $isAuthor)
{
$this->isAuthor = $isAuthor;
}
/**
* @return string
*/
public function getState(): string
{
return $this->state;
}
/**
* @param string $state
*/
public function setState(string $state)
{
$this->state = $state;
}
}

View file

@ -0,0 +1,154 @@
<?php
/**
* PHP version 7.0
*
* Command entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* Command class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Command
{
/**
* @var string $id
*
* @Type("string")
* @Accessor(getter="getId",setter="setId")
*/
private $id;
/**
* @var \DateTime $createdAt
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getCreatedAt",setter="setCreatedAt")
*/
private $createdAt;
/**
* @var \DateTime $updatedAt
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getUpdatedAt",setter="setUpdatedAt")
* @SkipWhenEmpty()
*/
private $updatedAt;
/**
* @var string $name
*
* @Type("string")
* @Accessor(getter="getName",setter="setName")
* @SkipWhenEmpty()
*/
private $name;
/**
* @var string $description
*
* @Type("string")
* @Accessor(getter="getDescrtiption",setter="setDescription")
* @SkipWhenEmpty()
*/
private $description;
/**
* @return string
*/
public function getId(): string
{
return $this->id;
}
/**
* @param string $id
*/
public function setId(string $id)
{
$this->id = $id;
}
/**
* @return \DateTime
*/
public function getCreatedAt(): \DateTime
{
return $this->createdAt;
}
/**
* @param \DateTime $createdAt
*/
public function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
}
/**
* @return \DateTime
*/
public function getUpdatedAt(): \DateTime
{
return $this->updatedAt;
}
/**
* @param \DateTime $updatedAt
*/
public function setUpdatedAt(\DateTime $updatedAt)
{
$this->updatedAt = $updatedAt;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name)
{
$this->name = $name;
}
/**
* @return string
*/
public function getDescription(): string
{
return $this->description;
}
/**
* @param string $description
*/
public function setDescription(string $description)
{
$this->description = $description;
}
}

View file

@ -0,0 +1,417 @@
<?php
/**
* PHP version 7.0
*
* Customer entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
use Symfony\Component\Validator\Constraints as Assert;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* Customer class
* | email | string |
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Customer
{
/**
* @var string $id
*
* @Type("string")
* @Accessor(getter="getId",setter="setId")
*/
private $id;
/**
* @var \DateTime $createdAt
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getCreatedAt",setter="setCreatedAt")
*/
private $createdAt;
/**
* @var \DateTime $updatedAt
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getUpdatedAt",setter="setUpdatedAt")
* @SkipWhenEmpty()
*/
private $updatedAt;
/**
* @var string $externalId
*
* @Type("string")
* @Accessor(getter="getExternalId",setter="setExternalId")
* @SkipWhenEmpty()
* @Assert\Length(max="64")
* @Assert\NotNull()
*/
private $externalId;
/**
* @var int $channelId
*
* @Type("int")
* @Accessor(getter="getChannelId",setter="setChannelId")
* @SkipWhenEmpty()
*/
private $channelId;
/**
* @var string $username
*
* @Type("string")
* @Accessor(getter="getUsername",setter="setUsername")
* @SkipWhenEmpty()
* @Assert\Length(max="255")
*/
private $username;
/**
* @var string $firstName
*
* @Type("string")
* @Accessor(getter="getFirstName",setter="setFirstName")
* @SkipWhenEmpty()
* @Assert\Length(max="255")
*/
private $firstName;
/**
* @var string $lastName
*
* @Type("string")
* @Accessor(getter="getLastName",setter="setLastName")
* @SkipWhenEmpty()
* @Assert\Length(max="255")
*/
private $lastName;
/**
* @var string $avatarUrl
*
* @Type("string")
* @Accessor(getter="getAvatarUrl",setter="setAvatarUrl")
* @SkipWhenEmpty()
* @Assert\Length(max="255")
*/
private $avatarUrl;
/**
* @var string $profileUrl
*
* @Type("string")
* @Accessor(getter="getProfileUrl",setter="setProfileUrl")
* @SkipWhenEmpty()
* @Assert\Length(max="255")
*/
private $profileUrl;
/**
* @var string $revokedAt
*
* @Type("string")
* @Accessor(getter="getRevokedAt",setter="setRevokedAt")
* @SkipWhenEmpty()
*/
private $revokedAt;
/**
* @var string $country
*
* @Type("string")
* @Accessor(getter="getCountry",setter="setCountry")
* @SkipWhenEmpty()
* @Assert\Length(max="2")
*/
private $country;
/**
* @var string $language
*
* @Type("string")
* @Accessor(getter="getLanguage",setter="setLanguage")
* @SkipWhenEmpty()
* @Assert\Length(max="20")
*/
private $language;
/**
* @var string $phone
*
* @Type("string")
* @Accessor(getter="getPhone",setter="setPhone")
* @SkipWhenEmpty()
* @Assert\Length(max="16")
*/
private $phone;
/**
* @var string $email
*
* @Type("string")
* @Accessor(getter="getEmail",setter="setEmail")
* @SkipWhenEmpty()
* @Assert\Length(max="16")
*/
private $email;
/**
* @return string
*/
public function getId(): string
{
return $this->id;
}
/**
* @param string $id
*/
public function setId(string $id)
{
$this->id = $id;
}
/**
* @return \DateTime
*/
public function getCreatedAt(): \DateTime
{
return $this->createdAt;
}
/**
* @param \DateTime $createdAt
*/
public function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
}
/**
* @return \DateTime
*/
public function getUpdatedAt(): \DateTime
{
return $this->updatedAt;
}
/**
* @param \DateTime $updatedAt
*/
public function setUpdatedAt(\DateTime $updatedAt)
{
$this->updatedAt = $updatedAt;
}
/**
* @return string
*/
public function getExternalId(): string
{
return $this->externalId;
}
/**
* @param string $externalId
*/
public function setExternalId(string $externalId)
{
$this->externalId = $externalId;
}
/**
* @return int
*/
public function getChannelId(): int
{
return $this->channelId;
}
/**
* @param int $channelId
*/
public function setChannelId(int $channelId)
{
$this->channelId = $channelId;
}
/**
* @return string
*/
public function getUsername(): string
{
return $this->username;
}
/**
* @param string $username
*/
public function setUsername(string $username)
{
$this->username = $username;
}
/**
* @return string
*/
public function getFirstName(): string
{
return $this->firstName;
}
/**
* @param string $firstName
*/
public function setFirstName(string $firstName)
{
$this->firstName = $firstName;
}
/**
* @return string
*/
public function getLastName(): string
{
return $this->lastName;
}
/**
* @param string $lastName
*/
public function setLastName(string $lastName)
{
$this->lastName = $lastName;
}
/**
* @return string
*/
public function getAvatarUrl(): string
{
return $this->avatarUrl;
}
/**
* @param string $avatarUrl
*/
public function setAvatarUrl(string $avatarUrl)
{
$this->avatarUrl = $avatarUrl;
}
/**
* @return string
*/
public function getProfileUrl(): string
{
return $this->profileUrl;
}
/**
* @param string $profileUrl
*/
public function setProfileUrl(string $profileUrl)
{
$this->profileUrl = $profileUrl;
}
/**
* @return string
*/
public function getRevokedAt(): string
{
return $this->revokedAt;
}
/**
* @param string $revokedAt
*/
public function setRevokedAt(string $revokedAt)
{
$this->revokedAt = $revokedAt;
}
/**
* @return string
*/
public function getCountry(): string
{
return $this->country;
}
/**
* @param string $country
*/
public function setCountry(string $country)
{
$this->country = $country;
}
/**
* @return string
*/
public function getLanguage(): string
{
return $this->language;
}
/**
* @param string $language
*/
public function setLanguage(string $language)
{
$this->language = $language;
}
/**
* @return string
*/
public function getPhone(): string
{
return $this->phone;
}
/**
* @param string $phone
*/
public function setPhone(string $phone)
{
$this->phone = $phone;
}
/**
* @return string
*/
public function getEmail(): string
{
return $this->email;
}
/**
* @param string $email
*/
public function setEmail(string $email)
{
$this->email = $email;
}
}

View file

@ -0,0 +1,304 @@
<?php
/**
* PHP version 7.0
*
* Dialog entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* Dialog class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Dialog
{
/**
* @var string $id
*
* @Type("string")
* @Accessor(getter="getId",setter="setId")
*/
private $id;
/**
* @var \DateTime $createdAt
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getCreatedAt",setter="setCreatedAt")
*/
private $createdAt;
/**
* @var \DateTime $updatedAt
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getUpdatedAt",setter="setUpdatedAt")
* @SkipWhenEmpty()
*/
private $updatedAt;
/**
* @var int $botId
*
* @Type("int")
* @Accessor(getter="getBotId",setter="setBotId")
* @SkipWhenEmpty()
*/
private $botId;
/**
* @var int $chatId
*
* @Type("int")
* @Accessor(getter="getChatId",setter="setChatId")
* @SkipWhenEmpty()
*/
private $chatId;
/**
* @var int $beginMessageId
*
* @Type("int")
* @Accessor(getter="getBeginMessageId",setter="setBeginMessageId")
* @SkipWhenEmpty()
*/
private $beginMessageId;
/**
* @var int $endingMessageId
*
* @Type("int")
* @Accessor(getter="getEndingMessageId",setter="setEndingMessageId")
* @SkipWhenEmpty()
*/
private $endingMessageId;
/**
* @var \DateTime $closedAt
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getClosedAt",setter="setClosedAt")
* @SkipWhenEmpty()
*/
private $closedAt;
/**
* @var bool $isAssigned
*
* @Type("bool")
* @Accessor(getter="getIsAssigned",setter="setIsAssigned")
* @SkipWhenEmpty()
*/
private $isAssigned;
/**
* @var Responsible $responsible
*
* @Type("RetailCrm\Mg\Bot\Model\Entity\Responsible")
* @Accessor(getter="getResponsible",setter="setResponsible")
* @SkipWhenEmpty()
*/
private $responsible;
/**
* @var bool $isActive
*
* @Type("bool")
* @Accessor(getter="getIsActive",setter="setIsActive")
* @SkipWhenEmpty()
*/
private $isActive;
/**
* @return string
*/
public function getId(): string
{
return $this->id;
}
/**
* @param string $id
*/
public function setId(string $id)
{
$this->id = $id;
}
/**
* @return \DateTime
*/
public function getCreatedAt(): \DateTime
{
return $this->createdAt;
}
/**
* @param \DateTime $createdAt
*/
public function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
}
/**
* @return \DateTime
*/
public function getUpdatedAt(): \DateTime
{
return $this->updatedAt;
}
/**
* @param \DateTime $updatedAt
*/
public function setUpdatedAt(\DateTime $updatedAt)
{
$this->updatedAt = $updatedAt;
}
/**
* @return int
*/
public function getBotId(): int
{
return $this->botId;
}
/**
* @param int $botId
*/
public function setBotId(int $botId)
{
$this->botId = $botId;
}
/**
* @return int
*/
public function getChatId(): int
{
return $this->chatId;
}
/**
* @param int $chatId
*/
public function setChatId(int $chatId)
{
$this->chatId = $chatId;
}
/**
* @return int
*/
public function getBeginMessageId(): int
{
return $this->beginMessageId;
}
/**
* @param int $beginMessageId
*/
public function setBeginMessageId(int $beginMessageId)
{
$this->beginMessageId = $beginMessageId;
}
/**
* @return int
*/
public function getEndingMessageId(): int
{
return $this->endingMessageId;
}
/**
* @param int $endingMessageId
*/
public function setEndingMessageId(int $endingMessageId)
{
$this->endingMessageId = $endingMessageId;
}
/**
* @return \DateTime
*/
public function getClosedAt(): \DateTime
{
return $this->closedAt;
}
/**
* @param \DateTime $closedAt
*/
public function setClosedAt(\DateTime $closedAt)
{
$this->closedAt = $closedAt;
}
/**
* @return bool
*/
public function isAssigned(): bool
{
return $this->isAssigned;
}
/**
* @param bool $isAssigned
*/
public function setIsAssigned(bool $isAssigned)
{
$this->isAssigned = $isAssigned;
}
/**
* @return Responsible
*/
public function getResponsible(): Responsible
{
return $this->responsible;
}
/**
* @param Responsible $responsible
*/
public function setResponsible(Responsible $responsible)
{
$this->responsible = $responsible;
}
/**
* @return bool
*/
public function isActive(): bool
{
return $this->isActive;
}
/**
* @param bool $isActive
*/
public function setIsActive(bool $isActive)
{
$this->isActive = $isActive;
}
}

View file

@ -0,0 +1,81 @@
<?php
/**
* PHP version 7.0
*
* FileMeta entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* FileMeta class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class FileMeta
{
/**
* @var int $height
*
* @Type("int")
* @Accessor(getter="getHeight",setter="setHeight")
* @SkipWhenEmpty()
*/
private $height;
/**
* @var int $width
*
* @Type("int")
* @Accessor(getter="getWidth",setter="setWidth")
* @SkipWhenEmpty()
*/
private $width;
/**
* @return int
*/
public function getHeight(): int
{
return $this->height;
}
/**
* @param int $height
*/
public function setHeight(int $height)
{
$this->height = $height;
}
/**
* @return int
*/
public function getWidth(): int
{
return $this->width;
}
/**
* @param int $width
*/
public function setWidth(int $width)
{
$this->width = $width;
}
}

View file

@ -5,13 +5,13 @@
*
* Item entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @package RetailCrm\Mg\Bot\Model\Entity\Message
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
@ -22,7 +22,7 @@ use JMS\Serializer\Annotation\Type;
*
* Item class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @package RetailCrm\Mg\Bot\Model\Entity\Message
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
@ -38,6 +38,15 @@ class Item
*/
private $id;
/**
* @var int $size
*
* @Type("int")
* @Accessor(getter="getSize",setter="setSize")
* @SkipWhenEmpty()
*/
private $size;
/**
* @var string $caption
*
@ -63,6 +72,22 @@ class Item
$this->id = $id;
}
/**
* @return int
*/
public function getSize(): int
{
return $this->size;
}
/**
* @param int $size
*/
public function setSize(int $size)
{
$this->size = $size;
}
/**
* @return string
*/

View file

@ -0,0 +1,531 @@
<?php
/**
* PHP version 7.0
*
* Message entity
*
* @package RetailCrm\Mg\Bot\Model\Entity\Message
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use RetailCrm\Mg\Bot\Model\Entity\Dialog;
use RetailCrm\Mg\Bot\Model\Entity\User;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* Message class
*
* @package RetailCrm\Mg\Bot\Model\Entity\Message
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Message
{
/**
* @var string $id
*
* @Type("string")
* @Accessor(getter="getId",setter="setId")
*/
private $id;
/**
* @var \DateTime $createdAt
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getCreatedAt",setter="setCreatedAt")
*/
private $createdAt;
/**
* @var \DateTime $updatedAt
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getUpdatedAt",setter="setUpdatedAt")
* @SkipWhenEmpty()
*/
private $updatedAt;
/**
* @var string $actions
*
* @Type("string")
* @Accessor(getter="getActions",setter="setActions")
* @SkipWhenEmpty()
*/
private $actions;
/**
* @var array $items
*
* @Type("array")
* @Accessor(getter="getItems",setter="setItems")
* @SkipWhenEmpty()
*/
private $items;
/**
* @var User $from
*
* @Type("RetailCrm\Mg\Bot\Model\Entity\User")
* @Accessor(getter="getFrom",setter="setFrom")
* @SkipWhenEmpty()
*/
private $from;
/**
* @var \DateTime $time
*
* @Type("DateTime<'Y-m-d\TH:i:sP'>")
* @Accessor(getter="getTime",setter="setTime")
* @SkipWhenEmpty()
*/
private $time;
/**
* @var string $type
*
* @Type("string")
* @Accessor(getter="getType",setter="setType")
* @SkipWhenEmpty()
*/
private $type;
/**
* @var string $scope
*
* @Type("string")
* @Accessor(getter="getScope",setter="setScope")
* @SkipWhenEmpty()
*/
private $scope;
/**
* @var int $chatId
*
* @Type("int")
* @Accessor(getter="getChatId",setter="setChatId")
* @SkipWhenEmpty()
*/
private $chatId;
/**
* @var string $content
*
* @Type("string")
* @Accessor(getter="getContent",setter="setContent")
* @SkipWhenEmpty()
*/
private $content;
/**
* @var bool $isRead
*
* @Type("bool")
* @Accessor(getter="getIsRead",setter="setIsRead")
* @SkipWhenEmpty()
*/
private $isRead;
/**
* @var bool $isEdit
*
* @Type("bool")
* @Accessor(getter="getIsEdit",setter="setIsEdit")
* @SkipWhenEmpty()
*/
private $isEdit;
/**
* @var string $status
*
* @Type("string")
* @Accessor(getter="getStatus",setter="setStatus")
* @SkipWhenEmpty()
*/
private $status;
/**
* @var string $action
*
* @Type("string")
* @Accessor(getter="getAction",setter="setAction")
* @SkipWhenEmpty()
*/
private $action;
/**
* @var Dialog $dialog
*
* @Type("Dialog")
* @Accessor(getter="getDialog",setter="setDialog")
* @SkipWhenEmpty()
*/
private $dialog;
/**
* @var int $channelId
*
* @Type("int")
* @Accessor(getter="getChannelId",setter="setChannelId")
* @SkipWhenEmpty()
*/
private $channelId;
/**
* @var \DateTime $channelSentAt
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getChannelSentAt",setter="setChannelSentAt")
* @SkipWhenEmpty()
*/
private $channelSentAt;
/**
* @var MessageOrder $order
*
* @Type("MessageOrder")
* @Accessor(getter="getOrder",setter="setOrder")
* @SkipWhenEmpty()
*/
private $order;
/**
* @var MessageProduct $product
*
* @Type("MessageProduct")
* @Accessor(getter="getProduct",setter="setProduct")
* @SkipWhenEmpty()
*/
private $product;
/**
* @return string
*/
public function getId(): string
{
return $this->id;
}
/**
* @param string $id
*/
public function setId(string $id)
{
$this->id = $id;
}
/**
* @return \DateTime
*/
public function getCreatedAt(): \DateTime
{
return $this->createdAt;
}
/**
* @param \DateTime $createdAt
*/
public function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
}
/**
* @return \DateTime
*/
public function getUpdatedAt(): \DateTime
{
return $this->updatedAt;
}
/**
* @param \DateTime $updatedAt
*/
public function setUpdatedAt(\DateTime $updatedAt)
{
$this->updatedAt = $updatedAt;
}
/**
* @return string
*/
public function getActions(): string
{
return $this->actions;
}
/**
* @param string $actions
*/
public function setActions(string $actions)
{
$this->actions = $actions;
}
/**
* @return array
*/
public function getItems(): array
{
return $this->items;
}
/**
* @param array $items
*/
public function setItems(array $items)
{
$this->items = $items;
}
/**
* @return User
*/
public function getFrom(): User
{
return $this->from;
}
/**
* @param User $from
*/
public function setFrom(User $from)
{
$this->from = $from;
}
/**
* @return \DateTime
*/
public function getTime(): \DateTime
{
return $this->time;
}
/**
* @param \DateTime $time
*/
public function setTime(\DateTime $time)
{
$this->time = $time;
}
/**
* @return string
*/
public function getType(): string
{
return $this->type;
}
/**
* @param string $type
*/
public function setType(string $type)
{
$this->type = $type;
}
/**
* @return string
*/
public function getScope(): string
{
return $this->scope;
}
/**
* @param string $scope
*/
public function setScope(string $scope)
{
$this->scope = $scope;
}
/**
* @return int
*/
public function getChatId(): int
{
return $this->chatId;
}
/**
* @param int $chatId
*/
public function setChatId(int $chatId)
{
$this->chatId = $chatId;
}
/**
* @return string
*/
public function getContent(): string
{
return $this->content;
}
/**
* @param string $content
*/
public function setContent(string $content)
{
$this->content = $content;
}
/**
* @return bool
*/
public function isRead(): bool
{
return $this->isRead;
}
/**
* @param bool $isRead
*/
public function setIsRead(bool $isRead)
{
$this->isRead = $isRead;
}
/**
* @return bool
*/
public function isEdit(): bool
{
return $this->isEdit;
}
/**
* @param bool $isEdit
*/
public function setIsEdit(bool $isEdit)
{
$this->isEdit = $isEdit;
}
/**
* @return string
*/
public function getStatus(): string
{
return $this->status;
}
/**
* @param string $status
*/
public function setStatus(string $status)
{
$this->status = $status;
}
/**
* @return string
*/
public function getAction(): string
{
return $this->action;
}
/**
* @param string $action
*/
public function setAction(string $action)
{
$this->action = $action;
}
/**
* @return Dialog
*/
public function getDialog(): Dialog
{
return $this->dialog;
}
/**
* @param Dialog $dialog
*/
public function setDialog(Dialog $dialog)
{
$this->dialog = $dialog;
}
/**
* @return int
*/
public function getChannelId(): int
{
return $this->channelId;
}
/**
* @param int $channelId
*/
public function setChannelId(int $channelId)
{
$this->channelId = $channelId;
}
/**
* @return \DateTime
*/
public function getChannelSentAt(): \DateTime
{
return $this->channelSentAt;
}
/**
* @param \DateTime $channelSentAt
*/
public function setChannelSentAt(\DateTime $channelSentAt)
{
$this->channelSentAt = $channelSentAt;
}
/**
* @return MessageOrder
*/
public function getOrder(): MessageOrder
{
return $this->order;
}
/**
* @param MessageOrder $order
*/
public function setOrder(MessageOrder $order)
{
$this->order = $order;
}
/**
* @return MessageProduct
*/
public function getProduct(): MessageProduct
{
return $this->product;
}
/**
* @param MessageProduct $product
*/
public function setProduct(MessageProduct $product)
{
$this->product = $product;
}
}

View file

@ -3,15 +3,15 @@
/**
* PHP version 7.0
*
* Cost entity
* MessageCost entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @package RetailCrm\Mg\Bot\Model\Entity\Message
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
@ -20,14 +20,14 @@ use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* Cost class
* MessageCost class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @package RetailCrm\Mg\Bot\Model\Entity\Message
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Cost
class MessageCost
{
/**
* @var float $value

View file

@ -3,31 +3,32 @@
/**
* PHP version 7.0
*
* Delivery entity
* MessageDelivery entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @package RetailCrm\Mg\Bot\Model\Entity\Message
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\Entity\Message\MessageCost;
/**
* PHP version 7.0
*
* Delivery class
* MessageDelivery class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @package RetailCrm\Mg\Bot\Model\Entity\Message
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Delivery
class MessageDelivery
{
/**
* @var string $name
@ -40,7 +41,7 @@ class Delivery
private $name;
/**
* @var Cost $price
* @var MessageCost $price
*
* @Type("Cost")
* @Accessor(getter="getPrice",setter="setPrice")
@ -84,7 +85,7 @@ class Delivery
}
/**
* @return Cost
* @return MessageCost
*/
public function getPrice()
{
@ -92,9 +93,9 @@ class Delivery
}
/**
* @param Cost $price
* @param MessageCost $price
*/
public function setPrice(Cost $price)
public function setPrice(MessageCost $price)
{
$this->price = $price;
}

View file

@ -3,15 +3,15 @@
/**
* PHP version 7.0
*
* Order entity
* MessageOrder entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @package RetailCrm\Mg\Bot\Model\Entity\Message
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
@ -20,14 +20,14 @@ use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* Order class
* MessageOrder class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @package RetailCrm\Mg\Bot\Model\Entity\Message
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Order
class MessageOrder
{
/**
* @var string $number
@ -57,27 +57,27 @@ class Order
private $date;
/**
* @var Cost $cost
* @var MessageCost $cost
*
* @Type("Cost")
* @Type("MessageCost")
* @Accessor(getter="getCost",setter="setCost")
* @SkipWhenEmpty()
*/
private $cost;
/**
* @var Status $status
* @var MessageStatus $status
*
* @Type("Status")
* @Type("MessageStatus")
* @Accessor(getter="getStatus",setter="setStatus")
* @SkipWhenEmpty()
*/
private $status;
/**
* @var Delivery $delivery
* @var MessageDelivery $delivery
*
* @Type("Delivery")
* @Type("MessageDelivery")
* @Accessor(getter="getDelivery",setter="setDelivery")
* @SkipWhenEmpty()
*/
@ -150,7 +150,7 @@ class Order
}
/**
* @return Cost
* @return MessageCost
*/
public function getCost()
{
@ -158,15 +158,15 @@ class Order
}
/**
* @param Cost $cost
* @param MessageCost $cost
*/
public function setCost(Cost $cost)
public function setCost(MessageCost $cost)
{
$this->cost = $cost;
}
/**
* @return Status
* @return MessageStatus
*/
public function getStatus()
{
@ -174,15 +174,15 @@ class Order
}
/**
* @param Status $status
* @param MessageStatus $status
*/
public function setStatus(Status $status)
public function setStatus(MessageStatus $status)
{
$this->status = $status;
}
/**
* @return Delivery
* @return MessageDelivery
*/
public function getDelivery()
{
@ -190,9 +190,9 @@ class Order
}
/**
* @param Delivery $delivery
* @param MessageDelivery $delivery
*/
public function setDelivery(Delivery $delivery)
public function setDelivery(MessageDelivery $delivery)
{
$this->delivery = $delivery;
}

View file

@ -1,36 +1,36 @@
<?php
/**
* PHP version 7.0
* PHP version 7.0.
*
* Order item entity
* MessageOrderItem entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*
* @see http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
* PHP version 7.0.
*
* OrderItem class
* MessageOrderItem class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*
* @see http://help.retailcrm.pro/docs/Developers
*/
class OrderItem
class MessageOrderItem
{
/**
* @var string $name
* @var string
*
* @Type("string")
* @Accessor(getter="getName",setter="setName")
@ -39,7 +39,7 @@ class OrderItem
private $name;
/**
* @var string $url
* @var string
*
* @Type("string")
* @Accessor(getter="getUrl",setter="setUrl")
@ -48,7 +48,7 @@ class OrderItem
private $url;
/**
* @var string $img
* @var string
*
* @Type("string")
* @Accessor(getter="getImg",setter="setImg")
@ -57,18 +57,18 @@ class OrderItem
private $img;
/**
* @var Cost $price
* @var MessageCost
*
* @Type("Cost")
* @Type("MessageCost")
* @Accessor(getter="getPrice",setter="setPrice")
* @SkipWhenEmpty()
*/
private $price;
/**
* @var Quantity $quantity
* @var MessageQuantity
*
* @Type("Quantity")
* @Type("MessageQuantity")
* @Accessor(getter="getQuantity",setter="setQuantity)
* @SkipWhenEmpty()
*/
@ -123,7 +123,7 @@ class OrderItem
}
/**
* @return Cost
* @return MessageCost
*/
public function getPrice()
{
@ -131,15 +131,15 @@ class OrderItem
}
/**
* @param Cost $price
* @param MessageCost $price
*/
public function setPrice(Cost $price)
public function setPrice(MessageCost $price)
{
$this->price = $price;
}
/**
* @return Quantity
* @return MessageQuantity
*/
public function getQuantity()
{
@ -147,9 +147,9 @@ class OrderItem
}
/**
* @param Quantity $quantity
* @param MessageQuantity $quantity
*/
public function setQuantity(Quantity $quantity)
public function setQuantity(MessageQuantity $quantity)
{
$this->quantity = $quantity;
}

View file

@ -3,15 +3,15 @@
/**
* PHP version 7.0
*
* Payment status entity
* MessageOrderPaymentStatus entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @package RetailCrm\Mg\Bot\Model\Entity\Message
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
@ -20,14 +20,14 @@ use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* PaymentStatus class
* MessageOrderPaymentStatus class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @package RetailCrm\Mg\Bot\Model\Entity\Message
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class PaymentStatus
class MessageOrderPaymentStatus
{
/**
* @var string $name
@ -39,7 +39,7 @@ class PaymentStatus
private $name;
/**
* @var bool $payed
* @var bool $name
*
* @Type("bool")
* @Accessor(getter="getPayed",setter="setPayed")
@ -50,7 +50,7 @@ class PaymentStatus
/**
* @return string
*/
public function getName()
public function getName(): string
{
return $this->name;
}
@ -66,7 +66,7 @@ class PaymentStatus
/**
* @return bool
*/
public function isPayed()
public function getPayed(): bool
{
return $this->payed;
}

View file

@ -3,15 +3,15 @@
/**
* PHP version 7.0
*
* Payment entity
* MessagePayment entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @package RetailCrm\Mg\Bot\Model\Entity\Message
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
@ -20,14 +20,14 @@ use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* Payment class
* MessagePayment class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @package RetailCrm\Mg\Bot\Model\Entity\Message
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Payment
class MessagePayment
{
/**
* @var string $name
@ -39,18 +39,18 @@ class Payment
private $name;
/**
* @var PaymentStatus $status
* @var MessageOrderPaymentStatus $status
*
* @Type("PaymentStatus")
* @Type("MessageOrderPaymentStatus")
* @Accessor(getter="getStatus",setter="setStatus")
* @SkipWhenEmpty()
*/
private $status;
/**
* @var Cost $amount
* @var MessageCost $amount
*
* @Type("Cost")
* @Type("MessageCost")
* @Accessor(getter="getAmount",setter="setAmount")
* @SkipWhenEmpty()
*/
@ -73,7 +73,7 @@ class Payment
}
/**
* @return PaymentStatus
* @return MessageOrderPaymentStatus
*/
public function getStatus()
{
@ -81,15 +81,15 @@ class Payment
}
/**
* @param PaymentStatus $status
* @param MessageOrderPaymentStatus $status
*/
public function setStatus(PaymentStatus $status)
public function setStatus(MessageOrderPaymentStatus $status)
{
$this->status = $status;
}
/**
* @return Cost
* @return MessageCost
*/
public function getAmount()
{
@ -97,9 +97,9 @@ class Payment
}
/**
* @param Cost $amount
* @param MessageCost $amount
*/
public function setAmount(Cost $amount)
public function setAmount(MessageCost $amount)
{
$this->amount = $amount;
}

View file

@ -3,15 +3,15 @@
/**
* PHP version 7.0
*
* Product entity
* MessageProduct entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @package RetailCrm\Mg\Bot\Model\Entity\Message
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
@ -20,14 +20,14 @@ use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* Product class
* MessageProduct class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @package RetailCrm\Mg\Bot\Model\Entity\Message
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Product
class MessageProduct
{
/**
* @var int $id
@ -75,7 +75,7 @@ class Product
private $img;
/**
* @var Cost $cost
* @var MessageCost $cost
*
* @Type("Cost")
* @Accessor(getter="getCost",setter="setCost")
@ -84,9 +84,9 @@ class Product
private $cost;
/**
* @var Quantity $quantity
* @var MessageQuantity $quantity
*
* @Type("Quantity")
* @Type("MessageQuantity")
* @Accessor(getter="getQuantity",setter="setQuantity)
* @SkipWhenEmpty()
*/
@ -111,7 +111,7 @@ class Product
/**
* @return string
*/
public function getName()
public function getName(): string
{
return $this->name;
}
@ -127,7 +127,7 @@ class Product
/**
* @return string
*/
public function getArticle()
public function getArticle(): string
{
return $this->article;
}
@ -143,7 +143,7 @@ class Product
/**
* @return string
*/
public function getUrl()
public function getUrl(): string
{
return $this->url;
}
@ -159,7 +159,7 @@ class Product
/**
* @return string
*/
public function getImg()
public function getImg(): string
{
return $this->img;
}
@ -173,33 +173,33 @@ class Product
}
/**
* @return Cost
* @return MessageCost
*/
public function getCost()
public function getCost(): MessageCost
{
return $this->cost;
}
/**
* @param Cost $cost
* @param MessageCost $cost
*/
public function setCost(Cost $cost)
public function setCost(MessageCost $cost)
{
$this->cost = $cost;
}
/**
* @return Quantity
* @return MessageQuantity
*/
public function getQuantity()
public function getQuantity(): MessageQuantity
{
return $this->quantity;
}
/**
* @param Quantity $quantity
* @param MessageQuantity $quantity
*/
public function setQuantity(Quantity $quantity)
public function setQuantity(MessageQuantity $quantity)
{
$this->quantity = $quantity;
}

View file

@ -3,15 +3,15 @@
/**
* PHP version 7.0
*
* Quantity entity
* MessageQuantity entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @package RetailCrm\Mg\Bot\Model\Entity\Message
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
@ -20,14 +20,14 @@ use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* Quantity class
* MessageQuantity class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @package RetailCrm\Mg\Bot\Model\Entity\Message
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Quantity
class MessageQuantity
{
/**
* @var float $value

View file

@ -3,15 +3,15 @@
/**
* PHP version 7.0
*
* Status entity
* MessageStatus entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @package RetailCrm\Mg\Bot\Model\Entity\Message
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
namespace RetailCrm\Mg\Bot\Model\Entity\Message;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
@ -20,14 +20,14 @@ use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* Status class
* MessageStatus class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @package RetailCrm\Mg\Bot\Model\Entity\Message
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Status
class MessageStatus
{
/**
* @var string $code
@ -50,7 +50,7 @@ class Status
/**
* @return string
*/
public function getCode()
public function getCode(): string
{
return $this->code;
}
@ -66,7 +66,7 @@ class Status
/**
* @return string
*/
public function getName()
public function getName(): string
{
return $this->name;
}

View file

@ -0,0 +1,106 @@
<?php
/**
* PHP version 7.0
*
* Responsible entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* Responsible class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Responsible
{
/**
* @var string $assignedAt
*
* @Type("string")
* @Accessor(getter="getAssignedAt",setter="setAssignedAt")
* @SkipWhenEmpty()
*/
private $assignedAt;
/**
* @var int $id
*
* @Type("int")
* @Accessor(getter="getId",setter="setId")
* @SkipWhenEmpty()
*/
private $id;
/**
* @var string $type
*
* @Type("string")
* @Accessor(getter="getType",setter="setType")
* @SkipWhenEmpty()
*/
private $type;
/**
* @return string
*/
public function getAssignedAt(): string
{
return $this->assignedAt;
}
/**
* @param string $assignedAt
*/
public function setAssignedAt(string $assignedAt)
{
$this->assignedAt = $assignedAt;
}
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @param int $id
*/
public function setId(int $id)
{
$this->id = $id;
}
/**
* @return string
*/
public function getType(): string
{
return $this->type;
}
/**
* @param string $type
*/
public function setType(string $type)
{
$this->type = $type;
}
}

View file

@ -0,0 +1,359 @@
<?php
/**
* PHP version 7.0
*
* User entity
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Entity;
use Symfony\Component\Validator\Constraints as Assert;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* User class
*
* @package RetailCrm\Mg\Bot\Model\Entity
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class User
{
/**
* @var string $id
*
* @Type("string")
* @Accessor(getter="getId",setter="setId")
*/
private $id;
/**
* @var \DateTime $createdAt
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getCreatedAt",setter="setCreatedAt")
*/
private $createdAt;
/**
* @var \DateTime $updatedAt
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getUpdatedAt",setter="setUpdatedAt")
* @SkipWhenEmpty()
*/
private $updatedAt;
/**
* @var string $externalId
*
* @Type("string")
* @Accessor(getter="getExternalId",setter="setExternalId")
* @SkipWhenEmpty()
* @Assert\Length(max="64")
*/
private $externalId;
/**
* @var string $type
*
* @Type("string")
* @Accessor(getter="getType",setter="setType")
* @SkipWhenEmpty()
*/
private $type;
/**
* @var string $avatar
*
* @Type("string")
* @Accessor(getter="getAvatar",setter="setAvatar")
* @SkipWhenEmpty()
*/
private $avatar;
/**
* @var string $name
*
* @Type("string")
* @Accessor(getter="getName",setter="setName")
* @SkipWhenEmpty()
*/
private $name;
/**
* @var string $username
*
* @Type("string")
* @Accessor(getter="getUsername",setter="setUsername")
* @SkipWhenEmpty()
* @Assert\Length(max="255")
*/
private $username;
/**
* @var string $firstName
*
* @Type("string")
* @Accessor(getter="getFirstName",setter="setFirstName")
* @SkipWhenEmpty()
* @Assert\Length(max="255")
*/
private $firstName;
/**
* @var string $lastName
*
* @Type("string")
* @Accessor(getter="getLastName",setter="setLastName")
* @SkipWhenEmpty()
* @Assert\Length(max="255")
*/
private $lastName;
/**
* @var bool $isActive
*
* @Type("bool")
* @Accessor(getter="getIsActive",setter="setIsActive")
* @SkipWhenEmpty()
*/
private $isActive;
/**
* @var bool $isOnline
*
* @Type("bool")
* @Accessor(getter="getIsOnline",setter="setIsOnline")
* @SkipWhenEmpty()
*/
private $isOnline;
/**
* @var \DateTime $revokedAt
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getRevokedAt",setter="setRevokedAt")
* @SkipWhenEmpty()
*/
private $revokedAt;
/**
* @return string
*/
public function getId(): string
{
return $this->id;
}
/**
* @param string $id
*/
public function setId(string $id)
{
$this->id = $id;
}
/**
* @return \DateTime
*/
public function getCreatedAt(): \DateTime
{
return $this->createdAt;
}
/**
* @param \DateTime $createdAt
*/
public function setCreatedAt(\DateTime $createdAt)
{
$this->createdAt = $createdAt;
}
/**
* @return \DateTime
*/
public function getUpdatedAt(): \DateTime
{
return $this->updatedAt;
}
/**
* @param \DateTime $updatedAt
*/
public function setUpdatedAt(\DateTime $updatedAt)
{
$this->updatedAt = $updatedAt;
}
/**
* @return string
*/
public function getExternalId(): string
{
return $this->externalId;
}
/**
* @param string $externalId
*/
public function setExternalId(string $externalId)
{
$this->externalId = $externalId;
}
/**
* @return string
*/
public function getType(): string
{
return $this->type;
}
/**
* @param string $type
*/
public function setType(string $type)
{
$this->type = $type;
}
/**
* @return string
*/
public function getAvatar(): string
{
return $this->avatar;
}
/**
* @param string $avatar
*/
public function setAvatar(string $avatar)
{
$this->avatar = $avatar;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name)
{
$this->name = $name;
}
/**
* @return string
*/
public function getUsername(): string
{
return $this->username;
}
/**
* @param string $username
*/
public function setUsername(string $username)
{
$this->username = $username;
}
/**
* @return string
*/
public function getFirstName(): string
{
return $this->firstName;
}
/**
* @param string $firstName
*/
public function setFirstName(string $firstName)
{
$this->firstName = $firstName;
}
/**
* @return string
*/
public function getLastName(): string
{
return $this->lastName;
}
/**
* @param string $lastName
*/
public function setLastName(string $lastName)
{
$this->lastName = $lastName;
}
/**
* @return bool
*/
public function isActive(): bool
{
return $this->isActive;
}
/**
* @param bool $isActive
*/
public function setIsActive(bool $isActive)
{
$this->isActive = $isActive;
}
/**
* @return bool
*/
public function isOnline(): bool
{
return $this->isOnline;
}
/**
* @param bool $isOnline
*/
public function setIsOnline(bool $isOnline)
{
$this->isOnline = $isOnline;
}
/**
* @return \DateTime
*/
public function getRevokedAt(): \DateTime
{
return $this->revokedAt;
}
/**
* @param \DateTime $revokedAt
*/
public function setRevokedAt(\DateTime $revokedAt)
{
$this->revokedAt = $revokedAt;
}
}

View file

@ -13,6 +13,7 @@
namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation as Serializer;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
@ -35,8 +36,7 @@ class CommandEditRequest
*
* @Type("int")
* @Accessor(getter="getBotId",setter="setBotId")
*
* @Assert\NotBlank
* @SkipWhenEmpty()
*/
private $botId;
@ -45,8 +45,7 @@ class CommandEditRequest
*
* @Type("string")
* @Accessor(getter="getName",setter="setName")
*
* @Assert\NotBlank
* @SkipWhenEmpty()
*/
private $name;

View file

@ -30,6 +30,8 @@ use JMS\Serializer\Annotation\Type;
trait CommonFields
{
/**
* @var int
*
* @Type("int")
* @Accessor(getter="getId",setter="setId")
* @SkipWhenEmpty
@ -37,14 +39,18 @@ trait CommonFields
private $id;
/**
* @Type("string")
* @var \DateTime
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getSince",setter="setSince")
* @SkipWhenEmpty
*/
private $since;
/**
* @Type("string")
* @var \DateTime
*
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
* @Accessor(getter="getUntil",setter="setUntil")
* @SkipWhenEmpty
*/
@ -67,7 +73,7 @@ trait CommonFields
}
/**
* @return string
* @return \DateTime
*/
public function getSince()
{
@ -75,15 +81,15 @@ trait CommonFields
}
/**
* @param string $since
* @param \DateTime $since
*/
public function setSince($since)
public function setSince(\DateTime $since)
{
$this->since = $since;
}
/**
* @return string
* @return \DateTime
*/
public function getUntil()
{
@ -91,9 +97,9 @@ trait CommonFields
}
/**
* @param string $until
* @param \DateTime $until
*/
public function setUntil($until)
public function setUntil(\DateTime $until)
{
$this->until = $until;
}

View file

@ -16,6 +16,7 @@ namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\Request\CommonFields;
/**
* PHP version 7.0

View file

@ -13,6 +13,7 @@
namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation as Serializer;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
@ -33,8 +34,8 @@ class DialogAssignRequest
* @var int $dialogId
*
* @Type("int")
* @Accessor(getter="getDialogId,setter="setDialogId")
* @SkipWhenEmpty
* @Accessor(getter="getDialogId", setter="setDialogId")
* @SkipWhenEmpty()
*/
private $dialogId;
@ -42,8 +43,8 @@ class DialogAssignRequest
* @var int $userId
*
* @Type("int")
* @Accessor(getter="getUserId",setter="setUserId")
* @SkipWhenEmpty
* @Accessor(getter="getUserId", setter="setUserId")
* @SkipWhenEmpty()
*/
private $userId;
@ -51,7 +52,7 @@ class DialogAssignRequest
* @var int $botId
*
* @Type("int")
* @Accessor(getter="getBotId",setter="setBotId")
* @Accessor(getter="getBotId", setter="setBotId")
* @SkipWhenEmpty()
*/
private $botId;
@ -67,7 +68,7 @@ class DialogAssignRequest
/**
* @param int $dialogId
*/
public function setDialogId(int $dialogId)
public function setDialogId($dialogId)
{
$this->dialogId = $dialogId;
}

View file

@ -16,6 +16,8 @@ namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\Entity\Message\MessageOrder;
use RetailCrm\Mg\Bot\Model\Entity\Message\MessageProduct;
use Symfony\Component\Validator\Constraints as Assert;
use RetailCrm\Mg\Bot\Model\Entity\Order;
use RetailCrm\Mg\Bot\Model\Entity\Product;
@ -52,7 +54,7 @@ class MessageSendRequest
private $content;
/**
* @var Product $product
* @var MessageProduct $product
*
* @Type("Product")
* @Accessor(getter="getProduct",setter="setProduct")
@ -61,7 +63,7 @@ class MessageSendRequest
private $product;
/**
* @var Order $order
* @var MessageOrder $order
*
* @Type("Order")
* @Accessor(getter="getOrder",setter="setOrder")
@ -174,7 +176,7 @@ class MessageSendRequest
}
/**
* @return Product
* @return MessageProduct
*/
public function getProduct()
{
@ -182,15 +184,15 @@ class MessageSendRequest
}
/**
* @param Product $product
* @param MessageProduct $product
*/
public function setProduct(Product $product)
public function setProduct(MessageProduct $product)
{
$this->product = $product;
}
/**
* @return Order
* @return MessageOrder
*/
public function getOrder()
{
@ -198,9 +200,9 @@ class MessageSendRequest
}
/**
* @param Order $order
* @param MessageOrder $order
*/
public function setOrder(Order $order)
public function setOrder(MessageOrder $order)
{
$this->order = $order;
}

View file

@ -0,0 +1,57 @@
<?php
/**
* PHP version 7.0
*
* Upload file by url request
*
* @package RetailCrm\Mg\Bot\Model\Request
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Request;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\Type;
use Symfony\Component\Validator\Constraints as Assert;
/**
* PHP version 7.0
*
* UploadFileByUrlRequest class
*
* @package RetailCrm\Mg\Bot\Model\Request
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class UploadFileByUrlRequest
{
/**
* @var string $url
*
* @Type("string")
* @Accessor(getter="getUrl",setter="setUrl")
* @Assert\NotBlank()
* @Assert\Url()
*/
private $url;
/**
* @return string
*/
public function getUrl(): string
{
return $this->url;
}
/**
* @param string $url
*/
public function setUrl(string $url)
{
$this->url = $url;
}
}

View file

@ -0,0 +1,134 @@
<?php
/**
* PHP version 7.0
*
* AssignResponse
*
* @package RetailCrm\Mg\Bot\Model\Response
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Response;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\Entity\Responsible;
/**
* PHP version 7.0
*
* AssignResponse class
*
* @package RetailCrm\Mg\Bot\Model\Response
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class AssignResponse
{
use CommonFields;
/**
* @var bool $isReassign
*
* @Type("bool")
* @Accessor(getter="getIsReassign",setter="setIsReassign")
* @SkipWhenEmpty()
*/
private $isReassign;
/**
* @var int $leftManagerId
*
* @Type("int")
* @Accessor(getter="getLeftManagerId",setter="setLeftManagerId")
* @SkipWhenEmpty()
*/
private $leftManagerId;
/**
* @var Responsible $previousResponsible
*
* @Type("RetailCrm\Mg\Bot\Model\Entity\Responsible")
* @Accessor(getter="getPreviousResponsible",setter="setPreviousResponsible")
* @SkipWhenEmpty()
*/
private $previousResponsible;
/**
* @var Responsible $responsible
*
* @Type("RetailCrm\Mg\Bot\Model\Entity\Responsible")
* @Accessor(getter="getResponsible",setter="setResponsible")
* @SkipWhenEmpty()
*/
private $responsible;
/**
* @return bool
*/
public function getIsReassign(): bool
{
return $this->isReassign;
}
/**
* @param bool $isReassign
*/
public function setIsReassign(bool $isReassign)
{
$this->isReassign = $isReassign;
}
/**
* @return int
*/
public function getLeftManagerId(): int
{
return $this->leftManagerId;
}
/**
* @param int $leftManagerId
*/
public function setLeftManagerId(int $leftManagerId)
{
$this->leftManagerId = $leftManagerId;
}
/**
* @return Responsible
*/
public function getPreviousResponsible(): Responsible
{
return $this->previousResponsible;
}
/**
* @param Responsible $previousResponsible
*/
public function setPreviousResponsible(Responsible $previousResponsible)
{
$this->previousResponsible = $previousResponsible;
}
/**
* @return Responsible
*/
public function getResponsible(): Responsible
{
return $this->responsible;
}
/**
* @param Responsible $responsible
*/
public function setResponsible(Responsible $responsible)
{
$this->responsible = $responsible;
}
}

View file

@ -0,0 +1,87 @@
<?php
/**
* PHP version 7.0
*
* ErrorTrait
*
* @package RetailCrm\Mg\Bot\Model\Response
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Response;
use JMS\Serializer\Annotation\Exclude;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* CommonFields trait
*
* @package RetailCrm\Mg\Bot\Model\Response
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
trait CommonFields
{
/**
* @var array $errors
*
* @Type("array")
* @Accessor(getter="getErrors",setter="setErrors")
* @SkipWhenEmpty()
*/
private $errors;
/**
* @var int $statusCode
* @Exclude()
*/
private $statusCode;
/**
* @return array
*/
public function getErrors(): array
{
return is_null($this->errors) ? [] : $this->errors;
}
/**
* @param array $errors
*/
public function setErrors(array $errors)
{
$this->errors = $errors;
}
/**
* @return int
*/
public function getStatusCode(): int
{
return $this->statusCode;
}
/**
* @param int $statusCode
*/
public function setStatusCode(int $statusCode)
{
$this->statusCode = $statusCode;
}
/**
* @return bool
*/
public function isSuccessful()
{
return empty($this->errors);
}
}

View file

@ -3,28 +3,27 @@
/**
* PHP version 7.0
*
* CurlException
* ErrorOnlyResponse
*
* @package RetailCrm\Common\Exception
* @package RetailCrm\Mg\Bot\Model\Response
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Common\Exception;
use RuntimeException;
namespace RetailCrm\Mg\Bot\Model\Response;
/**
* PHP version 7.0
*
* Class CurlException
* ErrorOnlyResponse class
*
* @package RetailCrm\Common\Exception
* @package RetailCrm\Mg\Bot\Model\Response
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class CurlException extends RuntimeException
class ErrorOnlyResponse
{
use CommonFields;
}

View file

@ -0,0 +1,133 @@
<?php
/**
* PHP version 7.0
*
* FullFileResponse
*
* @package RetailCrm\Mg\Bot\Model\Response
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Response;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* FullFileResponse class
*
* @package RetailCrm\Mg\Bot\Model\Response
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class FullFileResponse
{
use CommonFields;
/**
* @var string $id
*
* @Type("string")
* @Accessor(getter="getId",setter="setId")
* @SkipWhenEmpty()
*/
private $id;
/**
* @var int $size
*
* @Type("int")
* @Accessor(getter="getSize",setter="setSize")
* @SkipWhenEmpty()
*/
private $size;
/**
* @var string $type
*
* @Type("string")
* @Accessor(getter="getType",setter="setType")
* @SkipWhenEmpty()
*/
private $type;
/**
* @var string $url
*
* @Type("string")
* @Accessor(getter="getUrl",setter="setUrl")
* @SkipWhenEmpty()
*/
private $url;
/**
* @return string
*/
public function getId(): string
{
return $this->id;
}
/**
* @param string $id
*/
public function setId(string $id)
{
$this->id = $id;
}
/**
* @return int
*/
public function getSize(): int
{
return $this->size;
}
/**
* @param int $size
*/
public function setSize(int $size)
{
$this->size = $size;
}
/**
* @return string
*/
public function getType(): string
{
return $this->type;
}
/**
* @param string $type
*/
public function setType(string $type)
{
$this->type = $type;
}
/**
* @return string
*/
public function getUrl(): string
{
return $this->url;
}
/**
* @param string $url
*/
public function setUrl(string $url)
{
$this->url = $url;
}
}

View file

@ -0,0 +1,202 @@
<?php
/**
* PHP version 7.0
*
* ListResponse
*
* @package RetailCrm\Mg\Bot\Model\Response
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Response;
use RetailCrm\Common\Serializer;
/**
* PHP version 7.0
*
* ListResponse class. Used to store multiple objects at once.
* Implements `Iterator`, `ArrayAccess` and `Countable`.
*
* @package RetailCrm\Mg\Bot\Model\Response
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class ListResponse implements \Iterator, \ArrayAccess, \Countable
{
use CommonFields;
/**
* @var array
*/
private $items = [];
/**
* @var int
*/
private $position = 0;
/**
* ListResponse constructor.
*
* @param string $responseType
* @param array $data
* @param int $statusCode
*/
public function __construct($responseType, $data, $statusCode)
{
$this->setStatusCode($statusCode);
if (isset($data['errors'])) {
$this->setErrors($data['errors']);
} else {
foreach ($data as $item) {
$this->items[] =
Serializer::deserialize($item, $responseType, Serializer::S_ARRAY);
}
}
}
/**
* @return bool
*/
public function isSuccessful()
{
return empty($this->errors);
}
/**
* \Countable implementation
*
* @return int
*/
public function count(): int
{
return count($this->items ?: []);
}
/**
* Set offset
*
* @param mixed $offset offset value
* @param mixed $value value
*
* @return void
* @internal
*/
public function offsetSet($offset, $value)
{
throw new \BadMethodCallException(
"This call not allowed: offsetSet [$offset] [$value]"
);
}
/**
* Unset offset
*
* @param mixed $offset offset value
*
* @return void
* @internal
*/
public function offsetUnset($offset)
{
throw new \BadMethodCallException(
"This call not allowed: offsetSet [$offset]"
);
}
/**
* Check offset
*
* @param mixed $offset offset value
*
* @return bool
* @internal
*/
public function offsetExists($offset)
{
return isset($this->items[$offset]);
}
/**
* Get offset
*
* @param mixed $offset offset value
*
* @return mixed
* @internal
*/
public function offsetGet($offset)
{
if (!isset($this->items[$offset])) {
throw new \InvalidArgumentException("Item \"$offset\" not found");
}
return $this->items[$offset];
}
/**
* @param mixed $name
*
* @return mixed
* @internal
*/
public function __get($name)
{
return $this->items[$name];
}
/**
* Implements rewind() for Iterable
* @internal
*/
public function rewind()
{
$this->position = 0;
}
/**
* Implements current() for Iterable
*
* @internal
* @return mixed
*/
public function current()
{
return $this->items[$this->position];
}
/**
* Implements key() for Iterable
*
* @internal
* @return int|mixed
*/
public function key()
{
return $this->position;
}
/**
* Implements next() for Iterable
* @internal
*/
public function next()
{
++$this->position;
}
/**
* Implements valid() for Iterable
*
* @internal
* @return bool
*/
public function valid()
{
return isset($this->items[$this->position]);
}
}

View file

@ -0,0 +1,83 @@
<?php
/**
* PHP version 7.0
*
* MessageSendResponse
*
* @package RetailCrm\Mg\Bot\Model\Response
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Response;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* MessageSendResponse class
*
* @package RetailCrm\Mg\Bot\Model\Response
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class MessageSendResponse
{
use CommonFields;
/**
* @var int $messageId
*
* @Type("int")
* @Accessor(getter="getMessageId",setter="setMessageId")
* @SkipWhenEmpty()
*/
private $messageId;
/**
* @var string $time
*
* @Type("string")
* @Accessor(getter="getTime",setter="setTime")
* @SkipWhenEmpty()
*/
private $time;
/**
* @return int
*/
public function getMessageId(): int
{
return $this->messageId;
}
/**
* @param int $messageId
*/
public function setMessageId(int $messageId)
{
$this->messageId = $messageId;
}
/**
* @return string
*/
public function getTime(): string
{
return $this->time;
}
/**
* @param string $time
*/
public function setTime(string $time)
{
$this->time = $time;
}
}

View file

@ -0,0 +1,234 @@
<?php
/**
* PHP version 7.0
*
* UploadFileResponse
*
* @package RetailCrm\Mg\Bot\Model\Response
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Model\Response;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use RetailCrm\Mg\Bot\Model\Entity\FileMeta;
/**
* PHP version 7.0
*
* UploadFileResponse class
*
* @package RetailCrm\Mg\Bot\Model\Response
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class UploadFileResponse
{
use CommonFields;
/**
* @var string $createdAt
*
* @Type("string")
* @Accessor(getter="getCreatedAt",setter="setCreatedAt")
* @SkipWhenEmpty()
*/
private $createdAt;
/**
* @var string $hash
*
* @Type("string")
* @Accessor(getter="getHash",setter="setHash")
* @SkipWhenEmpty()
*/
private $hash;
/**
* @var string $id
*
* @Type("string")
* @Accessor(getter="getId",setter="setId")
* @SkipWhenEmpty()
*/
private $id;
/**
* @var FileMeta $meta
*
* @Type("FileMeta")
* @Accessor(getter="getMeta",setter="setMeta")
* @SkipWhenEmpty()
*/
private $meta;
/**
* @var string $mimeType
*
* @Type("string")
* @Accessor(getter="getMimeType",setter="setMimeType")
* @SkipWhenEmpty()
*/
private $mimeType;
/**
* @var int $size
*
* @Type("int")
* @Accessor(getter="getSize",setter="setSize")
* @SkipWhenEmpty()
*/
private $size;
/**
* @var string $time
*
* @Type("string")
* @Accessor(getter="getSourceUrl",setter="setSourceUrl")
* @SkipWhenEmpty()
*/
private $sourceUrl;
/**
* @var string $type
*
* @Type("string")
* @Accessor(getter="getType",setter="setType")
* @SkipWhenEmpty()
*/
private $type;
/**
* @return string
*/
public function getCreatedAt(): string
{
return $this->createdAt;
}
/**
* @param string $createdAt
*/
public function setCreatedAt(string $createdAt)
{
$this->createdAt = $createdAt;
}
/**
* @return string
*/
public function getHash(): string
{
return $this->hash;
}
/**
* @param string $hash
*/
public function setHash(string $hash)
{
$this->hash = $hash;
}
/**
* @return string
*/
public function getId(): string
{
return $this->id;
}
/**
* @param string $id
*/
public function setId(string $id)
{
$this->id = $id;
}
/**
* @return FileMeta
*/
public function getMeta(): FileMeta
{
return $this->meta;
}
/**
* @param FileMeta $meta
*/
public function setMeta(FileMeta $meta)
{
$this->meta = $meta;
}
/**
* @return string
*/
public function getMimeType(): string
{
return $this->mimeType;
}
/**
* @param string $mimeType
*/
public function setMimeType(string $mimeType)
{
$this->mimeType = $mimeType;
}
/**
* @return int
*/
public function getSize(): int
{
return $this->size;
}
/**
* @param int $size
*/
public function setSize(int $size)
{
$this->size = $size;
}
/**
* @return string
*/
public function getSourceUrl(): string
{
return $this->sourceUrl;
}
/**
* @param string $sourceUrl
*/
public function setSourceUrl(string $sourceUrl)
{
$this->sourceUrl = $sourceUrl;
}
/**
* @return string
*/
public function getType(): string
{
return $this->type;
}
/**
* @param string $type
*/
public function setType(string $type)
{
$this->type = $type;
}
}

View file

@ -1,205 +0,0 @@
<?php
/**
* PHP version 7.0
*
* Request
*
* @package RetailCrm\Mg\Bot
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot;
use RetailCrm\Common\Exception\CurlException;
use RetailCrm\Common\Exception\LimitException;
use Exception;
use InvalidArgumentException;
use RetailCrm\Common\Serializer;
use RetailCrm\Common\Url;
use Symfony\Component\Validator\Validation;
/**
* PHP version 7.0
*
* Request class
*
* @package RetailCrm\Mg\Bot
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Request
{
const METHOD_GET = 'GET';
const METHOD_POST = 'POST';
const METHOD_PUT = 'PUT';
const METHOD_PATCH = 'PATCH';
const METHOD_DELETE = 'DELETE';
protected $url;
protected $token;
private $debug;
private $allowedMethods;
private $stdout;
/**
* Client constructor.
*
* @param string $url api url
* @param string $token api token
* @param bool $debug make request verbose
* @param bool|resource $stdout default output for debug
*/
public function __construct($url, $token, $debug, $stdout = STDOUT)
{
if (false === stripos($url, 'https://')) {
throw new InvalidArgumentException('API schema requires HTTPS protocol');
}
$this->url = $url;
$this->token = $token;
$this->debug = $debug;
$this->stdout = $stdout;
$this->allowedMethods = [
self::METHOD_GET,
self::METHOD_POST,
self::METHOD_PUT,
self::METHOD_PATCH,
self::METHOD_DELETE
];
}
/**
* Make HTTP request
*
* @param string $path request url
* @param string $method (default: 'GET')
* @param mixed $request (default: null)
* @param int $serializeTo
*
* @return Response
* @throws \Exception
*/
public function makeRequest($path, $method, $request = null, $serializeTo = Serializer::S_JSON)
{
$this->validateMethod($method);
if (!is_null($request)) {
$this->validateRequest($request);
}
$urlBuilder = new Url();
$parameters = is_null($request) ? null : Serializer::serialize($request, $serializeTo);
$url = $method == self::METHOD_GET
? $this->url . $urlBuilder->buildUrl($path, $parameters, Url::RFC_CUSTOM)
: $this->url . $path
;
$curlHandler = curl_init();
curl_setopt($curlHandler, CURLOPT_URL, $url);
curl_setopt($curlHandler, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curlHandler, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curlHandler, CURLOPT_FAILONERROR, false);
curl_setopt($curlHandler, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curlHandler, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curlHandler, CURLOPT_TIMEOUT, 60);
curl_setopt($curlHandler, CURLOPT_CONNECTTIMEOUT, 60);
curl_setopt($curlHandler, CURLOPT_VERBOSE, $this->debug);
curl_setopt($curlHandler, CURLOPT_STDERR, $this->stdout);
curl_setopt($curlHandler, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
sprintf("X-Bot-Token: %s", $this->token)
]);
if (in_array($method, [self::METHOD_POST, self::METHOD_PUT, self::METHOD_PATCH, self::METHOD_DELETE])) {
curl_setopt($curlHandler, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curlHandler, CURLOPT_POSTFIELDS, $parameters);
}
$responseBody = curl_exec($curlHandler);
$statusCode = curl_getinfo($curlHandler, CURLINFO_HTTP_CODE);
$response = Response::parseJSON($responseBody);
$errorMessage = !empty($response['errorMsg']) ? $response['errorMsg'] : '';
$errorMessage = !empty($response['errors']) ? $this->getErrors($response['errors']) : $errorMessage;
/**
* responses with 400 & 460 http codes contains extended error data
* therefore they are not handled as exceptions
*/
if (in_array($statusCode, [403, 404, 500])) {
throw new Exception($errorMessage);
}
if ($statusCode == 503) {
throw new LimitException($errorMessage);
}
$errno = curl_errno($curlHandler);
$error = curl_error($curlHandler);
curl_close($curlHandler);
if ($errno) {
throw new CurlException($error, $errno);
}
return new Response($statusCode, $responseBody);
}
/**
* Validate HTTP method
*
* @param string $method
*/
private function validateMethod($method)
{
if (!in_array($method, $this->allowedMethods, false)) {
throw new InvalidArgumentException(
sprintf(
'Method "%s" is not valid. Allowed methods are %s',
$method,
implode(', ', $this->allowedMethods)
)
);
}
}
/**
* Validate given class
*
* @param string $class
*
* @return void
*/
private function validateRequest($class)
{
$validator = Validation::createValidatorBuilder()
->enableAnnotationMapping()
->getValidator();
$errors = $validator->validate($class);
if ($errors->count() > 0) {
$message = (string) $errors;
throw new InvalidArgumentException($message);
}
}
private function getErrors(array $errors)
{
$errorString = '';
foreach ($errors as $error) {
$errorString .= $error . " ";
}
return $errorString;
}
}

View file

@ -1,229 +0,0 @@
<?php
/**
* PHP version 7.0
*
* Request
*
* @package RetailCrm\Mg\Bot
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot;
use ArrayAccess;
use BadMethodCallException;
use InvalidArgumentException;
use RetailCrm\Common\Exception\InvalidJsonException;
/**
* PHP version 7.0
*
* Request class
*
* @package RetailCrm\Mg\Bot
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Response implements ArrayAccess
{
// HTTP response status code
protected $statusCode;
// response assoc array
protected $response;
// response body
protected $raw;
/**
* ApiResponse constructor.
*
* @param int $statusCode HTTP status code
* @param mixed $responseBody HTTP body
*
* @throws InvalidJsonException
*/
public function __construct($statusCode, $responseBody = null)
{
$this->statusCode = $statusCode;
$this->raw = $responseBody;
$this->response = self::parseJSON($responseBody);
}
/**
* Return raw HTTP response
*
* @return string|null
*/
public function getRawResponse()
{
return $this->raw;
}
/**
* Return HTTP response
*
* @return array
*/
public function getResponse()
{
return $this->response;
}
/**
* Return HTTP response status code
*
* @return int
*/
public function getStatusCode()
{
return $this->statusCode;
}
/**
* HTTP request was successful
*
* @return bool
*/
public function isSuccessful()
{
return $this->statusCode < 400;
}
/**
* Allow to access for the property throw class method
*
* @param string $name method name
* @param mixed $arguments method parameters
*
* @throws \InvalidArgumentException
*
* @return mixed
*/
public function __call($name, $arguments)
{
// convert getSomeProperty to someProperty
$propertyName = strtolower(substr($name, 3, 1)) . substr($name, 4);
if (!isset($this->response[$propertyName])) {
throw new InvalidArgumentException("Method \"$name\" not found");
}
return $this->response[$propertyName];
}
/**
* Allow to access for the property throw object property
*
* @param string $name property name
*
* @throws \InvalidArgumentException
*
* @return mixed
*/
public function __get($name)
{
if (!isset($this->response[$name])) {
throw new InvalidArgumentException("Property \"$name\" not found");
}
return $this->response[$name];
}
/**
* Allow to check if the property exists through object property
*
* @param string $name property name
*
* @return bool
*/
public function __isset($name)
{
return isset($this->response[$name]);
}
/**
* Offset set
*
* @param mixed $offset offset
* @param mixed $value value
*
* @throws BadMethodCallException
* @return void
*/
public function offsetSet($offset, $value)
{
$message = sprintf("This call not allowed. Offset given: %s. Value given: %s", $offset, $value);
throw new BadMethodCallException($message);
}
/**
* Offset unset
*
* @param mixed $offset offset
*
* @throws BadMethodCallException
* @return void
*/
public function offsetUnset($offset)
{
$message = sprintf("This call not allowed. Offset given: %s", $offset);
throw new BadMethodCallException($message);
}
/**
* Check offset
*
* @param mixed $offset offset
*
* @return bool
*/
public function offsetExists($offset)
{
return isset($this->response[$offset]);
}
/**
* Get offset
*
* @param mixed $offset offset
*
* @throws \InvalidArgumentException
*
* @return mixed
*/
public function offsetGet($offset)
{
if (!isset($this->response[$offset])) {
throw new InvalidArgumentException("Property \"$offset\" not found");
}
return $this->response[$offset];
}
/**
* @param string $responseBody
*
* @return array
*/
public static function parseJSON($responseBody): array
{
$result = [];
if (!empty($responseBody)) {
$response = json_decode($responseBody, true);
if (!$response && JSON_ERROR_NONE !== ($error = json_last_error())) {
throw new InvalidJsonException("Invalid JSON in the API response body. Error code #$error", $error);
}
$result = $response;
}
return $result;
}
}

View file

@ -18,7 +18,7 @@ use DomainException;
/**
* PHP version 7.0
*
* Class CurlException
* Class LimitException
*
* @package RetailCrm\Common\Exception
* @author retailCRM <integration@retailcrm.ru>

View file

@ -13,6 +13,8 @@
namespace RetailCrm\Common;
use JMS\Serializer\DeserializationContext;
use JMS\Serializer\SerializationContext;
use JMS\Serializer\SerializerBuilder;
/**
@ -27,14 +29,14 @@ use JMS\Serializer\SerializerBuilder;
*/
class Serializer
{
const S_ARRAY = 0;
const S_JSON = 1;
const S_ARRAY = 'array';
const S_JSON = 'json';
/**
* Serialize given object to JSON or Array
*
* @param object $request
* @param int $serialize
* @param string $serialize
*
* @return array|string
*/
@ -42,17 +44,79 @@ class Serializer
{
$serialized = null;
$serializer = SerializerBuilder::create()->build();
$context = self::getContext();
switch ($serialize) {
case self::S_ARRAY:
$serialized = $serializer->toArray($request);
$serialized = $serializer->toArray($request, $context);
break;
case self::S_JSON:
default:
$serialized = $serializer->serialize($request, 'json');
$serialized = $serializer->serialize($request, $serialize, $context);
break;
}
return $serialized;
}
/**
* Deserialize given array or JSON to object
*
* @param mixed $data
* @param string $entityType
* @param string $from
*
* @return object|null
*/
public static function deserialize($data, $entityType, $from = self::S_JSON)
{
$deserialized = null;
$serializer = SerializerBuilder::create()->build();
$context = self::getContext(true);
switch ($from) {
case self::S_ARRAY:
$deserialized =
$serializer->fromArray(array_filter($data), self::normalizeNamespace($entityType), $context);
break;
case self::S_JSON:
$deserialized =
$serializer->deserialize($data, self::normalizeNamespace($entityType), $from, $context);
break;
}
return is_object($deserialized) ? $deserialized : null;
}
/**
* @param bool $deserialization (default: false)
*
* @return DeserializationContext|SerializationContext
*/
private static function getContext(bool $deserialization = false)
{
if ($deserialization) {
$context = new DeserializationContext();
} else {
$context = new SerializationContext();
}
$context->setSerializeNull(false);
return $context;
}
/**
* @param string $namespace
*
* @return bool|string
*/
private static function normalizeNamespace(string $namespace)
{
if (substr($namespace, 0, 1) == '\\') {
$namespace = substr($namespace, 1);
}
return $namespace;
}
}

View file

@ -25,15 +25,12 @@ namespace RetailCrm\Common;
*/
class Url
{
const RFC_DEFAULT = 1;
const RFC_CUSTOM = 2;
private $parts = [];
public function __toString()
{
return $this->build();
}
/**
* This class is used to store normalizeUrl method
* which is used in Client and HttpClient to check
* trailing slash.
*/
private function __construct() {}
/**
* Check trailing slash into url
@ -52,75 +49,26 @@ class Url
}
/**
* Build request url
* Convert request data to GET parameters
*
* @param string $path
* @param array $parameters
* @param int $rfc
* @param array $params
*
* @return string
*/
public function buildUrl($path, $parameters, $rfc = self::RFC_DEFAULT)
public static function buildGetParameters(array $params)
{
$url = $path;
$result = '';
switch ($rfc) {
case self::RFC_CUSTOM:
foreach ($parameters as $key => $value) {
if (is_array($value)) {
foreach ($value as $element) {
$this->add($key, $element);
}
} else {
$this->add($key, $value);
}
foreach ($params as $param => $value) {
if (!is_array($value)) {
$result .= '&' . $param . '=' . $value;
} else {
foreach ($value as $subvalue) {
$result .= '&' . $param . '=' . $subvalue;
}
$url = sprintf("%s?%s", $url, $this->build());
break;
case self::RFC_DEFAULT:
default:
$queryString = http_build_query($parameters, '', '&');
$url = sprintf("%s?%s", $path, $queryString);
break;
}
}
return $url;
}
/**
* Add each key valued element of parameters array
* to internal structure before build
*
* @param string $key
* @param mixed $value
*
* @return void
*/
private function add($key, $value)
{
$this->parts[] = array(
'key' => $key,
'value' => $value
);
}
/**
* Build query string with same keys if needed
*
* @param string $separator
* @param string $equals
*
* @return string
*/
private function build($separator = '&', $equals = '=')
{
$queryString = array();
foreach ($this->parts as $part) {
$queryString[] = urlencode($part['key']) . $equals . urlencode($part['value']);
}
return implode($separator, $queryString);
return strlen($result) > 0 ? '?' . substr($result, 1) : '';
}
}

View file

@ -14,6 +14,9 @@
namespace RetailCrm\Mg\Bot\Test;
use PHPUnit\Framework\TestCase as BaseCase;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use RetailCrm\Mg\Bot\Client;
/**
@ -30,25 +33,118 @@ class TestCase extends BaseCase
/**
* Return bot api client object
*
* @param string $url (default: null)
* @param string $key (default: null)
* @param bool $debug (default: false)
* @param string $url (default: null)
* @param string $key (default: null)
* @param bool $debug (default: false)
* @param array $response (default: null)
*
* @return \RetailCrm\Mg\Bot\Client
* @return Client
*/
public static function getApiClient(
$url = null,
$key = null,
$debug = false
$debug = false,
...$response
) {
$configUrl = getenv('MG_BOT_URL');
$configKey = getenv('MG_BOT_KEY');
$configDbg = getenv('MG_BOT_DBG');
$mock = new MockHandler($response ?: []);
return new Client(
$url ?: $configUrl,
$key ?: $configKey,
$debug ?: $configDbg
$debug ?: $configDbg,
empty($response) ? null : HandlerStack::create($mock)
);
}
/**
* Returns mocked GuzzleHttp response
*
* @param string|null $body
* @param int $statusCode
*
* @return Response
*/
public function getResponse(string $body = null, int $statusCode = 200)
{
return new Response(
$statusCode,
array_filter(
[
'Server' => 'openresty/1.13.6.2',
'Date' => gmdate("D, d M Y H:m:s \G\M\T"),
'Content-Type' => 'application/json; charset=utf-8',
'Content-Length' => is_null($body) ? null : strlen($body),
'Connection' => 'keep-alive',
'Access-Control-Allow-Credentials' => 'true',
'Access-Control-Allow-Headers' => 'X-Requested-With, Content-Type, X-Api-Key, X-Client-Token',
'Access-Control-Allow-Methods' => 'GET, POST, PUT, DELETE, OPTIONS'
]
),
$body
);
}
/**
* Generate and return mocked response.
* Response data should be stored in Resources directory as json file.
* Only file name (without extension or any other data) should be provided,
* e.g. `getJsonResponse('bots', 200)`
*
* @param string $jsonFile
* @param int $statusCode
*
* @return Response|null
*/
public function getJsonResponse(string $jsonFile, int $statusCode = 200)
{
$fileName = realpath(
join(
DIRECTORY_SEPARATOR,
[__DIR__, '..', '..', 'Resources', \sprintf('%s.json', $jsonFile)]
)
);
if (file_exists($fileName)) {
$json = file_get_contents($fileName);
json_decode($json, true);
if (json_last_error() == JSON_ERROR_NONE) {
return $this->getResponse($json, $statusCode);
}
} else {
return null;
}
}
/**
* @param int $statusCode
* @param array ...$errors
*
* @return Response
*/
public function getErrorsResponse(int $statusCode = 400, ...$errors)
{
$json = ['errors' => []];
foreach ($errors as $error) {
$json['errors'][] = is_string($error) ? $error : null;
}
return $this->getResponse(json_encode(array_filter($json)), $statusCode);
}
/**
* Generate and return empty response
*
* @param int $statusCode
*
* @return Response|null
*/
public function getEmptyResponse(int $statusCode = 200)
{
return $this->getResponse(null, $statusCode);
}
}

View file

@ -14,6 +14,13 @@
namespace RetailCrm\Mg\Bot\Tests;
use RetailCrm\Mg\Bot\Model\Constants;
use RetailCrm\Mg\Bot\Model\Entity\Channel;
use RetailCrm\Mg\Bot\Model\Entity\Chat\Chat;
use RetailCrm\Mg\Bot\Model\Entity\Chat\ChatMember;
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\User;
use RetailCrm\Mg\Bot\Model\Request;
use RetailCrm\Mg\Bot\Test\TestCase;
@ -29,22 +36,27 @@ use RetailCrm\Mg\Bot\Test\TestCase;
*/
class ClientListTest extends TestCase
{
/**
* @group("list")
* @throws \Exception
*/
public function testChannels()
{
$client = self::getApiClient();
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('channels')
);
$request = new Request\ChannelsRequest();
$request->setActive(true);
$request->setTypes([Constants::CHANNEL_TYPE_FACEBOOK, Constants::CHANNEL_TYPE_INSTAGRAM]);
$request->setTypes([Constants::CHANNEL_TYPE_TELEGRAM, Constants::CHANNEL_TYPE_INSTAGRAM]);
$response = $client->channels($request);
self::assertTrue($response->isSuccessful() == true);
static::assertEquals(4, count($response), "Incorrect channels count");
static::assertTrue($response[0] instanceof Channel\Channel, "Incorrect channel instance");
}
/**
@ -53,14 +65,20 @@ class ClientListTest extends TestCase
*/
public function testChats()
{
$client = self::getApiClient();
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('chats')
);
$request = new Request\ChatsRequest();
$request->setChannelType(Constants::CHANNEL_TYPE_FACEBOOK);
$request->setChannelType(Constants::CHANNEL_TYPE_TELEGRAM);
$response = $client->chats($request);
self::assertTrue($response->isSuccessful() == true);
static::assertEquals(2, count($response), "Incorrect chats count");
static::assertTrue($response[0] instanceof Chat, "Incorrect chat instance");
}
/**
@ -69,13 +87,18 @@ class ClientListTest extends TestCase
*/
public function testMembers()
{
$client = self::getApiClient();
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('members')
);
$request = new Request\MembersRequest();
$response = $client->members($request);
self::assertTrue($response->isSuccessful() == true);
static::assertEquals(4, count($response), "Incorrect members count");
static::assertTrue($response[0] instanceof ChatMember, "Incorrect member instance");
}
/**
@ -84,7 +107,12 @@ class ClientListTest extends TestCase
*/
public function testMessages()
{
$client = self::getApiClient();
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('messages')
);
$request = new Request\MessagesRequest();
$request->setChannelType(Constants::CHANNEL_TYPE_INSTAGRAM);
@ -92,7 +120,8 @@ class ClientListTest extends TestCase
$response = $client->messages($request);
self::assertTrue($response->isSuccessful() == true);
static::assertEquals(2, count($response), "Incorrect message count");
static::assertTrue($response[0] instanceof Message, "Incorrect message instance");
}
/**
@ -101,13 +130,17 @@ class ClientListTest extends TestCase
*/
public function testCommands()
{
$client = self::getApiClient();
$client = self::getApiClient(
null,
null,
false,
$this->getResponse('[]')
);
$request = new Request\CommandsRequest();
$response = $client->commands($request);
self::assertTrue($response->isSuccessful() == true);
self::assertEquals(0, count($response), "Invalid commands count");
}
/**
@ -116,15 +149,20 @@ class ClientListTest extends TestCase
*/
public function testBots()
{
$client = self::getApiClient();
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('bots')
);
$request = new Request\BotsRequest();
$request->setActive(1);
$request->setRoles([Constants::BOT_ROLE_RESPONSIBLE]);
$response = $client->bots($request);
$data = $client->bots($request);
self::assertTrue($response->isSuccessful() == true);
static::assertEquals(3, count($data));
}
/**
@ -133,7 +171,12 @@ class ClientListTest extends TestCase
*/
public function testUsers()
{
$client = self::getApiClient();
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('users')
);
$request = new Request\UsersRequest();
$request->setActive(1);
@ -141,7 +184,8 @@ class ClientListTest extends TestCase
$response = $client->users($request);
self::assertTrue($response->isSuccessful() == true);
self::assertEquals(2, count($response));
self::assertTrue($response[0] instanceof User);
}
/**
@ -150,7 +194,12 @@ class ClientListTest extends TestCase
*/
public function testDialogs()
{
$client = self::getApiClient();
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('dialogs')
);
$request = new Request\DialogsRequest();
$request->setActive(1);
@ -158,7 +207,8 @@ class ClientListTest extends TestCase
$response = $client->dialogs($request);
self::assertTrue($response->isSuccessful() == true);
self::assertEquals(2, count($response));
self::assertTrue($response[0] instanceof Dialog);
}
/**
@ -167,12 +217,18 @@ class ClientListTest extends TestCase
*/
public function testCustomers()
{
$client = self::getApiClient();
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('customers')
);
$request = new Request\CustomersRequest();
$response = $client->customers($request);
self::assertTrue($response->isSuccessful() == true);
self::assertEquals(2, count($response));
self::assertTrue($response[0] instanceof Customer);
}
}

View file

@ -3,7 +3,7 @@
/**
* PHP version 7.0
*
* Client Test
* Commands Test
*
* @package RetailCrm\Mg\Bot\Tests
* @author retailCRM <integration@retailcrm.ru>
@ -13,15 +13,15 @@
namespace RetailCrm\Mg\Bot\Tests;
use Exception;
use InvalidArgumentException;
use RetailCrm\Common\Exception\InvalidJsonException;
use RetailCrm\Mg\Bot\Model\Request\CommandEditRequest;
use RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse;
use RetailCrm\Mg\Bot\Test\TestCase;
/**
* PHP version 7.0
*
* Class ClientTest
* Class CommandsTest
*
* @package RetailCrm\Mg\Bot\Tests
* @author retailCRM <integration@retailcrm.ru>
@ -36,9 +36,14 @@ class CommandsTest extends TestCase
*/
public function testCommandEditException()
{
self::expectException(InvalidArgumentException::class);
self::expectException(InvalidJsonException::class);
$client = self::getApiClient();
$client = self::getApiClient(
null,
null,
false,
$this->getResponse('EOF', 400)
);
$request = new CommandEditRequest();
$request->setDescription("qwerty");
@ -52,7 +57,7 @@ class CommandsTest extends TestCase
*/
public function testCommandDeleteException()
{
self::expectException(Exception::class);
self::expectException(\Exception::class);
$client = self::getApiClient();
@ -67,7 +72,12 @@ class CommandsTest extends TestCase
*/
public function testCommandEdit()
{
$client = self::getApiClient();
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('commandEdit')
);
$request = new CommandEditRequest();
$request->setBotId(1);
@ -76,7 +86,8 @@ class CommandsTest extends TestCase
$response = $client->commandEdit($request);
self::assertTrue($response->isSuccessful() == true);
self::assertTrue($response instanceof ErrorOnlyResponse);
self::assertTrue($response->isSuccessful());
}
/**
@ -86,7 +97,12 @@ class CommandsTest extends TestCase
*/
public function testCommandDelete()
{
$client = self::getApiClient();
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('commandEdit')
);
$response = $client->commandDelete("show_payment_types");

View file

@ -0,0 +1,118 @@
<?php
/**
* PHP version 7.0
*
* Dialogs Test
*
* @package RetailCrm\Mg\Bot\Tests
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Tests;
use InvalidArgumentException;
use RetailCrm\Mg\Bot\Model\Entity\Responsible;
use RetailCrm\Mg\Bot\Model\Request\DialogAssignRequest;
use RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse;
use RetailCrm\Mg\Bot\Test\TestCase;
/**
* PHP version 7.0
*
* Class DialogsTest
*
* @package RetailCrm\Mg\Bot\Tests
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class DialogsTest extends TestCase
{
/**
* @group("dialogs")
* @throws \Exception
*/
public function testDialogAssignError()
{
$client = self::getApiClient(
null,
null,
false,
$this->getErrorsResponse(400, "incorrect dialog_id")
);
$request = new DialogAssignRequest();
$request->setDialogId(-1);
$response = $client->dialogAssign($request);
self::assertTrue(!$response->isSuccessful());
self::assertNotEmpty($response->getErrors());
}
/**
* @group("dialogs")
* @throws \Exception
*/
public function testDialogAssign()
{
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('dialogReassigned')
);
$request = new DialogAssignRequest();
$request->setDialogId(60);
$request->setUserId(4);
$response = $client->dialogAssign($request);
self::assertTrue($response->isSuccessful());
self::assertTrue($response->getIsReassign());
self::assertTrue($response->getPreviousResponsible() instanceof Responsible);
self::assertTrue($response->getResponsible() instanceof Responsible);
}
/**
* @group("dialogs")
* @throws \Exception
*/
public function testDialogCloseError()
{
self::expectException(InvalidArgumentException::class);
$client = self::getApiClient(
null,
null,
false,
$this->getErrorsResponse(404, "dialog #2131231231 not found")
);
$client->dialogClose('2131231231');
}
/**
* @group("dialogs")
* @throws \Exception
*/
public function testDialogClose()
{
$client = self::getApiClient(
null,
null,
false,
$this->getResponse('{}')
);
$response = $client->dialogClose('62');
self::assertTrue($response instanceof ErrorOnlyResponse);
self::assertTrue($response->isSuccessful());
self::assertEmpty($response->getErrors());
}
}

View file

@ -0,0 +1,111 @@
<?php
/**
* PHP version 7.0
*
* Upload file Test
*
* @package RetailCrm\Mg\Bot\Tests
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Mg\Bot\Tests;
use RetailCrm\Mg\Bot\Model\Response\FullFileResponse;
use RetailCrm\Mg\Bot\Model\Response\UploadFileResponse;
use RetailCrm\Mg\Bot\Test\TestCase;
/**
* PHP version 7.0
*
* Class UploadFileTest
*
* @package RetailCrm\Mg\Bot\Tests
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class FileTest extends TestCase
{
/**
* @group("upload")
* @throws \Exception
*/
public function testUploadFileByUrlException()
{
$client = self::getApiClient(
null,
null,
false,
$this->getEmptyResponse(400)
);
self::expectException(\InvalidArgumentException::class);
$client->uploadFileByUrl('');
$client->uploadFileByUrl('rar');
}
/**
* @group("upload")
* @throws \Exception
*/
public function testUploadFileByUrl()
{
$client = self::getApiClient(
null,
null,
false,
$this->getResponse('{"id":"881712bb-4062-4973-9e23-3373135836e2","type":"image","size":3773}')
);
$response = $client->uploadFileByUrl('https://2ip.ru/images/logo.gif');
self::assertTrue($response->isSuccessful());
self::assertEquals('881712bb-4062-4973-9e23-3373135836e2', $response->getId());
self::assertEquals('image', $response->getType());
self::assertEquals('3773', $response->getSize());
}
/**
* @group("upload")
* @throws \Exception
*/
public function testUploadFileViaForm()
{
$client = self::getApiClient(
null,
null,
false,
$this->getResponse('{"id":"b2bdba90-166c-4e0a-829d-69f26a09fd2a","type":"file","size":214}')
);
$response = $client->uploadFile(__FILE__);
self::assertTrue($response instanceof UploadFileResponse);
self::assertEquals('b2bdba90-166c-4e0a-829d-69f26a09fd2a', $response->getId());
self::assertEquals('file', $response->getType());
self::assertEquals(214, $response->getSize());
}
/**
* @group("upload")
* @throws \Exception
*/
public function testGetFileById()
{
$fileId = 'b2bdba90-166c-4e0a-829d-69f26a09fd2a';
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('getFile')
);
$response = $client->getFileById($fileId);
self::assertTrue($response instanceof FullFileResponse);
self::assertEquals($fileId, $response->getId());
}
}

View file

@ -3,7 +3,7 @@
/**
* PHP version 7.0
*
* Client Test
* Messages Test
*
* @package RetailCrm\Mg\Bot\Tests
* @author retailCRM <integration@retailcrm.ru>
@ -13,12 +13,8 @@
namespace RetailCrm\Mg\Bot\Tests;
use Exception;
use InvalidArgumentException;
use RetailCrm\Common\Exception\CurlException;
use RetailCrm\Common\Exception\InvalidJsonException;
use RetailCrm\Mg\Bot\Model\Constants;
use RetailCrm\Mg\Bot\Model\Request\CommandEditRequest;
use RetailCrm\Mg\Bot\Model\Request\MessageEditRequest;
use RetailCrm\Mg\Bot\Model\Request\MessageSendRequest;
use RetailCrm\Mg\Bot\Test\TestCase;
@ -38,17 +34,144 @@ class MessagesTest extends TestCase
* @group("messages")
* @throws \Exception
*/
public function testMessageSend()
public function testMessageSendError()
{
$client = self::getApiClient();
$client = self::getApiClient(
null,
null,
false,
$this->getErrorsResponse(
400,
'chat_id is a required field'
)
);
$request = new MessageSendRequest();
$request->setChatId(0);
$request->setScope(Constants::MESSAGE_SCOPE_PUBLIC);
$request->setContent("Hello");
$request = $client->messageSend($request);
$response = $client->messageSend($request);
self::assertEquals($request->getStatusCode(), 400);
self::assertTrue(!$response->isSuccessful());
self::assertEquals(1, count($response->getErrors()));
}
/**
* @group("messages")
* @throws \Exception
*/
public function testMessageSend()
{
$client = self::getApiClient(
null,
null,
false,
$this->getResponse(
'{"message_id":3636,"time":"2019-06-24T06:02:04.434291791Z"}',
201
)
);
$request = new MessageSendRequest();
$request->setChatId(28);
$request->setScope(Constants::MESSAGE_SCOPE_PUBLIC);
$request->setContent("Hello");
$response = $client->messageSend($request);
self::assertTrue($response->isSuccessful());
self::assertEquals(0, count($response->getErrors()));
self::assertEquals(3636, $response->getMessageId());
}
/**
* @group("messages")
* @throws \Exception
*/
public function testMessageEditError()
{
$client = self::getApiClient(
null,
null,
false,
$this->getErrorsResponse(
400,
'Incorrect message_id'
)
);
$request = new MessageEditRequest();
$request->setId(0);
$request->setContent("Hello");
$response = $client->messageEdit($request);
self::assertTrue(!$response->isSuccessful());
self::assertEquals(1, count($response->getErrors()));
}
/**
* @group("messages")
* @throws \Exception
*/
public function testMessageEdit()
{
$client = self::getApiClient(
null,
null,
false,
$this->getResponse('{}', 200)
);
$request = new MessageEditRequest();
$request->setId(3636);
$request->setContent("123");
$response = $client->messageEdit($request);
self::assertTrue($response->isSuccessful());
self::assertEquals(0, count($response->getErrors()));
}
/**
* @group("messages")
* @throws \Exception
*/
public function testMessageDeleteError()
{
$client = self::getApiClient(
null,
null,
false,
$this->getErrorsResponse(
400,
'Incorrect message_id'
)
);
$response = $client->messageDelete('0');
self::assertTrue(!$response->isSuccessful());
self::assertEquals(1, count($response->getErrors()));
}
/**
* @group("messages")
* @throws \Exception
*/
public function testMessageDelete()
{
$client = self::getApiClient(
null,
null,
false,
$this->getResponse('{}', 200)
);
$response = $client->messageDelete('3636');
self::assertTrue($response->isSuccessful());
self::assertEquals(0, count($response->getErrors()));
}
}

46
tests/Resources/bots.json Normal file
View file

@ -0,0 +1,46 @@
[
{
"id": 9,
"name": "Помощник",
"events": null,
"client_id": "identifier_1",
"avatar_url": "https://s3-s1.retailcrm.tech/eu-central-1/retailcrm-billing/images/5b927ad342366-bot-logo.svg",
"roles": null,
"created_at": "2018-09-13T07:38:02.988438Z",
"updated_at": "2019-06-13T12:56:36.346811Z",
"deactivated_at": null,
"is_active": true,
"is_self": true,
"is_system": false
},
{
"id": 7,
"name": "Helper",
"events": null,
"client_id": "identifier_2",
"avatar_url": "https://test.te/static/logo.svg",
"roles": null,
"created_at": "2018-09-07T07:27:41.87424Z",
"updated_at": "2018-10-25T07:43:03.077956Z",
"deactivated_at": "2019-10-25T07:43:03.077956Z",
"is_active": false,
"is_self": false,
"is_system": false
},
{
"id": 6,
"name": "Mira chat bot",
"events": null,
"client_id": "identifier_3",
"avatar_url": "https://s3.retailcrm.pro/eu-central-1/retailcrm-billing/images/5b97bfd983d2b-bot-logo-2.svg",
"roles": [
"responsible"
],
"created_at": "2018-09-06T13:40:02.956515Z",
"updated_at": "2018-09-12T06:15:32.858632Z",
"deactivated_at": null,
"is_active": true,
"is_self": false,
"is_system": false
}
]

View file

@ -0,0 +1,178 @@
[
{
"id": 72,
"type": "telegram",
"name": "@testbot",
"settings": {
"status": {
"delivered": "send"
},
"text": {
"creating": "both",
"editing": "both",
"quoting": "both",
"deleting": "receive",
"max_chars_count": 4096
},
"product": {
"creating": "receive",
"editing": "receive"
},
"order": {
"creating": "receive",
"editing": "receive"
},
"image": {
"creating": "both",
"editing": "both",
"quoting": "both",
"deleting": "receive",
"max_items_count": 10
},
"file": {
"creating": "both",
"editing": "both",
"quoting": "both",
"deleting": "receive",
"max_items_count": 1
}
},
"created_at": "2019-06-11T12:46:48.72241Z",
"updated_at": "2019-06-11T12:56:48.72241Z",
"activated_at": "2019-06-11T12:46:48.722086Z",
"deactivated_at": null,
"is_active": true
},
{
"id": 71,
"type": "telegram",
"name": "@testbot",
"settings": {
"status": {
"delivered": "send"
},
"text": {
"creating": "both",
"editing": "both",
"quoting": "both",
"deleting": "receive",
"max_chars_count": 4096
},
"product": {
"creating": "receive",
"editing": "receive"
},
"order": {
"creating": "receive",
"editing": "receive"
},
"image": {
"creating": "both",
"editing": "both",
"quoting": "both",
"deleting": "receive",
"max_items_count": 10
},
"file": {
"creating": "both",
"editing": "both",
"quoting": "both",
"deleting": "receive",
"max_items_count": 1
}
},
"created_at": "2019-06-11T12:41:44.660495Z",
"updated_at": "2019-06-11T12:46:42.094353Z",
"activated_at": "2019-06-11T12:41:44.660204Z",
"deactivated_at": "2019-06-11T12:46:42.094135Z",
"is_active": true
},
{
"id": 70,
"type": "telegram",
"name": "@testbot",
"settings": {
"status": {
"delivered": "send"
},
"text": {
"creating": "both",
"editing": "both",
"quoting": "both",
"deleting": "receive",
"max_chars_count": 4096
},
"product": {
"creating": "receive",
"editing": "receive"
},
"order": {
"creating": "receive",
"editing": "receive"
},
"image": {
"creating": "both",
"editing": "both",
"quoting": "both",
"deleting": "receive",
"max_items_count": 10
},
"file": {
"creating": "both",
"editing": "both",
"quoting": "both",
"deleting": "receive",
"max_items_count": 1
}
},
"created_at": "2019-06-11T12:38:24.322413Z",
"updated_at": "2019-06-11T12:41:42.335889Z",
"activated_at": "2019-06-11T12:38:24.322125Z",
"deactivated_at": "2019-06-11T12:41:42.335678Z",
"is_active": true
},
{
"id": 69,
"type": "telegram",
"name": "@testbot",
"settings": {
"status": {
"delivered": "send"
},
"text": {
"creating": "both",
"editing": "both",
"quoting": "both",
"deleting": "receive",
"max_chars_count": 4096
},
"product": {
"creating": "receive",
"editing": "receive"
},
"order": {
"creating": "receive",
"editing": "receive"
},
"image": {
"creating": "both",
"editing": "both",
"quoting": "both",
"deleting": "receive",
"max_items_count": 10
},
"file": {
"creating": "both",
"editing": "both",
"quoting": "both",
"deleting": "receive",
"max_items_count": 1
}
},
"created_at": "2019-06-11T12:33:08.676214Z",
"updated_at": "2019-06-11T12:38:19.615651Z",
"activated_at": "2019-06-11T12:33:08.676043Z",
"deactivated_at": "2019-06-11T12:38:19.615335Z",
"is_active": true
}
]

116
tests/Resources/chats.json Normal file
View file

@ -0,0 +1,116 @@
[
{
"id": 30,
"avatar": "",
"name": "",
"channel": {
"id": 72,
"avatar": "",
"transport_id": 4,
"type": "fbmessenger",
"settings": {
"status": {
"delivered": "send"
},
"text": {
"creating": "both",
"editing": "both",
"quoting": "both",
"deleting": "receive",
"max_chars_count": 4096
},
"product": {
"creating": "receive",
"editing": "receive"
},
"order": {
"creating": "receive",
"editing": "receive"
},
"image": {
"creating": "both",
"editing": "both",
"quoting": "both",
"deleting": "receive",
"max_items_count": 10
},
"file": {
"creating": "both",
"editing": "both",
"quoting": "both",
"deleting": "receive",
"max_items_count": 1
}
},
"name": "testbot",
"is_active": true
},
"members": null,
"customer": {
"id": 39,
"type": "customer",
"avatar": "",
"name": "Иван",
"username": "Иван",
"first_name": "Иван"
},
"author_id": 0,
"last_message": null,
"last_activity": "2019-06-11T17:36:20+03:00",
"created_at": "2019-06-11T12:49:26.938879Z",
"updated_at": "2019-06-14T14:40:28.7111Z"
},
{
"id": 29,
"avatar": "",
"name": "",
"channel": {
"id": 68,
"avatar": "",
"transport_id": 5,
"type": "fbmessenger",
"settings": {
"status": {
"delivered": "send",
"read": "send"
},
"text": {
"creating": "both",
"quoting": "receive",
"max_chars_count": 2000
},
"product": {
"creating": "receive"
},
"order": {
"creating": "receive"
},
"image": {
"creating": "both",
"max_items_count": 10
},
"file": {
"creating": "both",
"max_items_count": 10
}
},
"name": "testbot",
"is_active": false
},
"members": null,
"customer": {
"id": 38,
"type": "customer",
"avatar": "",
"name": "Пётр Петрович",
"username": "Пётр",
"first_name": "Пётр",
"last_name": "Петрович"
},
"author_id": 0,
"last_message": null,
"last_activity": "2019-06-13T11:07:14+03:00",
"created_at": "2019-06-11T07:34:16.082957Z",
"updated_at": "2019-06-16T08:10:28.657972Z"
}
]

View file

@ -0,0 +1 @@
{"id":6,"name":"show_payment_types","description":"Get available payment types","created_at":"2019-06-19T09:02:35Z","updated_at":"2019-06-19T09:39:00Z"}

View file

@ -0,0 +1,34 @@
[
{
"id": 39,
"external_id": "333296016",
"channel_id": 3,
"username": "user1",
"first_name": "User1",
"last_name": "Lastname1",
"created_at": "2019-06-11T12:49:26.935824Z",
"updated_at": "2019-06-11T14:36:20.840304Z",
"avatar_url": "",
"profile_url": "",
"country": "",
"language": "en",
"phone": "",
"email": ""
},
{
"id": 38,
"external_id": "2272664739519803",
"channel_id": 3,
"username": "user2",
"first_name": "User2",
"last_name": "Lastname2",
"created_at": "2019-06-11T07:34:16.079453Z",
"updated_at": "2019-06-13T08:07:14.898472Z",
"avatar_url": "",
"profile_url": "",
"country": "",
"language": "ru",
"phone": "",
"email": ""
}
]

View file

@ -0,0 +1 @@
{"responsible":{"type":"user","id":4,"assigned_at":"2019-06-21T08:01:09Z"},"is_reassign":true,"previous_responsible":{"type":"user","id":12,"assigned_at":"2019-06-11T12:49:34Z"},"left_user_id":12}

View file

@ -0,0 +1,34 @@
[
{
"id": 60,
"chat_id": 30,
"begin_message_id": 3540,
"ending_message_id": 3625,
"created_at": "2019-06-11T12:49:26.955306Z",
"updated_at": "2019-06-14T14:40:28.711974Z",
"closed_at": "2019-06-14T14:40:28.684683Z",
"is_assigned": true,
"responsible": {
"type": "user",
"id": 12,
"assigned_at": "2019-06-11T12:49:34.716716Z"
},
"is_active": true
},
{
"id": 59,
"chat_id": 29,
"begin_message_id": 3483,
"ending_message_id": 3626,
"created_at": "2019-06-11T07:34:16.101228Z",
"updated_at": "2019-06-16T08:10:28.659389Z",
"closed_at": "2019-06-16T08:10:28.645607Z",
"is_assigned": true,
"responsible": {
"type": "user",
"id": 12,
"assigned_at": "2019-06-11T08:40:14.136916Z"
},
"is_active": true
}
]

View file

@ -0,0 +1 @@
{"id":"b2bdba90-166c-4e0a-829d-69f26a09fd2a","type":"file","size":214,"Url":"https://s3.eu-central-1.amazonaws.com/mg-node-files/files/21/b2bdba90-166c-4e0a-829d-69f26a09fd2a"}

View file

@ -0,0 +1,38 @@
[
{
"id": 50,
"created_at": "2019-06-11T12:49:34.718596Z",
"updated_at": "2019-06-11T14:36:22.086823Z",
"is_author": false,
"state": "active",
"chat_id": 30,
"user_id": 12
},
{
"id": 49,
"created_at": "2019-06-11T12:49:26.967903Z",
"updated_at": "2019-06-11T12:49:34.723983Z",
"is_author": false,
"state": "kicked",
"chat_id": 30,
"user_id": 4
},
{
"id": 48,
"created_at": "2019-06-11T08:40:14.139024Z",
"updated_at": "2019-06-13T08:10:03.576754Z",
"is_author": false,
"state": "active",
"chat_id": 29,
"user_id": 12
},
{
"id": 47,
"created_at": "2019-06-11T07:34:16.117109Z",
"updated_at": "2019-06-11T08:40:14.145243Z",
"is_author": false,
"state": "kicked",
"chat_id": 29,
"user_id": 4
}
]

View file

@ -0,0 +1,48 @@
[
{
"id": 3376,
"time": "2019-05-20T17:17:28+03:00",
"type": "text",
"scope": "public",
"chat_id": 26,
"is_read": false,
"is_edit": false,
"status": "seen",
"from": {
"id": 35,
"type": "customer",
"avatar": "",
"name": "Иванов Иван",
"username": "username",
"first_name": "Иванов Иван"
},
"content": "Text",
"quote": null,
"channel_id": 61,
"created_at": "2019-05-20T14:17:28.025314Z",
"updated_at": "2019-05-20T14:20:57.05964Z"
},
{
"id": 3373,
"time": "2019-05-20T15:24:52+03:00",
"type": "text",
"scope": "public",
"chat_id": 26,
"is_read": false,
"is_edit": false,
"status": "seen",
"from": {
"id": 35,
"type": "customer",
"avatar": "",
"name": "Иванов Иван",
"username": "username",
"first_name": "Иванов Иван"
},
"content": "❤️",
"quote": null,
"channel_id": 61,
"created_at": "2019-05-20T12:24:52.478633Z",
"updated_at": "2019-05-20T12:24:52.585284Z"
}
]

View file

@ -0,0 +1,23 @@
[
{
"id": 1,
"external_id": "11",
"username": "User 1",
"first_name": "User",
"created_at": "2018-10-02T10:10:10.066295Z",
"updated_at": "2019-06-17T07:40:26.613546Z",
"is_online": false,
"is_active": true,
"avatar_url": "<url>"
},
{
"id": 2,
"external_id": "22",
"username": "User 2",
"first_name": "User",
"created_at": "2018-09-06T13:19:25.01842Z",
"updated_at": "2019-06-07T11:36:52.342065Z",
"is_online": false,
"is_active": true
}
]

View file

@ -12,4 +12,9 @@ $loader->add('RetailCrm\\Mg\\Bot\\Test', __DIR__);
use Symfony\Component\Dotenv\Dotenv;
$dotenv = new Dotenv();
$dotenv->load(__DIR__ . '/../.env');
try {
$dotenv->load(__DIR__ . '/../.env');
} catch (Exception $exception) {
echo "WARNING: Can't load .env file. Using default environment.";
}