Added suggestions to MessageSendRequest (#16)
This commit is contained in:
parent
bb78a4ffb3
commit
c6a44ea2b3
74
src/Bot/Model/Entity/Message/Suggestion.php
Normal file
74
src/Bot/Model/Entity/Message/Suggestion.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 7.1
|
||||
*
|
||||
* Suggestion entity
|
||||
*
|
||||
* @package RetailCrm\Mg\Bot\Model\Entity\Message
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Mg\Bot\Model\Entity\Message;
|
||||
|
||||
use JMS\Serializer\Annotation\Accessor;
|
||||
use JMS\Serializer\Annotation\SkipWhenEmpty;
|
||||
use JMS\Serializer\Annotation\Type;
|
||||
use RetailCrm\Mg\Bot\Model\ModelInterface;
|
||||
|
||||
/**
|
||||
* Suggestion class
|
||||
*
|
||||
* @package RetailCrm\Mg\Bot\Model\Entity\Message
|
||||
*/
|
||||
class Suggestion implements ModelInterface
|
||||
{
|
||||
/**
|
||||
* @var string $title
|
||||
*
|
||||
* @Type("string")
|
||||
* @Accessor(getter="getTitle",setter="setTitle")
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
private $title;
|
||||
|
||||
/**
|
||||
* @var string $type
|
||||
*
|
||||
* @Type("string")
|
||||
* @Accessor(getter="getType",setter="setType")
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
private $type;
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getTitle(): ?string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $title
|
||||
*/
|
||||
public function setTitle(string $title)
|
||||
{
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getType(): ?string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $type
|
||||
*/
|
||||
public function setType(string $type)
|
||||
{
|
||||
$this->type = $type;
|
||||
}
|
||||
}
|
50
src/Bot/Model/Entity/Message/TransportAttachments.php
Normal file
50
src/Bot/Model/Entity/Message/TransportAttachments.php
Normal file
@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 7.1
|
||||
*
|
||||
* TransportAttachments entity
|
||||
*
|
||||
* @package RetailCrm\Mg\Bot\Model\Entity\Message
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Mg\Bot\Model\Entity\Message;
|
||||
|
||||
use JMS\Serializer\Annotation\Accessor;
|
||||
use JMS\Serializer\Annotation\SkipWhenEmpty;
|
||||
use JMS\Serializer\Annotation\Type;
|
||||
use RetailCrm\Mg\Bot\Model\ModelInterface;
|
||||
|
||||
/**
|
||||
* TransportAttachments class
|
||||
*
|
||||
* @package RetailCrm\Mg\Bot\Model\Entity\Message
|
||||
*/
|
||||
class TransportAttachments implements ModelInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @var array $suggestions
|
||||
*
|
||||
* @Type("array")
|
||||
* @Accessor(getter="getSuggestions",setter="setSuggestions")
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
private $suggestions;
|
||||
|
||||
/**
|
||||
* @param array $suggestions
|
||||
*/
|
||||
public function setSuggestions(array $suggestions): void
|
||||
{
|
||||
$this->suggestions = $suggestions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getSuggestions(): array
|
||||
{
|
||||
return $this->suggestions;
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@ use JMS\Serializer\Annotation\SkipWhenEmpty;
|
||||
use JMS\Serializer\Annotation\Type;
|
||||
use RetailCrm\Mg\Bot\Model\Entity\Message\MessageOrder;
|
||||
use RetailCrm\Mg\Bot\Model\Entity\Message\MessageProduct;
|
||||
use RetailCrm\Mg\Bot\Model\Entity\Message\TransportAttachments;
|
||||
use RetailCrm\Mg\Bot\Model\ModelInterface;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
@ -81,6 +82,16 @@ class MessageSendRequest implements ModelInterface
|
||||
*/
|
||||
private $scope;
|
||||
|
||||
|
||||
/**
|
||||
* @var TransportAttachments $transportAttachments
|
||||
*
|
||||
* @Type("RetailCrm\Mg\Bot\Model\Entity\Message\TransportAttachments")
|
||||
* @Accessor(getter="getTransportAttachments",setter="setTransportAttachments")
|
||||
* @SkipWhenEmpty
|
||||
*/
|
||||
private $transportAttachments;
|
||||
|
||||
/**
|
||||
* @var int $chatId
|
||||
*
|
||||
@ -134,6 +145,22 @@ class MessageSendRequest implements ModelInterface
|
||||
$this->scope = $scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return TransportAttachments
|
||||
*/
|
||||
public function getTransportAttachments()
|
||||
{
|
||||
return $this->transportAttachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param TransportAttachments $transportAttachments
|
||||
*/
|
||||
public function setTransportAttachments(TransportAttachments $transportAttachments)
|
||||
{
|
||||
$this->transportAttachments = $transportAttachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
@ -19,6 +19,8 @@ use RetailCrm\Mg\Bot\Model\Entity\Message\MessageOrderPaymentStatus;
|
||||
use RetailCrm\Mg\Bot\Model\Entity\Message\MessageProduct;
|
||||
use RetailCrm\Mg\Bot\Model\Entity\Message\MessageQuantity;
|
||||
use RetailCrm\Mg\Bot\Model\Entity\Message\MessageStatus;
|
||||
use RetailCrm\Mg\Bot\Model\Entity\Message\Suggestion;
|
||||
use RetailCrm\Mg\Bot\Model\Entity\Message\TransportAttachments;
|
||||
use RetailCrm\Mg\Bot\Model\Request\MessageEditRequest;
|
||||
use RetailCrm\Mg\Bot\Model\Request\MessageSendRequest;
|
||||
use RetailCrm\Mg\Bot\Model\Response\MessageSendResponse;
|
||||
@ -297,4 +299,66 @@ class MessagesTest extends TestCase
|
||||
self::assertTrue($response->isSuccessful());
|
||||
self::assertCount(0, $response->getErrors());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group("messages")
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testMessageSendSuggestions()
|
||||
{
|
||||
$client = self::getApiClient(
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
$this->getResponse(
|
||||
'{"message_id":3636,"time":"2019-06-24T06:02:04.434291791Z"}',
|
||||
201
|
||||
)
|
||||
);
|
||||
|
||||
$suggestionsData = [
|
||||
[
|
||||
'title' => 'Hello',
|
||||
'type' => 'text'
|
||||
],
|
||||
[
|
||||
'type' => 'email'
|
||||
],
|
||||
[
|
||||
'type' => 'phone'
|
||||
],
|
||||
];
|
||||
|
||||
|
||||
$suggestions = [];
|
||||
foreach ($suggestionsData as $suggestionsDatum) {
|
||||
$suggestion = new Suggestion();
|
||||
$suggestion->setType($suggestionsDatum['type']);
|
||||
|
||||
if (isset($suggestionsDatum['title'])) {
|
||||
$suggestion->setTitle($suggestionsDatum['title']);
|
||||
}
|
||||
|
||||
$suggestions[] = $suggestion;
|
||||
}
|
||||
|
||||
$transportAttachments = new TransportAttachments();
|
||||
$transportAttachments->setSuggestions($suggestions);
|
||||
|
||||
$request = new MessageSendRequest();
|
||||
$request->setChatId(28);
|
||||
$request->setScope(Constants::MESSAGE_SCOPE_PUBLIC);
|
||||
$request->setContent("Hello");
|
||||
$request->setTransportAttachments($transportAttachments);
|
||||
|
||||
$response = $client->messageSend($request);
|
||||
|
||||
self::assertInstanceOf(MessageSendResponse::class, $response);
|
||||
|
||||
if ($response instanceof MessageSendResponse) {
|
||||
self::assertTrue($response->isSuccessful());
|
||||
self::assertCount(0, $response->getErrors());
|
||||
self::assertEquals(3636, $response->getMessageId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user