1
0
mirror of synced 2024-11-23 12:16:02 +03:00

Initial version (#1)

This commit is contained in:
Alex Lushpai 2019-06-10 16:24:22 +03:00 committed by GitHub
parent 9290228aca
commit 282d00b81a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
53 changed files with 9759 additions and 1 deletions

3
.env.dist Normal file
View File

@ -0,0 +1,3 @@
MG_BOT_URL=""
MG_BOT_KEY=""
MG_BOT_DBG=""

186
.gitignore vendored Normal file
View File

@ -0,0 +1,186 @@
# Created by .ignore support plugin (hsz.mobi)
### macOS template
# General
.DS_Store
.AppleDouble
.LSOverride
.env
# Icon must end with two \r
Icon
# Thumbnails
._*
# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent
# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/dictionaries
.idea/**/shelf
# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml
# Gradle
.idea/**/gradle.xml
.idea/**/libraries
# CMake
cmake-build-debug/
cmake-build-release/
# Mongo Explorer plugin
.idea/**/mongoSettings.xml
# File-based project format
*.iws
# IntelliJ
out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Cursive Clojure plugin
.idea/replstate.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties
# Editor-based Rest Client
.idea/httpRequests
### NetBeans template
nbproject/private/
nbbuild/
/dist/
nbdist/
.nb-gradle/
### Eclipse template
.metadata
bin/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.settings/
.loadpath
.recommenders
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# PyDev specific (Python IDE for Eclipse)
*.pydevproject
# CDT-specific (C/C++ Development Tooling)
.cproject
# CDT- autotools
.autotools
# Java annotation processor (APT)
.factorypath
# PDT-specific (PHP Development Tools)
.buildpath
# sbteclipse plugin
.target
# Tern plugin
.tern-project
# TeXlipse plugin
.texlipse
# STS (Spring Tool Suite)
.springBeans
# Code Recommenders
.recommenders/
# Scala IDE specific (Scala & Java development for Eclipse)
.cache-main
.scala_dependencies
.worksheet
### Composer template
composer.phar
/vendor/
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
# composer.lock
### Linux template
*~
# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*
# KDE directory preferences
.directory
# Linux trash folder which might appear on any partition or disk
.Trash-*
# .nfs files are created when an open file is removed but is still being accessed
.nfs*
### Windows template
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db
# Dump file
*.stackdump
# Folder config file
[Dd]esktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp
# Windows shortcuts
*.lnk
/.php_cs.cache

16
.travis.yml Normal file
View File

@ -0,0 +1,16 @@
language: php
cache:
directories:
- $HOME/.composer/cache
php:
- '7.0'
- '7.1'
- '7.2'
before_script:
- flags="-o"
- composer install $flags
script: make test

View File

@ -1,6 +1,6 @@
MIT License MIT License
Copyright (c) 2018 retailCRM Copyright (c) 2018-2019 RetailDriver LLC
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

19
Makefile Normal file
View File

@ -0,0 +1,19 @@
ROOT_DIR=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
SRC_DIR=$(ROOT_DIR)/src
BIN_DIR=$(ROOT_DIR)/bin
deps:
@echo "==> Installing dependencies"
@curl -L https://getcomposer.org/composer.phar -o $(BIN_DIR)/composer
@COMPOSER_HOME=/tmp php -d memory_limit=-1 $(BIN_DIR)/composer install
test:
@echo "==> Running tests"
@cd $(ROOT_DIR)
@php -d memory_limit=-1 $(BIN_DIR)/phpunit -c phpunit.xml.dist --log-junit $(ROOT_DIR)/test-report.xml
@echo "==> Testing complete"
stan:
@echo "==> Running analysis"
@php $(BIN_DIR)/phpstan analyse -l 4 -c $(ROOT_DIR)/phpstan.neon $(SRC_DIR)
@echo "==> Analysis complete"

32
apigen.neon Normal file
View File

@ -0,0 +1,32 @@
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

50
composer.json Normal file
View File

@ -0,0 +1,50 @@
{
"name": "retailcrm/mg-bot-api-client-php",
"description": "PHP client for retailCRM MG Bot API",
"type": "library",
"keywords": ["API", "retailCRM", "REST", "bot"],
"homepage": "http://www.retailcrm.ru/",
"license": "MIT",
"authors": [
{
"name": "retailCRM",
"email": "support@retailcrm.ru"
}
],
"require": {
"php": ">=7.0",
"ext-curl": "*",
"ext-json": "*",
"jms/serializer": "1.13.*",
"symfony/validator": "^4.2",
"doctrine/annotations": "^1.6",
"doctrine/cache": "^1.8"
},
"require-dev": {
"phpunit/phpunit": "6.5.*",
"phpmd/phpmd": "2.6.*",
"phpstan/phpstan": "0.9.*",
"squizlabs/php_codesniffer": "3.4.*",
"symfony/dotenv": "^4.2",
"friendsofphp/php-cs-fixer": "^2.14"
},
"support": {
"email": "support@retailcrm.ru"
},
"autoload": {
"psr-4": {
"RetailCrm\\Mg\\": ["src/", "tests/"],
"RetailCrm\\Common\\": "src/"
},
"files": ["extra/autoloader.php"]
},
"extra": {
"branch-alias": {
"dev-master": "1.x-dev"
}
},
"config": {
"bin-dir": "bin",
"process-timeout": 600
}
}

4251
composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

19
extra/autoloader.php Normal file
View File

@ -0,0 +1,19 @@
<?php
// autoload.php
use Doctrine\Common\Annotations\AnnotationRegistry;
use Composer\Autoload\ClassLoader;
/**
* @var ClassLoader $loader
*/
$autoloadFile = file_exists(__DIR__ . '/../vendor/autoload.php')
? __DIR__ . '/../vendor/autoload.php'
: __DIR__ . '/../../../autoload.php';
$loader = require $autoloadFile;
AnnotationRegistry::registerLoader('class_exists');
return $loader;

3
phpstan.neon Normal file
View File

@ -0,0 +1,3 @@
parameters:
autoload_files:
- %currentWorkingDirectory%/vendor/autoload.php

22
phpunit.xml.dist Normal file
View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="phpunit.xsd"
bootstrap="./tests/bootstrap.php"
colors="true"
verbose="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="RetailCrm">
<directory>tests/Bot/Tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">./src/Bot</directory>
</whitelist>
</filter>
</phpunit>

251
phpunit.xsd Normal file
View File

@ -0,0 +1,251 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:annotation>
<xs:documentation source="http://www.phpunit.de/manual/3.7/en/appendixes.configuration.html">
This Schema file defines the rules by which the XML configuration file of PHPUnit 3.7 may be structured.
</xs:documentation>
<xs:appinfo source="http://www.phpunit.de/manual/current/en/appendixes.configuration.html"/>
</xs:annotation>
<xs:element name="phpunit" type="phpUnitType">
<xs:annotation>
<xs:documentation>Root Element</xs:documentation>
</xs:annotation>
</xs:element>
<xs:complexType name="filtersType">
<xs:choice>
<xs:sequence>
<xs:element name="blacklist" type="filterType"/>
<xs:element name="whitelist" type="whiteListType" minOccurs="0"/>
</xs:sequence>
<xs:sequence>
<xs:element name="whitelist" type="whiteListType"/>
</xs:sequence>
</xs:choice>
</xs:complexType>
<xs:complexType name="filterType">
<xs:sequence>
<xs:group ref="pathGroup"/>
<xs:element name="exclude" maxOccurs="unbounded" minOccurs="0">
<xs:complexType>
<xs:group ref="pathGroup"/>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:complexType name="whiteListType">
<xs:complexContent>
<xs:extension base="filterType">
<xs:attribute name="processUncoveredFilesFromWhitelist" default="true" type="xs:boolean"/>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="groupsType">
<xs:choice>
<xs:sequence>
<xs:element name="include" type="groupType"/>
<xs:element name="exclude" type="groupType" minOccurs="0"/>
</xs:sequence>
<xs:sequence>
<xs:element name="exclude" type="groupType"/>
</xs:sequence>
</xs:choice>
</xs:complexType>
<xs:complexType name="groupType">
<xs:sequence>
<xs:element name="group" type="xs:string" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="listenersType">
<xs:sequence>
<xs:element name="listener" type="objectType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="objectType">
<xs:sequence>
<xs:element name="arguments" minOccurs="0">
<xs:complexType>
<xs:group ref="argumentsGroup"/>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="class" type="xs:string" use="required"/>
<xs:attribute name="file" type="xs:anyURI"/>
</xs:complexType>
<xs:complexType name="arrayType">
<xs:sequence>
<xs:element name="element" type="argumentType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="argumentType">
<xs:group ref="argumentChoice"/>
<xs:attribute name="key" use="required"/>
</xs:complexType>
<xs:group name="argumentsGroup">
<xs:sequence>
<xs:element name="array" type="arrayType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="integer" type="xs:integer" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="string" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="double" type="xs:double" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="null" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="object" type="objectType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="file" type="xs:anyURI" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="directory" type="xs:anyURI" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:group>
<xs:group name="argumentChoice">
<xs:choice>
<xs:element name="array" type="arrayType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="integer" type="xs:integer" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="string" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="double" type="xs:double" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="null" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="object" type="objectType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="file" type="xs:anyURI" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="directory" type="xs:anyURI" minOccurs="0" maxOccurs="unbounded"/>
</xs:choice>
</xs:group>
<xs:complexType name="loggersType">
<xs:sequence>
<xs:element name="log" type="loggerType" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="loggerType">
<xs:attribute name="type">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="coverage-html"/>
<xs:enumeration value="coverage-clover"/>
<xs:enumeration value="json"/>
<xs:enumeration value="plain"/>
<xs:enumeration value="tap"/>
<xs:enumeration value="junit"/>
<xs:enumeration value="testdox-html"/>
<xs:enumeration value="testdox-text"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
<xs:attribute name="target" type="xs:anyURI"/>
<xs:attribute name="title" type="xs:string"/>
<xs:attribute name="charset" type="xs:string" default="UTF-8"/>
<xs:attribute name="yui" type="xs:boolean" default="true"/>
<xs:attribute name="highlight" type="xs:boolean" default="false"/>
<xs:attribute name="lowUpperBound" type="xs:nonNegativeInteger" default="35"/>
<xs:attribute name="highLowerBound" type="xs:nonNegativeInteger" default="70"/>
<xs:attribute name="logIncompleteSkipped" type="xs:boolean" default="false"/>
</xs:complexType>
<xs:group name="pathGroup">
<xs:sequence>
<xs:element name="directory" type="directoryFilterType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="file" type="fileFilterType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:group>
<xs:complexType name="directoryFilterType">
<xs:simpleContent>
<xs:extension base="xs:anyURI">
<xs:attribute type="xs:string" name="suffix" default="Test.php"/>
<xs:attributeGroup ref="phpVersionGroup"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="fileFilterType">
<xs:simpleContent>
<xs:extension base="xs:anyURI">
<xs:attributeGroup ref="phpVersionGroup"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:attributeGroup name="phpVersionGroup">
<xs:attribute name="phpVersion" type="xs:string" default="5.3.0"/>
<xs:attribute name="phpVersionOperator" type="xs:string" default="&gt;="/>
</xs:attributeGroup>
<xs:complexType name="phpType">
<xs:sequence>
<xs:element name="includePath" type="xs:anyURI" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="ini" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="const" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="var" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="env" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="post" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="get" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="cookie" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="server" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="files" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="request" type="namedValueType" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="namedValueType">
<xs:attribute name="name" use="required" type="xs:string"/>
<xs:attribute name="value" use="required" type="xs:anySimpleType"/>
</xs:complexType>
<xs:complexType name="phpUnitType">
<xs:annotation>
<xs:documentation>The main type specifying the document structure</xs:documentation>
</xs:annotation>
<xs:group ref="configGroup"/>
<xs:attributeGroup ref="configAttributeGroup"/>
</xs:complexType>
<xs:attributeGroup name="configAttributeGroup">
<xs:attribute name="backupGlobals" type="xs:boolean" default="true"/>
<xs:attribute name="backupStaticAttributes" type="xs:boolean" default="false"/>
<xs:attribute name="bootstrap" type="xs:anyURI"/>
<xs:attribute name="cacheTokens" type="xs:boolean"/>
<xs:attribute name="colors" type="xs:boolean" default="false"/>
<xs:attribute name="convertErrorsToExceptions" type="xs:boolean" default="true"/>
<xs:attribute name="convertNoticesToExceptions" type="xs:boolean" default="true"/>
<xs:attribute name="convertWarningsToExceptions" type="xs:boolean" default="true"/>
<xs:attribute name="forceCoversAnnotation" type="xs:boolean" default="false"/>
<xs:attribute name="mapTestClassNameToCoveredClassName" type="xs:boolean" default="false"/>
<xs:attribute name="printerClass" type="xs:string" default="PHPUnit_TextUI_ResultPrinter"/>
<xs:attribute name="printerFile" type="xs:anyURI"/>
<xs:attribute name="processIsolation" type="xs:boolean" default="false"/>
<xs:attribute name="stopOnError" type="xs:boolean" default="false"/>
<xs:attribute name="stopOnFailure" type="xs:boolean" default="false"/>
<xs:attribute name="stopOnIncomplete" type="xs:boolean" default="false"/>
<xs:attribute name="stopOnSkipped" type="xs:boolean" default="false"/>
<xs:attribute name="strict" type="xs:boolean" default="false"/>
<xs:attribute name="testSuiteLoaderClass" type="xs:string" default="PHPUnit_Runner_StandardTestSuiteLoader"/>
<xs:attribute name="testSuiteLoaderFile" type="xs:anyURI"/>
<xs:attribute name="timeoutForSmallTests" type="xs:integer" default="1"/>
<xs:attribute name="timeoutForMediumTests" type="xs:integer" default="10"/>
<xs:attribute name="timeoutForLargeTests" type="xs:integer" default="60"/>
<xs:attribute name="verbose" type="xs:boolean" default="false"/>
</xs:attributeGroup>
<xs:group name="configGroup">
<xs:all>
<xs:element ref="testSuiteFacet" minOccurs="0"/>
<xs:element name="groups" type="groupsType" minOccurs="0"/>
<xs:element name="filter" type="filtersType" minOccurs="0"/>
<xs:element name="logging" type="loggersType" minOccurs="0"/>
<xs:element name="listeners" type="listenersType" minOccurs="0"/>
<xs:element name="php" type="phpType" minOccurs="0"/>
<xs:element name="selenium" type="seleniumType" minOccurs="0"/>
</xs:all>
</xs:group>
<xs:complexType name="seleniumType">
<xs:sequence>
<xs:element name="browser" type="browserType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="browserType">
<xs:attribute name="name" type="xs:string"/>
<xs:attribute name="browser" type="xs:string"/>
<xs:attribute name="host" type="xs:anyURI"/>
<xs:attribute name="port" type="xs:nonNegativeInteger"/>
<xs:attribute name="timeout" type="xs:nonNegativeInteger"/>
</xs:complexType>
<xs:element name="testSuiteFacet" abstract="true"/>
<xs:element name="testsuite" type="testSuiteType" substitutionGroup="testSuiteFacet"/>
<xs:element name="testsuites" type="testSuitesType" substitutionGroup="testSuiteFacet"/>
<xs:complexType name="testSuitesType">
<xs:sequence>
<xs:element name="testsuite" type="testSuiteType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="testSuiteType">
<xs:sequence>
<xs:group ref="pathGroup"/>
<xs:element name="exclude" type="xs:anyURI" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
<xs:attribute name="name" type="xs:string" use="required"/>
</xs:complexType>
</xs:schema>

345
src/Bot/Client.php Normal file
View File

@ -0,0 +1,345 @@
<?php
/**
* PHP version 7.0
*
* Client
*
* @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\InvalidJsonException;
use RetailCrm\Common\Url;
use RetailCrm\Common\Serializer;
use RetailCrm\Mg\Bot\Model;
use Exception;
use InvalidArgumentException;
/**
* PHP version 7.0
*
* Client 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 Client
{
const VERSION = 'v1';
protected $client;
/**
* Init
*
* @param string $url api url
* @param string $token api key
* @param bool $debug debug flag
*/
public function __construct($url, $token, $debug = false)
{
$url = sprintf("%sapi/bot/%s", Url::normalizeUrl($url), self::VERSION);
$this->client = new Request($url, $token, $debug);
}
/**
* Returns filtered bots list
*
* @param Model\Request\BotsRequest $request
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
*/
public function bots(Model\Request\BotsRequest $request)
{
return $this->client->makeRequest('/bots', Request::METHOD_GET, $request, Serializer::S_ARRAY);
}
/**
* Edit bot info
*
* @param Model\Request\InfoRequest $request
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws CurlException
* @throws Exception
*
* @return Response
*/
public function info(Model\Request\InfoRequest $request)
{
return $this->client->makeRequest('/my/info', Request::METHOD_PATCH, $request);
}
/**
* Returns filtered channels list
*
* @param Model\Request\ChannelsRequest $request
*
* @return Response
* @throws \Exception
*/
public function channels(Model\Request\ChannelsRequest $request)
{
return $this->client->makeRequest('/channels', Request::METHOD_GET, $request, Serializer::S_ARRAY);
}
/**
* Returns filtered chats list
*
* @param Model\Request\ChatsRequest $request
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
*/
public function chats(Model\Request\ChatsRequest $request)
{
return $this->client->makeRequest('/chats', Request::METHOD_GET, $request, Serializer::S_ARRAY);
}
/**
* Returns filtered commands list
*
* @param Model\Request\CommandsRequest $request
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
*/
public function commands(Model\Request\CommandsRequest $request)
{
return $this->client->makeRequest('/my/commands', Request::METHOD_GET, $request, Serializer::S_ARRAY);
}
/**
* Edit commands for exact bot
*
* @param Model\Request\CommandEditRequest $request
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
*/
public function commandEdit(Model\Request\CommandEditRequest $request)
{
return $this->client->makeRequest(
sprintf("/my/commands/%s", $request->getName()),
Request::METHOD_PUT,
$request
);
}
/**
* Delete command for exact bot
*
* @param string $request
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
*/
public function commandDelete(string $request)
{
return $this->client->makeRequest(sprintf("/my/commands/%s", $request), Request::METHOD_DELETE);
}
/**
* Returns filtered customers list
*
* @param Model\Request\CustomersRequest $request
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
*/
public function customers(Model\Request\CustomersRequest $request)
{
return $this->client->makeRequest('/customers', Request::METHOD_GET, $request, Serializer::S_ARRAY);
}
/**
* Returns filtered dialogs list
*
* @param Model\Request\DialogsRequest $request
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
*/
public function dialogs(Model\Request\DialogsRequest $request)
{
return $this->client->makeRequest('/dialogs', Request::METHOD_GET, $request, Serializer::S_ARRAY);
}
/**
* Assign dialog to exact user
*
* @param Model\Request\DialogAssignRequest $request
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
*/
public function dialogAssign(Model\Request\DialogAssignRequest $request)
{
return $this->client->makeRequest(
sprintf("/dialogs/%d/assign", $request->getDialogId()),
Request::METHOD_PATCH,
$request
);
}
/**
* Close exact dialog
*
* @param string $request
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
*/
public function dialogClose(string $request)
{
return $this->client->makeRequest(sprintf("/dialogs/%d/close", $request), Request::METHOD_DELETE);
}
/**
* Returns filtered members list
*
* @param Model\Request\MembersRequest $request
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
*/
public function members(Model\Request\MembersRequest $request)
{
return $this->client->makeRequest('/members', Request::METHOD_GET, $request, Serializer::S_ARRAY);
}
/**
* Returns filtered messages list
*
* @param Model\Request\MessagesRequest $request
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
*/
public function messages(Model\Request\MessagesRequest $request)
{
return $this->client->makeRequest('/messages', Request::METHOD_GET, $request, Serializer::S_ARRAY);
}
/**
* Send a message
*
* @param Model\Request\MessageSendRequest $request
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
*/
public function messageSend(Model\Request\MessageSendRequest $request)
{
return $this->client->makeRequest('/messages', Request::METHOD_POST, $request);
}
/**
* Edit a message
*
* @param Model\Request\MessageEditRequest $request
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
*/
public function messageEdit(Model\Request\MessageEditRequest $request)
{
return $this->client->makeRequest('/messages/%d', Request::METHOD_PATCH, $request->getId());
}
/**
* Delete a message
*
* @param string $request
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
*/
public function messageDelete(string $request)
{
return $this->client->makeRequest(sprintf("/messages/%d", $request), Request::METHOD_DELETE);
}
/**
* Returns filtered users list
*
* @param Model\Request\UsersRequest $request
*
* @throws InvalidArgumentException
* @throws CurlException
* @throws InvalidJsonException
* @throws Exception
*
* @return Response
*/
public function users(Model\Request\UsersRequest $request)
{
return $this->client->makeRequest('/users', Request::METHOD_GET, $request, Serializer::S_ARRAY);
}
}

View File

@ -0,0 +1,85 @@
<?php
/**
* PHP version 7.0
*
* Constants
*
* @package RetailCrm\Mg\Bot\Model
* @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;
/**
* PHP version 7.0
*
* Constants class
*
* @package RetailCrm\Mg\Bot\Model
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Constants
{
const CHANNEL_TYPE_TELEGRAM = "telegram";
const CHANNEL_TYPE_FACEBOOK = "fbmessenger";
const CHANNEL_TYPE_VIBER = "viber";
const CHANNEL_TYPE_WHATSAPP = "whatsapp";
const CHANNEL_TYPE_SKYPE = "skype";
const CHANNEL_TYPE_VK = "vk";
const CHANNEL_TYPE_INSTAGRAM = "instagram";
const CHANNEL_TYPE_CONSULTANT = "consultant";
const CHANNEL_TYPE_CUSTOM = "custom";
const CHAT_MEMBER_STATE_ACTIVE = "active";
const CHAT_MEMBER_STATE_KICKED = "kicked";
const CHAT_MEMBER_STATE_LEAVED = "leaved";
const CHANNEL_FEATURE_NONE = "none";
const CHANNEL_FEATURE_RECEIVE = "receive";
const CHANNEL_FEATURE_SEND = "send";
const CHANNEL_FEATURE_BOTH = "both";
const BOT_ROLE_DISTRIBUTOR = "distributor";
const BOT_ROLE_RESPONSIBLE = "responsible";
const MESSAGE_SCOPE_PUBLIC = "public";
const MESSAGE_SCOPE_PRIVATE = "private";
const MESSAGE_TYPE_TEXT = "text";
const MESSAGE_TYPE_SYSTEM = "system";
const MESSAGE_TYPE_COMMAND = "command";
const MESSAGE_TYPE_ORDER = "order";
const MESSAGE_TYPE_PRODUCT = "product";
const MESSAGE_TYPE_FILE = "file";
const MESSAGE_TYPE_IMAGE = "image";
const MESSAGE_ORDER_STATUS_CODE_NEW = "new";
const MESSAGE_ORDER_STATUS_CODE_APPROVAL = "approval";
const MESSAGE_ORDER_STATUS_CODE_ASSEMBLING = "assembling";
const MESSAGE_ORDER_STATUS_CODE_DELIVERY = "delivery";
const MESSAGE_ORDER_STATUS_CODE_COMPLETE = "complete";
const MESSAGE_ORDER_STATUS_CODE_CANCEL = "cancel";
const WS_EVENT_MESSAGE_NEW = "message_new";
const WS_EVENT_MESSAGE_UPDATED = "message_updated";
const WS_EVENT_MESSAGE_DELETED = "message_deleted";
const WS_EVENT_DIALOG_OPENED = "dialog_opened";
const WS_EVENT_DIALOG_CLOSED = "dialog_closed";
const WS_EVENT_DIALOG_ASSIGN = "dialog_assign";
const WS_EVENT_CHAT_CREATED = "chat_created";
const WS_EVENT_CHAT_UPDATED = "chat_updated";
const WS_EVENT_CHAT_UNREAD_UPDATED = "chat_unread_updated";
const WS_EVENT_USER_ONLINE_UPDATED = "user_online_updated";
const WS_EVENT_USER_JOINED = "user_joined_chat";
const WS_EVENT_USER_LEAVE = "user_left_chat";
const WS_EVENT_USER_UPDATED = "user_updated";
const WS_EVENT_CUSTOMER_UPDATED = "customer_updated";
const WS_EVENT_BOT_UPDATED = "bot_updated";
const WS_EVENT_CHANNEL_UPDATED = "channel_updated";
const WS_EVENT_SETTINGS_UPDATED = "settings_updated";
}

View File

@ -0,0 +1,82 @@
<?php
/**
* PHP version 7.0
*
* Cost 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
*
* Cost 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 Cost
{
/**
* @var float $value
*
* @Type("float")
* @Accessor(getter="getValue",setter="setValue")
* @SkipWhenEmpty()
*/
private $value;
/**
* @var string $currency
*
* @Type("string")
* @Accessor(getter="getCurrency",setter="setCurrency")
*
* @Assert\Currency
*/
private $currency;
/**
* @return float
*/
public function getValue()
{
return $this->value;
}
/**
* @param float $value
*/
public function setValue(float $value)
{
$this->value = $value;
}
/**
* @return string
*/
public function getCurrency()
{
return $this->currency;
}
/**
* @param string $currency
*/
public function setCurrency(string $currency)
{
$this->currency = $currency;
}
}

View File

@ -0,0 +1,133 @@
<?php
/**
* PHP version 7.0
*
* Delivery 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
*
* Delivery 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 Delivery
{
/**
* @var string $name
*
* @Type("string")
* @Accessor(getter="getName",setter="setName")
*
* @Assert\NotBlank
*/
private $name;
/**
* @var Cost $price
*
* @Type("Cost")
* @Accessor(getter="getPrice",setter="setPrice")
*
* @Assert\Currency
*/
private $price;
/**
* @var string $address
*
* @Type("string")
* @Accessor(getter="getAddress",setter="setAddress")
* @SkipWhenEmpty()
*/
private $address;
/**
* @var string $comment
*
* @Type("string")
* @Accessor(getter="getComment",setter="setComment")
* @SkipWhenEmpty()
*/
private $comment;
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name)
{
$this->name = $name;
}
/**
* @return Cost
*/
public function getPrice()
{
return $this->price;
}
/**
* @param Cost $price
*/
public function setPrice(Cost $price)
{
$this->price = $price;
}
/**
* @return string
*/
public function getAddress()
{
return $this->address;
}
/**
* @param string $address
*/
public function setAddress(string $address)
{
$this->address = $address;
}
/**
* @return string
*/
public function getComment()
{
return $this->comment;
}
/**
* @param string $comment
*/
public function setComment(string $comment)
{
$this->comment = $comment;
}
}

View File

@ -0,0 +1,81 @@
<?php
/**
* PHP version 7.0
*
* Item 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
*
* Item 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 Item
{
/**
* @var string $id
*
* @Type("string")
* @Accessor(getter="getId",setter="setId")
* @SkipWhenEmpty()
*/
private $id;
/**
* @var string $caption
*
* @Type("string")
* @Accessor(getter="getCaption",setter="setCaption")
* @SkipWhenEmpty()
*/
private $caption;
/**
* @return string
*/
public function getId()
{
return $this->id;
}
/**
* @param string $id
*/
public function setId(string $id)
{
$this->id = $id;
}
/**
* @return string
*/
public function getCaption()
{
return $this->caption;
}
/**
* @param string $caption
*/
public function setCaption(string $caption)
{
$this->caption = $caption;
}
}

View File

@ -0,0 +1,231 @@
<?php
/**
* PHP version 7.0
*
* Order 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
*
* Order 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 Order
{
/**
* @var string $number
*
* @Type("string")
* @Accessor(getter="getNumber",setter="setNumber")
* @SkipWhenEmpty()
*/
private $number;
/**
* @var string $url
*
* @Type("string")
* @Accessor(getter="getUrl",setter="setUrl")
* @SkipWhenEmpty()
*/
private $url;
/**
* @var string $date
*
* @Type("string")
* @Accessor(getter="getDate",setter="setDate")
* @SkipWhenEmpty()
*/
private $date;
/**
* @var Cost $cost
*
* @Type("Cost")
* @Accessor(getter="getCost",setter="setCost")
* @SkipWhenEmpty()
*/
private $cost;
/**
* @var Status $status
*
* @Type("Status")
* @Accessor(getter="getStatus",setter="setStatus")
* @SkipWhenEmpty()
*/
private $status;
/**
* @var Delivery $delivery
*
* @Type("Delivery")
* @Accessor(getter="getDelivery",setter="setDelivery")
* @SkipWhenEmpty()
*/
private $delivery;
/**
* @var array $items
*
* @Type("array")
* @Accessor(getter="getItems",setter="setItems")
* @SkipWhenEmpty()
*/
private $items;
/**
* @var array $payments
*
* @Type("array")
* @Accessor(getter="getPayments",setter="setPayments")
* @SkipWhenEmpty()
*/
private $payments;
/**
* @return string
*/
public function getNumber()
{
return $this->number;
}
/**
* @param string $number
*/
public function setNumber(string $number)
{
$this->number = $number;
}
/**
* @return string
*/
public function getUrl()
{
return $this->url;
}
/**
* @param string $url
*/
public function setUrl(string $url)
{
$this->url = $url;
}
/**
* @return string
*/
public function getDate()
{
return $this->date;
}
/**
* @param string $date
*/
public function setDate(string $date)
{
$this->date = $date;
}
/**
* @return Cost
*/
public function getCost()
{
return $this->cost;
}
/**
* @param Cost $cost
*/
public function setCost(Cost $cost)
{
$this->cost = $cost;
}
/**
* @return Status
*/
public function getStatus()
{
return $this->status;
}
/**
* @param Status $status
*/
public function setStatus(Status $status)
{
$this->status = $status;
}
/**
* @return Delivery
*/
public function getDelivery()
{
return $this->delivery;
}
/**
* @param Delivery $delivery
*/
public function setDelivery(Delivery $delivery)
{
$this->delivery = $delivery;
}
/**
* @return array
*/
public function getItems()
{
return $this->items;
}
/**
* @param array $items
*/
public function setItems(array $items)
{
$this->items = $items;
}
/**
* @return array
*/
public function getPayments()
{
return $this->payments;
}
/**
* @param array $payments
*/
public function setPayments(array $payments)
{
$this->payments = $payments;
}
}

View File

@ -0,0 +1,156 @@
<?php
/**
* PHP version 7.0
*
* Order item 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
*
* OrderItem 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 OrderItem
{
/**
* @var string $name
*
* @Type("string")
* @Accessor(getter="getName",setter="setName")
* @SkipWhenEmpty()
*/
private $name;
/**
* @var string $url
*
* @Type("string")
* @Accessor(getter="getUrl",setter="setUrl")
* @SkipWhenEmpty()
*/
private $url;
/**
* @var string $img
*
* @Type("string")
* @Accessor(getter="getImg",setter="setImg")
* @SkipWhenEmpty()
*/
private $img;
/**
* @var Cost $price
*
* @Type("Cost")
* @Accessor(getter="getPrice",setter="setPrice")
* @SkipWhenEmpty()
*/
private $price;
/**
* @var Quantity $quantity
*
* @Type("Quantity")
* @Accessor(getter="getQuantity",setter="setQuantity)
* @SkipWhenEmpty()
*/
private $quantity;
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name)
{
$this->name = $name;
}
/**
* @return string
*/
public function getUrl()
{
return $this->url;
}
/**
* @param string $url
*/
public function setUrl(string $url)
{
$this->url = $url;
}
/**
* @return string
*/
public function getImg()
{
return $this->img;
}
/**
* @param string $img
*/
public function setImg(string $img)
{
$this->img = $img;
}
/**
* @return Cost
*/
public function getPrice()
{
return $this->price;
}
/**
* @param Cost $price
*/
public function setPrice(Cost $price)
{
$this->price = $price;
}
/**
* @return Quantity
*/
public function getQuantity()
{
return $this->quantity;
}
/**
* @param Quantity $quantity
*/
public function setQuantity(Quantity $quantity)
{
$this->quantity = $quantity;
}
}

View File

@ -0,0 +1,106 @@
<?php
/**
* PHP version 7.0
*
* Payment 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
*
* Payment 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 Payment
{
/**
* @var string $name
*
* @Type("string")
* @Accessor(getter="getName",setter="setName")
* @SkipWhenEmpty()
*/
private $name;
/**
* @var PaymentStatus $status
*
* @Type("PaymentStatus")
* @Accessor(getter="getStatus",setter="setStatus")
* @SkipWhenEmpty()
*/
private $status;
/**
* @var Cost $amount
*
* @Type("Cost")
* @Accessor(getter="getAmount",setter="setAmount")
* @SkipWhenEmpty()
*/
private $amount;
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name)
{
$this->name = $name;
}
/**
* @return PaymentStatus
*/
public function getStatus()
{
return $this->status;
}
/**
* @param PaymentStatus $status
*/
public function setStatus(PaymentStatus $status)
{
$this->status = $status;
}
/**
* @return Cost
*/
public function getAmount()
{
return $this->amount;
}
/**
* @param Cost $amount
*/
public function setAmount(Cost $amount)
{
$this->amount = $amount;
}
}

View File

@ -0,0 +1,81 @@
<?php
/**
* PHP version 7.0
*
* Payment status 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
*
* PaymentStatus 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 PaymentStatus
{
/**
* @var string $name
*
* @Type("string")
* @Accessor(getter="getName",setter="setName")
* @SkipWhenEmpty()
*/
private $name;
/**
* @var bool $payed
*
* @Type("bool")
* @Accessor(getter="getPayed",setter="setPayed")
* @SkipWhenEmpty()
*/
private $payed;
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name)
{
$this->name = $name;
}
/**
* @return bool
*/
public function isPayed()
{
return $this->payed;
}
/**
* @param bool $payed
*/
public function setPayed(bool $payed)
{
$this->payed = $payed;
}
}

View File

@ -0,0 +1,206 @@
<?php
/**
* PHP version 7.0
*
* Product 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
*
* Product 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 Product
{
/**
* @var int $id
*
* @Type("int")
* @Accessor(getter="getId",setter="setId")
* @SkipWhenEmpty()
*/
private $id;
/**
* @var string $name
*
* @Type("string")
* @Accessor(getter="getName",setter="setName")
* @SkipWhenEmpty()
*/
private $name;
/**
* @var string $article
*
* @Type("string")
* @Accessor(getter="getArticle",setter="setArticle")
* @SkipWhenEmpty()
*/
private $article;
/**
* @var string $url
*
* @Type("string")
* @Accessor(getter="getUrl",setter="setUrl")
* @SkipWhenEmpty()
*/
private $url;
/**
* @var string $img
*
* @Type("string")
* @Accessor(getter="getImg",setter="setImg")
* @SkipWhenEmpty()
*/
private $img;
/**
* @var Cost $cost
*
* @Type("Cost")
* @Accessor(getter="getCost",setter="setCost")
* @SkipWhenEmpty()
*/
private $cost;
/**
* @var Quantity $quantity
*
* @Type("Quantity")
* @Accessor(getter="getQuantity",setter="setQuantity)
* @SkipWhenEmpty()
*/
private $quantity;
/**
* @return int
*/
public function getId(): int
{
return $this->id;
}
/**
* @param int $id
*/
public function setId(int $id)
{
$this->id = $id;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name)
{
$this->name = $name;
}
/**
* @return string
*/
public function getArticle()
{
return $this->article;
}
/**
* @param string $article
*/
public function setArticle(string $article)
{
$this->article = $article;
}
/**
* @return string
*/
public function getUrl()
{
return $this->url;
}
/**
* @param string $url
*/
public function setUrl(string $url)
{
$this->url = $url;
}
/**
* @return string
*/
public function getImg()
{
return $this->img;
}
/**
* @param string $img
*/
public function setImg(string $img)
{
$this->img = $img;
}
/**
* @return Cost
*/
public function getCost()
{
return $this->cost;
}
/**
* @param Cost $cost
*/
public function setCost(Cost $cost)
{
$this->cost = $cost;
}
/**
* @return Quantity
*/
public function getQuantity()
{
return $this->quantity;
}
/**
* @param Quantity $quantity
*/
public function setQuantity(Quantity $quantity)
{
$this->quantity = $quantity;
}
}

View File

@ -0,0 +1,82 @@
<?php
/**
* PHP version 7.0
*
* Quantity 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
*
* Quantity 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 Quantity
{
/**
* @var float $value
*
* @Type("float")
* @Accessor(getter="getValue",setter="setValue")
* @SkipWhenEmpty()
*/
private $value;
/**
* @var string $unit
*
* @Type("string")
* @Accessor(getter="getUnit",setter="setUnit")
*
* @Assert\Currency
*/
private $unit;
/**
* @return float
*/
public function getValue()
{
return $this->value;
}
/**
* @param float $value
*/
public function setValue(float $value)
{
$this->value = $value;
}
/**
* @return string
*/
public function getUnit()
{
return $this->unit;
}
/**
* @param string $unit
*/
public function setUnit(string $unit)
{
$this->unit = $unit;
}
}

View File

@ -0,0 +1,81 @@
<?php
/**
* PHP version 7.0
*
* Status 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
*
* Status 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 Status
{
/**
* @var string $code
*
* @Type("string")
* @Accessor(getter="getCode",setter="setCode")
* @SkipWhenEmpty()
*/
private $code;
/**
* @var string $name
*
* @Type("string")
* @Accessor(getter="getName",setter="setName")
* @SkipWhenEmpty()
*/
private $name;
/**
* @return string
*/
public function getCode()
{
return $this->code;
}
/**
* @param string $code
*/
public function setCode(string $code)
{
$this->code = $code;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name)
{
$this->name = $name;
}
}

View File

@ -0,0 +1,102 @@
<?php
/**
* PHP version 7.0
*
* Bots 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\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* BotsRequest 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 BotsRequest
{
use CommonFields;
/**
* @Type("int")
* @Accessor(getter="getActive",setter="setActive")
* @SkipWhenEmpty
*/
private $active;
/**
* @Type("int")
* @Accessor(getter="getSelf",setter="setSelf")
* @SkipWhenEmpty
*/
private $self;
/**
* @Type("array")
* @Accessor(getter="getRoles",setter="setRoles")
* @SkipWhenEmpty
*/
private $roles;
/**
* @return int
*/
public function getSelf()
{
return $this->self;
}
/**
* @param int $self
*/
public function setSelf($self)
{
$this->self = $self;
}
/**
* @return int
*/
public function getActive()
{
return $this->active;
}
/**
* @param int $active
*/
public function setActive($active)
{
$this->active = $active;
}
/**
* @return array
*/
public function getRoles()
{
return $this->roles;
}
/**
* @param array $roles
*/
public function setRoles($roles)
{
$this->roles = $roles;
}
}

View File

@ -0,0 +1,79 @@
<?php
/**
* PHP version 7.0
*
* Channels list 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\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* ChannelsRequest 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 ChannelsRequest
{
use CommonFields;
/**
* @Type("array")
* @Accessor(getter="getTypes",setter="setTypes")
* @SkipWhenEmpty
*/
private $types;
/**
* @Type("int")
* @Accessor(getter="getActive",setter="setActive")
* @SkipWhenEmpty
*/
private $active;
/**
* @return array
*/
public function getTypes()
{
return $this->types;
}
/**
* @param array $types
*/
public function setTypes($types)
{
$this->types = $types;
}
/**
* @return int
*/
public function getActive()
{
return $this->active;
}
/**
* @param int $active
*/
public function setActive($active)
{
$this->active = $active;
}
}

View File

@ -0,0 +1,79 @@
<?php
/**
* PHP version 7.0
*
* Chats list 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\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* ChatsRequest 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 ChatsRequest
{
use CommonFields;
/**
* @Type("int")
* @Accessor(getter="getChannelId",setter="setChannelId")
* @SkipWhenEmpty()
*/
private $channelId;
/**
* @Type("string")
* @Accessor(getter="getChannelType",setter="setChannelType")
* @SkipWhenEmpty()
*/
private $channelType;
/**
* @return int
*/
public function getChannelId()
{
return $this->channelId;
}
/**
* @param int $channelId
*/
public function setChannelId($channelId)
{
$this->channelId = $channelId;
}
/**
* @return string
*/
public function getChannelType()
{
return $this->channelType;
}
/**
* @param string $channelType
*/
public function setChannelType($channelType)
{
$this->channelType = $channelType;
}
}

View File

@ -0,0 +1,109 @@
<?php
/**
* PHP version 7.0
*
* Edit Command 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\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use Symfony\Component\Validator\Constraints as Assert;
/**
* PHP version 7.0
*
* CommandEditRequest 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 CommandEditRequest
{
/**
* @var int $botId
*
* @Type("int")
* @Accessor(getter="getBotId",setter="setBotId")
*
* @Assert\NotBlank
*/
private $botId;
/**
* @var string $name
*
* @Type("string")
* @Accessor(getter="getName",setter="setName")
*
* @Assert\NotBlank
*/
private $name;
/**
* @var string $description
*
* @Type("string")
* @Accessor(getter="getDescription",setter="setDescription")
* @SkipWhenEmpty
*/
private $description;
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name)
{
$this->name = $name;
}
/**
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* @param string $description
*/
public function setDescription(string $description)
{
$this->description = $description;
}
/**
* @return int
*/
public function getBotId()
{
return $this->botId;
}
/**
* @param int $botId
*/
public function setBotId(int $botId)
{
$this->botId = $botId;
}
}

View File

@ -0,0 +1,56 @@
<?php
/**
* PHP version 7.0
*
* Commands list 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\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* CommandsRequest 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 CommandsRequest
{
use CommonFields;
/**
* @Type("string")
* @Accessor(getter="getName",setter="setName")
* @SkipWhenEmpty
*/
private $name;
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName($name)
{
$this->name = $name;
}
}

View File

@ -0,0 +1,100 @@
<?php
/**
* PHP version 7.0
*
* Common fields
*
* @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\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* CommonFields trait
*
* @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
*/
trait CommonFields
{
/**
* @Type("int")
* @Accessor(getter="getId",setter="setId")
* @SkipWhenEmpty
*/
private $id;
/**
* @Type("string")
* @Accessor(getter="getSince",setter="setSince")
* @SkipWhenEmpty
*/
private $since;
/**
* @Type("string")
* @Accessor(getter="getUntil",setter="setUntil")
* @SkipWhenEmpty
*/
private $until;
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*/
public function setId($id)
{
$this->id = $id;
}
/**
* @return string
*/
public function getSince()
{
return $this->since;
}
/**
* @param string $since
*/
public function setSince($since)
{
$this->since = $since;
}
/**
* @return string
*/
public function getUntil()
{
return $this->until;
}
/**
* @param string $until
*/
public function setUntil($until)
{
$this->until = $until;
}
}

View File

@ -0,0 +1,56 @@
<?php
/**
* PHP version 7.0
*
* Customers list 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\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* CustomersRequest 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 CustomersRequest
{
use CommonFields;
/**
* @Type("string")
* @Accessor(getter="getExternalId",setter="setExternalId")
* @SkipWhenEmpty
*/
private $externalId;
/**
* @return string
*/
public function getExternalId()
{
return $this->externalId;
}
/**
* @param string $externalId
*/
public function setExternalId($externalId)
{
$this->externalId = $externalId;
}
}

View File

@ -0,0 +1,106 @@
<?php
/**
* PHP version 7.0
*
* Dialog assign 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\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* DialogAssignRequest 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 DialogAssignRequest
{
/**
* @var int $dialogId
*
* @Type("int")
* @Accessor(getter="getDialogId,setter="setDialogId")
* @SkipWhenEmpty
*/
private $dialogId;
/**
* @var int $userId
*
* @Type("int")
* @Accessor(getter="getUserId",setter="setUserId")
* @SkipWhenEmpty
*/
private $userId;
/**
* @var int $botId
*
* @Type("int")
* @Accessor(getter="getBotId",setter="setBotId")
* @SkipWhenEmpty()
*/
private $botId;
/**
* @return int
*/
public function getDialogId()
{
return $this->dialogId;
}
/**
* @param int $dialogId
*/
public function setDialogId(int $dialogId)
{
$this->dialogId = $dialogId;
}
/**
* @return int
*/
public function getUserId()
{
return $this->userId;
}
/**
* @param int $userId
*/
public function setUserId(int $userId)
{
$this->userId = $userId;
}
/**
* @return int
*/
public function getBotId()
{
return $this->botId;
}
/**
* @param int $botId
*/
public function setBotId(int $botId)
{
$this->botId = $botId;
}
}

View File

@ -0,0 +1,158 @@
<?php
/**
* PHP version 7.0
*
* Dialogs list 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\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* DialogsRequest 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 DialogsRequest
{
use CommonFields;
/**
* @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 int $botId
*
* @Type("int")
* @Accessor(getter="getBotId",setter="setBotId")
* @SkipWhenEmpty()
*/
private $botId;
/**
* @var int $active
*
* @Type("int")
* @Accessor(getter="getActive",setter="setActive")
* @SkipWhenEmpty
*/
private $active;
/**
* @var int $assign
*
* @Type("int")
* @Accessor(getter="getAssign",setter="setAssign")
* @SkipWhenEmpty
*/
private $assign;
/**
* @return int
*/
public function getChatId()
{
return $this->chatId;
}
/**
* @param int $chatId
*/
public function setChatId(int $chatId)
{
$this->chatId = $chatId;
}
/**
* @return int
*/
public function getUserId()
{
return $this->userId;
}
/**
* @param int $userId
*/
public function setUserId(int $userId)
{
$this->userId = $userId;
}
/**
* @return int
*/
public function getBotId()
{
return $this->botId;
}
/**
* @param int $botId
*/
public function setBotId(int $botId)
{
$this->botId = $botId;
}
/**
* @return int
*/
public function getActive()
{
return $this->active;
}
/**
* @param int $active
*/
public function setActive(int $active)
{
$this->active = $active;
}
/**
* @return int
*/
public function getAssign()
{
return $this->assign;
}
/**
* @param int $assign
*/
public function setAssign(int $assign)
{
$this->assign = $assign;
}
}

View File

@ -0,0 +1,106 @@
<?php
/**
* PHP version 7.0
*
* Bot info 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\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* InfoRequest 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 InfoRequest
{
/**
* @var string $name
*
* @Type("string")
* @Accessor(getter="getName",setter="setName")
* @SkipWhenEmpty()
*/
private $name;
/**
* @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;
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name)
{
$this->name = $name;
}
/**
* @return string
*/
public function getAvatarUrl()
{
return $this->avatarUrl;
}
/**
* @param string $avatarUrl
*/
public function setAvatarUrl(string $avatarUrl)
{
$this->avatarUrl = $avatarUrl;
}
/**
* @return array
*/
public function getRoles()
{
return $this->roles;
}
/**
* @param array $roles
*/
public function setRoles(array $roles)
{
$this->roles = $roles;
}
}

View File

@ -0,0 +1,156 @@
<?php
/**
* PHP version 7.0
*
* Members list 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\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* MembersRequest 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 MembersRequest
{
/**
* @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 string $state
*
* @Type("string")
* @Accessor(getter="getState",setter="setState")
* @SkipWhenEmpty
*/
private $state;
/**
* @var string $since
*
* @Type("string")
* @Accessor(getter="getSince",setter="setSince")
* @SkipWhenEmpty
*/
private $since;
/**
* @var string $until
*
* @Type("string")
* @Accessor(getter="getUntil",setter="setUntil")
* @SkipWhenEmpty
*/
private $until;
/**
* @return int
*/
public function getChatId()
{
return $this->chatId;
}
/**
* @param int $chatId
*/
public function setChatId(int $chatId)
{
$this->chatId = $chatId;
}
/**
* @return int
*/
public function getUserId()
{
return $this->userId;
}
/**
* @param int $userId
*/
public function setUserId(int $userId)
{
$this->userId = $userId;
}
/**
* @return string
*/
public function getState()
{
return $this->state;
}
/**
* @param string $state
*/
public function setState(string $state)
{
$this->state = $state;
}
/**
* @return string
*/
public function getSince()
{
return $this->since;
}
/**
* @param string $since
*/
public function setSince(string $since)
{
$this->since = $since;
}
/**
* @return string
*/
public function getUntil()
{
return $this->until;
}
/**
* @param string $until
*/
public function setUntil(string $until)
{
$this->until = $until;
}
}

View File

@ -0,0 +1,81 @@
<?php
/**
* PHP version 7.0
*
* Messages edit 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\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* MessageEditRequest 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 MessageEditRequest
{
/**
* @var int $id
*
* @Type("int")
* @Accessor(getter="getId",setter="setId")
* @SkipWhenEmpty()
*/
private $id;
/**
* @var string $content
*
* @Type("string")
* @Accessor(getter="getContent",setter="setContent")
* @SkipWhenEmpty()
*/
private $content;
/**
* @return int
*/
public function getId()
{
return $this->id;
}
/**
* @param int $id
*/
public function setId(int $id)
{
$this->id = $id;
}
/**
* @return string
*/
public function getContent()
{
return $this->content;
}
/**
* @param string $content
*/
public function setContent(string $content)
{
$this->content = $content;
}
}

View File

@ -0,0 +1,239 @@
<?php
/**
* PHP version 7.0
*
* Messages send 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\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use Symfony\Component\Validator\Constraints as Assert;
use RetailCrm\Mg\Bot\Model\Entity\Order;
use RetailCrm\Mg\Bot\Model\Entity\Product;
/**
* PHP version 7.0
*
* MessageSendRequest 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 MessageSendRequest
{
/**
* @var string $type
*
* @Type("string")
* @Accessor(getter="getType",setter="setType")
* @SkipWhenEmpty()
*/
private $type;
/**
* @var string $content
*
* @Type("string")
* @Accessor(getter="getContent",setter="setContent")
*
* @Assert\NotBlank
*/
private $content;
/**
* @var Product $product
*
* @Type("Product")
* @Accessor(getter="getProduct",setter="setProduct")
* @SkipWhenEmpty()
*/
private $product;
/**
* @var Order $order
*
* @Type("Order")
* @Accessor(getter="getOrder",setter="setOrder")
* @SkipWhenEmpty()
*/
private $order;
/**
* @var array $items
*
* @Type("array")
* @Accessor(getter="getItems",setter="setItems")
* @SkipWhenEmpty()
*/
private $items;
/**
* @var string $scope
*
* @Type("string")
* @Accessor(getter="getScope",setter="setScope")
*
* @Assert\NotBlank
*/
private $scope;
/**
* @var int $chatId
*
* @Type("int")
* @Accessor(getter="getChatId",setter="setChatId")
*
* @Assert\NotBlank
*/
private $chatId;
/**
* @var int $quoteMessageId
*
* @Type("int")
* @Accessor(getter="getQuoteMessageId",setter="setQuoteMessageId")
* @SkipWhenEmpty
*/
private $quoteMessageId;
/**
* @return int
*/
public function getChatId()
{
return $this->chatId;
}
/**
* @param int $chatId
*/
public function setChatId(int $chatId)
{
$this->chatId = $chatId;
}
/**
* @return string
*/
public function getScope()
{
return $this->scope;
}
/**
* @param string $scope
*/
public function setScope(string $scope)
{
$this->scope = $scope;
}
/**
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* @param string $type
*/
public function setType(string $type)
{
$this->type = $type;
}
/**
* @return string
*/
public function getContent()
{
return $this->content;
}
/**
* @param string $content
*/
public function setContent(string $content)
{
$this->content = $content;
}
/**
* @return Product
*/
public function getProduct()
{
return $this->product;
}
/**
* @param Product $product
*/
public function setProduct(Product $product)
{
$this->product = $product;
}
/**
* @return Order
*/
public function getOrder()
{
return $this->order;
}
/**
* @param Order $order
*/
public function setOrder(Order $order)
{
$this->order = $order;
}
/**
* @return array
*/
public function getItems()
{
return $this->items;
}
/**
* @param array $items
*/
public function setItems(array $items)
{
$this->items = $items;
}
/**
* @return int
*/
public function getQuoteMessageId()
{
return $this->quoteMessageId;
}
/**
* @param int $quoteMessageId
*/
public function setQuoteMessageId(int $quoteMessageId)
{
$this->quoteMessageId = $quoteMessageId;
}
}

View File

@ -0,0 +1,258 @@
<?php
/**
* PHP version 7.0
*
* Messages list 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\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* MessagesRequest 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 MessagesRequest
{
use CommonFields;
/**
* @var int $chatId
*
* @Type("int")
* @Accessor(getter="getChatId",setter="setChatId")
* @SkipWhenEmpty
*/
private $chatId;
/**
* @var int $dialogId
*
* @Type("int")
* @Accessor(getter="getDialogId",setter="setDialogId")
* @SkipWhenEmpty
*/
private $dialogId;
/**
* @var int $userId
*
* @Type("int")
* @Accessor(getter="getUserId",setter="setUserId")
* @SkipWhenEmpty
*/
private $userId;
/**
* @var int $customerId
*
* @Type("int")
* @Accessor(getter="getCustomerId",setter="setCustomerId")
* @SkipWhenEmpty()
*/
private $customerId;
/**
* @var int $botId
*
* @Type("int")
* @Accessor(getter="getBotId",setter="setBotId")
* @SkipWhenEmpty()
*/
private $botId;
/**
* @var int $channelId
*
* @Type("int")
* @Accessor(getter="getChannelId",setter="setChannelId")
* @SkipWhenEmpty()
*/
private $channelId;
/**
* @var string $channelType
*
* @Type("string")
* @Accessor(getter="getChannelType",setter="setChannelType")
* @SkipWhenEmpty()
*/
private $channelType;
/**
* @var string $scope
*
* @Type("string")
* @Accessor(getter="getScope",setter="setScope")
* @SkipWhenEmpty()
*/
private $scope;
/**
* @var string $type
*
* @Type("string")
* @Accessor(getter="getType",setter="setType")
* @SkipWhenEmpty()
*/
private $type;
/**
* @return int
*/
public function getChatId()
{
return $this->chatId;
}
/**
* @param int $chatId
*/
public function setChatId(int $chatId)
{
$this->chatId = $chatId;
}
/**
* @return int
*/
public function getDialogId()
{
return $this->dialogId;
}
/**
* @param int $dialogId
*/
public function setDialogId(int $dialogId)
{
$this->dialogId = $dialogId;
}
/**
* @return int
*/
public function getUserId()
{
return $this->userId;
}
/**
* @param int $userId
*/
public function setUserId(int $userId)
{
$this->userId = $userId;
}
/**
* @return int
*/
public function getCustomerId()
{
return $this->customerId;
}
/**
* @param int $customerId
*/
public function setCustomerId(int $customerId)
{
$this->customerId = $customerId;
}
/**
* @return int
*/
public function getBotId()
{
return $this->botId;
}
/**
* @param int $botId
*/
public function setBotId(int $botId)
{
$this->botId = $botId;
}
/**
* @return int
*/
public function getChannelId()
{
return $this->channelId;
}
/**
* @param int $channelId
*/
public function setChannelId(int $channelId)
{
$this->channelId = $channelId;
}
/**
* @return string
*/
public function getChannelType()
{
return $this->channelType;
}
/**
* @param string $channelType
*/
public function setChannelType(string $channelType)
{
$this->channelType = $channelType;
}
/**
* @return string
*/
public function getScope()
{
return $this->scope;
}
/**
* @param string $scope
*/
public function setScope(string $scope)
{
$this->scope = $scope;
}
/**
* @return string
*/
public function getType()
{
return $this->type;
}
/**
* @param string $type
*/
public function setType(string $type)
{
$this->type = $type;
}
}

View File

@ -0,0 +1,102 @@
<?php
/**
* PHP version 7.0
*
* Users list 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\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
/**
* PHP version 7.0
*
* UsersRequest 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 UsersRequest
{
use CommonFields;
/**
* @Type("string")
* @Accessor(getter="getExternalId",setter="setExternalId")
* @SkipWhenEmpty
*/
private $externalId;
/**
* @Type("int")
* @Accessor(getter="getActive",setter="setActive")
* @SkipWhenEmpty
*/
private $active;
/**
* @Type("int")
* @Accessor(getter="getOnline",setter="setOnline")
* @SkipWhenEmpty
*/
private $online;
/**
* @return string
*/
public function getExternalId()
{
return $this->externalId;
}
/**
* @param string $externalId
*/
public function setExternalId($externalId)
{
$this->externalId = $externalId;
}
/**
* @return int
*/
public function getActive()
{
return $this->active;
}
/**
* @param int $active
*/
public function setActive($active)
{
$this->active = $active;
}
/**
* @return int
*/
public function getOnline()
{
return $this->online;
}
/**
* @param int $online
*/
public function setOnline($online)
{
$this->online = $online;
}
}

View File

205
src/Bot/Request.php Normal file
View File

@ -0,0 +1,205 @@
<?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;
}
}

229
src/Bot/Response.php Normal file
View File

@ -0,0 +1,229 @@
<?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

@ -0,0 +1,30 @@
<?php
/**
* PHP version 7.0
*
* CurlException
*
* @package RetailCrm\Common\Exception
* @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;
/**
* PHP version 7.0
*
* Class CurlException
*
* @package RetailCrm\Common\Exception
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class CurlException extends RuntimeException
{
}

View File

@ -0,0 +1,30 @@
<?php
/**
* PHP version 7.0
*
* CurlException
*
* @package RetailCrm\Common\Exception
* @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 DomainException;
/**
* PHP version 7.0
*
* Class InvalidJsonException
*
* @package RetailCrm\Common\Exception
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class InvalidJsonException extends DomainException
{
}

View File

@ -0,0 +1,30 @@
<?php
/**
* PHP version 7.0
*
* CurlException
*
* @package RetailCrm\Common\Exception
* @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 DomainException;
/**
* PHP version 7.0
*
* Class CurlException
*
* @package RetailCrm\Common\Exception
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class LimitException extends DomainException
{
}

346
src/Register.php Normal file
View File

@ -0,0 +1,346 @@
<?php
/**
* PHP version 7.0
*
* Register Helper
*
* @package RetailCrm\Common
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Common;
use JMS\Serializer\Annotation\Accessor;
use JMS\Serializer\Annotation\SkipWhenEmpty;
use JMS\Serializer\Annotation\Type;
use Symfony\Component\Validator\Constraints as Assert;
/**
* PHP version 7.0
*
* RequestHelper class
*
* @package RetailCrm\Common
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Register
{
/**
* @var string $code
*
* @Type("string")
* @Accessor(getter="getCode",setter="setCode")
*
* @Assert\NotBlank
*/
private $code;
/**
* @var string $integrationCode
*
* @Type("string")
* @Accessor(getter="getIntegrationCode",setter="setIntegrationCode")
*
* @Assert\NotBlank
*/
private $integrationCode;
/**
* @var string $active
* @Type("string")
* @Accessor(getter="getActive",setter="setActive")
* @SkipWhenEmpty
*/
private $active;
/**
* @var string $name
*
* @Type("string")
* @Accessor(getter="getName",setter="setName")
* @SkipWhenEmpty
*/
private $name;
/**
* @var string $logo
*
* @Type("string")
* @Accessor(getter="getLogo",setter="setLogo")
* @SkipWhenEmpty
*
* @Assert\Url(
* message = "The logo url is not a valid url",
* protocols = {"http", "https"}
* )
*/
private $logo;
/**
* @var string $clientId
*
* @Type("string")
* @Accessor(getter="getClientId",setter="setClientId")
*
* @Assert\NotBlank
*/
private $clientId;
/**
* @var string $baseUrl
*
* @Type("string")
* @Accessor(getter="getBaseUrl",setter="setBaseUrl")
*
* @Assert\NotBlank
* @Assert\Url(
* message = "The baseUrl is not a valid url",
* protocols = {"http", "https"}
* )
*/
private $baseUrl;
/**
* @var string $accountUrl
*
* @Type("string")
* @Accessor(getter="getAccountUrl",setter="setAccountUrl")
*
* @Assert\NotBlank
* @Assert\Url(
* message = "The baseUrl is not a valid url",
* protocols = {"http", "https"}
* )
*/
private $accountUrl;
/**
* @var array $actions
*
* @Type("array")
* @Accessor(getter="getActions",setter="setActions")
*
* @Assert\NotBlank
*/
private $actions;
/**
* @var array $availableCountries
*
* @Type("array")
* @Accessor(getter="getAvailableCountries",setter="setAvailableCountries")
* @SkipWhenEmpty
*/
private $availableCountries;
/**
* @var array $integrations
*
* @Type("array")
* @Accessor(getter="getIntegrations",setter="setIntegrations")
*
* @Assert\NotBlank
*/
private $integrations;
/**
* @return string
*/
public function getCode()
{
return $this->code;
}
/**
* @param string $code
*/
public function setCode(string $code)
{
$this->code = $code;
}
/**
* @return string
*/
public function getIntegrationCode()
{
return $this->integrationCode;
}
/**
* @param string $integrationCode
*/
public function setIntegrationCode(string $integrationCode)
{
$this->integrationCode = $integrationCode;
}
/**
* @return string
*/
public function getActive()
{
return $this->active;
}
/**
* @param string $active
*/
public function setActive(string $active)
{
$this->active = $active;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName(string $name)
{
$this->name = $name;
}
/**
* @return string
*/
public function getLogo()
{
return $this->logo;
}
/**
* @param string $logo
*/
public function setLogo(string $logo)
{
$this->logo = $logo;
}
/**
* @return string
*/
public function getClientId()
{
return $this->clientId;
}
/**
* @param string $clientId
*/
public function setClientId(string $clientId)
{
$this->clientId = $clientId;
}
/**
* @return string
*/
public function getBaseUrl()
{
return $this->baseUrl;
}
/**
* @param string $baseUrl
*/
public function setBaseUrl(string $baseUrl)
{
$this->baseUrl = $baseUrl;
}
/**
* @return string
*/
public function getAccountUrl()
{
return $this->accountUrl;
}
/**
* @param string $accountUrl
*/
public function setAccountUrl(string $accountUrl)
{
$this->accountUrl = $accountUrl;
}
/**
* @return array
*/
public function getActions()
{
return $this->actions;
}
/**
* @param array $actions
*/
public function setActions(array $actions)
{
$this->actions = $actions;
}
/**
* @return array
*/
public function getAvailableCountries()
{
return $this->availableCountries;
}
/**
* @param array $availableCountries
*/
public function setAvailableCountries(array $availableCountries)
{
$this->availableCountries = $availableCountries;
}
/**
* @return array
*/
public function getIntegrations()
{
return $this->integrations;
}
/**
* @param array $integrations
*/
public function setIntegrations(array $integrations)
{
$this->integrations = $integrations;
}
/**
* Get configuration as JSON
*
* @return array|string
*/
public function getJsonConfiguration()
{
return Serializer::serialize($this);
}
/**
* Get configuration as array
*
* @return array|string
*/
public function getArrayConfiguration()
{
return Serializer::serialize($this, Serializer::S_ARRAY);
}
}

58
src/Serializer.php Normal file
View File

@ -0,0 +1,58 @@
<?php
/**
* PHP version 7.0
*
* Serializer
*
* @package RetailCrm\Common
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Common;
use JMS\Serializer\SerializerBuilder;
/**
* PHP version 7.0
*
* Serializer class
*
* @package RetailCrm\Common
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Serializer
{
const S_ARRAY = 0;
const S_JSON = 1;
/**
* Serialize given object to JSON or Array
*
* @param object $request
* @param int $serialize
*
* @return array|string
*/
public static function serialize($request, $serialize = self::S_JSON)
{
$serialized = null;
$serializer = SerializerBuilder::create()->build();
switch ($serialize) {
case self::S_ARRAY:
$serialized = $serializer->toArray($request);
break;
case self::S_JSON:
default:
$serialized = $serializer->serialize($request, 'json');
break;
}
return $serialized;
}
}

126
src/Url.php Normal file
View File

@ -0,0 +1,126 @@
<?php
/**
* PHP version 7.0
*
* Url handler
*
* @package RetailCrm\Common
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
namespace RetailCrm\Common;
/**
* PHP version 7.0
*
* Url class
*
* @package RetailCrm\Common
* @author retailCRM <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://help.retailcrm.pro/docs/Developers
*/
class Url
{
const RFC_DEFAULT = 1;
const RFC_CUSTOM = 2;
private $parts = [];
public function __toString()
{
return $this->build();
}
/**
* Check trailing slash into url
*
* @param string $url
*
* @return string
*/
public static function normalizeUrl($url)
{
if ('/' !== $url[strlen($url) - 1]) {
$url .= '/';
}
return $url;
}
/**
* Build request url
*
* @param string $path
* @param array $parameters
* @param int $rfc
*
* @return string
*/
public function buildUrl($path, $parameters, $rfc = self::RFC_DEFAULT)
{
$url = $path;
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);
}
}
$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);
}
}

View File

@ -0,0 +1,54 @@
<?php
/**
* PHP version 5.4
*
* Test case class
*
* @package Test
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
namespace RetailCrm\Mg\Bot\Test;
use PHPUnit\Framework\TestCase as BaseCase;
use RetailCrm\Mg\Bot\Client;
/**
* Class TestCase
*
* @category RetailCrm
* @package Test
* @author RetailCrm <integration@retailcrm.ru>
* @license https://opensource.org/licenses/MIT MIT License
* @link http://www.retailcrm.ru/docs/Developers/ApiVersion5
*/
class TestCase extends BaseCase
{
/**
* Return bot api client object
*
* @param string $url (default: null)
* @param string $key (default: null)
* @param bool $debug (default: false)
*
* @return \RetailCrm\Mg\Bot\Client
*/
public static function getApiClient(
$url = null,
$key = null,
$debug = false
) {
$configUrl = getenv('MG_BOT_URL');
$configKey = getenv('MG_BOT_KEY');
$configDbg = getenv('MG_BOT_DBG');
return new Client(
$url ?: $configUrl,
$key ?: $configKey,
$debug ?: $configDbg
);
}
}

View File

@ -0,0 +1,178 @@
<?php
/**
* PHP version 7.0
*
* Client 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\Constants;
use RetailCrm\Mg\Bot\Model\Request;
use RetailCrm\Mg\Bot\Test\TestCase;
/**
* PHP version 7.0
*
* Class ClientListTest
*
* @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 ClientListTest extends TestCase
{
/**
* @group("list")
* @throws \Exception
*/
public function testChannels()
{
$client = self::getApiClient();
$request = new Request\ChannelsRequest();
$request->setActive(true);
$request->setTypes([Constants::CHANNEL_TYPE_FACEBOOK, Constants::CHANNEL_TYPE_INSTAGRAM]);
$response = $client->channels($request);
self::assertTrue($response->isSuccessful() == true);
}
/**
* @group("list")
* @throws \Exception
*/
public function testChats()
{
$client = self::getApiClient();
$request = new Request\ChatsRequest();
$request->setChannelType(Constants::CHANNEL_TYPE_FACEBOOK);
$response = $client->chats($request);
self::assertTrue($response->isSuccessful() == true);
}
/**
* @group("list")
* @throws \Exception
*/
public function testMembers()
{
$client = self::getApiClient();
$request = new Request\MembersRequest();
$response = $client->members($request);
self::assertTrue($response->isSuccessful() == true);
}
/**
* @group("list")
* @throws \Exception
*/
public function testMessages()
{
$client = self::getApiClient();
$request = new Request\MessagesRequest();
$request->setChannelType(Constants::CHANNEL_TYPE_INSTAGRAM);
$request->setType(Constants::MESSAGE_TYPE_TEXT);
$response = $client->messages($request);
self::assertTrue($response->isSuccessful() == true);
}
/**
* @group("list")
* @throws \Exception
*/
public function testCommands()
{
$client = self::getApiClient();
$request = new Request\CommandsRequest();
$response = $client->commands($request);
self::assertTrue($response->isSuccessful() == true);
}
/**
* @group("list")
* @throws \Exception
*/
public function testBots()
{
$client = self::getApiClient();
$request = new Request\BotsRequest();
$request->setActive(1);
$request->setRoles([Constants::BOT_ROLE_RESPONSIBLE]);
$response = $client->bots($request);
self::assertTrue($response->isSuccessful() == true);
}
/**
* @group("list")
* @throws \Exception
*/
public function testUsers()
{
$client = self::getApiClient();
$request = new Request\UsersRequest();
$request->setActive(1);
$request->setOnline(0);
$response = $client->users($request);
self::assertTrue($response->isSuccessful() == true);
}
/**
* @group("list")
* @throws \Exception
*/
public function testDialogs()
{
$client = self::getApiClient();
$request = new Request\DialogsRequest();
$request->setActive(1);
$request->setAssign(1);
$response = $client->dialogs($request);
self::assertTrue($response->isSuccessful() == true);
}
/**
* @group("list")
* @throws \Exception
*/
public function testCustomers()
{
$client = self::getApiClient();
$request = new Request\CustomersRequest();
$response = $client->customers($request);
self::assertTrue($response->isSuccessful() == true);
}
}

View File

@ -0,0 +1,95 @@
<?php
/**
* PHP version 7.0
*
* Client 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 Exception;
use InvalidArgumentException;
use RetailCrm\Mg\Bot\Model\Request\CommandEditRequest;
use RetailCrm\Mg\Bot\Test\TestCase;
/**
* PHP version 7.0
*
* Class ClientTest
*
* @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 CommandsTest extends TestCase
{
/**
* @group("commands")
* @throws \Exception
*/
public function testCommandEditException()
{
self::expectException(InvalidArgumentException::class);
$client = self::getApiClient();
$request = new CommandEditRequest();
$request->setDescription("qwerty");
$client->commandEdit($request);
}
/**
* @group("commands")
* @throws \Exception
*/
public function testCommandDeleteException()
{
self::expectException(Exception::class);
$client = self::getApiClient();
$request = "qwerty";
$client->commandDelete($request);
}
/**
* @group("commands")
* @throws \Exception
*/
public function testCommandEdit()
{
$client = self::getApiClient();
$request = new CommandEditRequest();
$request->setBotId(1);
$request->setName("show_payment_types");
$request->setDescription("Get available payment types");
$response = $client->commandEdit($request);
self::assertTrue($response->isSuccessful() == true);
}
/**
* @group("commands")
* @depends testCommandEdit
* @throws \Exception
*/
public function testCommandDelete()
{
$client = self::getApiClient();
$response = $client->commandDelete("show_payment_types");
self::assertTrue($response->isSuccessful() == true);
}
}

View File

@ -0,0 +1,54 @@
<?php
/**
* PHP version 7.0
*
* Client 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 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\MessageSendRequest;
use RetailCrm\Mg\Bot\Test\TestCase;
/**
* PHP version 7.0
*
* Class MessagesTest
*
* @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 MessagesTest extends TestCase
{
/**
* @group("messages")
* @throws \Exception
*/
public function testMessageSend()
{
$client = self::getApiClient();
$request = new MessageSendRequest();
$request->setChatId(0);
$request->setScope(Constants::MESSAGE_SCOPE_PUBLIC);
$request->setContent("Hello");
$request = $client->messageSend($request);
self::assertEquals($request->getStatusCode(), 400);
}
}

15
tests/bootstrap.php Normal file
View File

@ -0,0 +1,15 @@
<?php
if (function_exists('date_default_timezone_set')
&& function_exists('date_default_timezone_get')
) {
date_default_timezone_set(date_default_timezone_get());
}
$loader = include dirname(__DIR__) . '/vendor/autoload.php';
$loader->add('RetailCrm\\Mg\\Bot\\Test', __DIR__);
use Symfony\Component\Dotenv\Dotenv;
$dotenv = new Dotenv();
$dotenv->load(__DIR__ . '/../.env');