yourtar-cli 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/botTemplate/.env.dev-example +23 -0
- package/bin/botTemplate/.env.prod-example +23 -0
- package/bin/botTemplate/.env.stage-example +23 -0
- package/bin/botTemplate/Makefile +38 -0
- package/bin/botTemplate/Readme.md +32 -0
- package/bin/botTemplate/config/packages/nelmio_cors.yaml +24 -0
- package/bin/botTemplate/docker/config/nginx/default.conf +22 -0
- package/bin/botTemplate/docker/config/php/php-ini-overrides.ini +0 -0
- package/bin/botTemplate/docker/docker-compose.dev.yml +73 -0
- package/bin/botTemplate/docker/docker-compose.prod.yml +91 -0
- package/bin/botTemplate/docker/docker-compose.stage.yml +82 -0
- package/bin/botTemplate/docker/dockerfile/cron/Dockerfile +36 -0
- package/bin/botTemplate/docker/dockerfile/cron/entrypoint.sh +12 -0
- package/bin/botTemplate/docker/dockerfile/cron/scheduler +1 -0
- package/bin/botTemplate/docker/dockerfile/php/Dockerfile +27 -0
- package/bin/botTemplate/src/Controller/MessageController.php +39 -0
- package/bin/botTemplate/src/Entity/Chat.php +112 -0
- package/bin/botTemplate/src/Entity/DialogContext.php +83 -0
- package/bin/botTemplate/src/Entity/Order.php +51 -0
- package/bin/botTemplate/src/Kernel.php +11 -0
- package/bin/botTemplate/src/Repository/ChatRepository.php +99 -0
- package/bin/botTemplate/src/Repository/DialogContextRepository.php +68 -0
- package/bin/botTemplate/src/Repository/OrderRepository.php +43 -0
- package/bin/botTemplate/src/Service/MessageProcessService.php +201 -0
- package/bin/botTemplate/src/Service/TelegramService.php +227 -0
- package/bin/frontTemplate/Makefile +3 -0
- package/bin/frontTemplate/README.md +5 -0
- package/bin/index.js +24 -0
- package/package.json +1 -1
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace App\Entity;
|
|
4
|
+
|
|
5
|
+
use App\Repository\DialogContextRepository;
|
|
6
|
+
use Doctrine\DBAL\Types\Types;
|
|
7
|
+
use Doctrine\ORM\Mapping as ORM;
|
|
8
|
+
|
|
9
|
+
#[ORM\Entity(repositoryClass: DialogContextRepository::class)]
|
|
10
|
+
class DialogContext
|
|
11
|
+
{
|
|
12
|
+
#[ORM\Id]
|
|
13
|
+
#[ORM\GeneratedValue]
|
|
14
|
+
#[ORM\Column]
|
|
15
|
+
private ?int $id = null;
|
|
16
|
+
|
|
17
|
+
#[ORM\OneToOne(cascade: ['persist'])]
|
|
18
|
+
#[ORM\JoinColumn(nullable: false)]
|
|
19
|
+
private ?Chat $chat = null;
|
|
20
|
+
|
|
21
|
+
#[ORM\Column(type: Types::ARRAY)]
|
|
22
|
+
private array $context = [];
|
|
23
|
+
|
|
24
|
+
public function getId(): ?int
|
|
25
|
+
{
|
|
26
|
+
return $this->id;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public function getChat(): ?Chat
|
|
30
|
+
{
|
|
31
|
+
return $this->chat;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public function setChat(Chat $chat): static
|
|
35
|
+
{
|
|
36
|
+
$this->chat = $chat;
|
|
37
|
+
|
|
38
|
+
return $this;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public function getContext(): array
|
|
42
|
+
{
|
|
43
|
+
return $this->context;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public function setContext(array $context): static
|
|
47
|
+
{
|
|
48
|
+
$this->context = $context;
|
|
49
|
+
|
|
50
|
+
return $this;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
public function getNextMessage($order = null):array
|
|
54
|
+
{
|
|
55
|
+
$result = array('message' => '', 'buttons' => array());
|
|
56
|
+
|
|
57
|
+
switch ($this->context['data'][0]) {
|
|
58
|
+
case 'name':
|
|
59
|
+
$result['message'] = "Материал №" . $this->context['id'] . "\r\n\r\nВведите, пожалуйста, название материала:";
|
|
60
|
+
break;
|
|
61
|
+
case 'description':
|
|
62
|
+
$result['message'] = "Материал №" . $this->context['id'] . "\r\n\r\nВведите, пожалуйста, описание материала:";
|
|
63
|
+
break;
|
|
64
|
+
case 'price':
|
|
65
|
+
$result['message'] = "Материал №" . $this->context['id'] . "\r\n\r\nВведите, пожалуйста, стоимость заказа (введите 0 для бесплатных материалов)";
|
|
66
|
+
break;
|
|
67
|
+
case 'file':
|
|
68
|
+
$result['message'] = "Материал №" . $this->context['id'] . "\r\n\r\nПрикрепите, пожалуйста, файл, который будет продаваться";
|
|
69
|
+
break;
|
|
70
|
+
case 'photo':
|
|
71
|
+
$result['message'] = "Материал №" . $this->context['id'] . "\r\n\r\nПрикрепите, пожалуйста, изображение, которое будет показываться на экране с подробностями о материале";
|
|
72
|
+
break;
|
|
73
|
+
case 'materialDelete':
|
|
74
|
+
$result['message'] = "Материал №" . $this->context['id'] . "\r\n\r\nВы точно хотите его удалить?";
|
|
75
|
+
$result['buttons'] = [
|
|
76
|
+
[['text' => "Да", 'callback_data' => json_encode(array('command' => 'materialDeleteConfirm', 'id' => $this->context['id']))], ['text' => "Нет", 'callback_data' => json_encode(array('command' => 'materialDeleteCancel', 'id' => $this->context['id']))]]
|
|
77
|
+
];
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return $result;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace App\Entity;
|
|
4
|
+
|
|
5
|
+
use App\Repository\OrderRepository;
|
|
6
|
+
use Doctrine\ORM\Mapping as ORM;
|
|
7
|
+
|
|
8
|
+
#[ORM\Entity(repositoryClass: OrderRepository::class)]
|
|
9
|
+
#[ORM\Table(name: '`order`')]
|
|
10
|
+
class Order
|
|
11
|
+
{
|
|
12
|
+
#[ORM\Id]
|
|
13
|
+
#[ORM\GeneratedValue]
|
|
14
|
+
#[ORM\Column]
|
|
15
|
+
private ?int $id = null;
|
|
16
|
+
|
|
17
|
+
#[ORM\Column]
|
|
18
|
+
private ?\DateTimeImmutable $createAt = null;
|
|
19
|
+
|
|
20
|
+
#[ORM\Column]
|
|
21
|
+
private ?int $price = null;
|
|
22
|
+
|
|
23
|
+
public function getId(): ?int
|
|
24
|
+
{
|
|
25
|
+
return $this->id;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public function getCreateAt(): ?\DateTimeImmutable
|
|
29
|
+
{
|
|
30
|
+
return $this->createAt;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
public function setCreateAt(\DateTimeImmutable $createAt): static
|
|
34
|
+
{
|
|
35
|
+
$this->createAt = $createAt;
|
|
36
|
+
|
|
37
|
+
return $this;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public function getPrice(): ?int
|
|
41
|
+
{
|
|
42
|
+
return $this->price;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public function setPrice(int $price): static
|
|
46
|
+
{
|
|
47
|
+
$this->price = $price;
|
|
48
|
+
|
|
49
|
+
return $this;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace App\Repository;
|
|
4
|
+
|
|
5
|
+
use App\Entity\Chat;
|
|
6
|
+
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
7
|
+
use Doctrine\Persistence\ManagerRegistry;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @extends ServiceEntityRepository<Chat>
|
|
11
|
+
*/
|
|
12
|
+
class ChatRepository extends ServiceEntityRepository
|
|
13
|
+
{
|
|
14
|
+
public function __construct(ManagerRegistry $registry)
|
|
15
|
+
{
|
|
16
|
+
parent::__construct($registry, Chat::class);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public function add(Chat $token, $isFlush = false): void
|
|
20
|
+
{
|
|
21
|
+
$this->getEntityManager()->persist($token);
|
|
22
|
+
|
|
23
|
+
if ($isFlush) {
|
|
24
|
+
$this->getEntityManager()->flush();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public function remove(Chat $token, $isFlush = false): void
|
|
29
|
+
{
|
|
30
|
+
$this->getEntityManager()->remove($token);
|
|
31
|
+
|
|
32
|
+
if ($isFlush) {
|
|
33
|
+
$this->getEntityManager()->flush();
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public function findWithRole()
|
|
38
|
+
{
|
|
39
|
+
return $this->createQueryBuilder('c')
|
|
40
|
+
->andWhere('c.role IS NOT NULL')
|
|
41
|
+
->orderBy('c.id', 'ASC')
|
|
42
|
+
->getQuery()
|
|
43
|
+
->getResult();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
public function findAgents()
|
|
47
|
+
{
|
|
48
|
+
return $this->createQueryBuilder('c')
|
|
49
|
+
->andWhere('c.role = :role')
|
|
50
|
+
->setParameter('role', Chat::ROLE_AGENT)
|
|
51
|
+
->orderBy('c.id', 'ASC')
|
|
52
|
+
->getQuery()
|
|
53
|
+
->getResult();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
public function findNextDiagnostics()
|
|
57
|
+
{
|
|
58
|
+
return $this->createQueryBuilder('c')
|
|
59
|
+
->andWhere('c.diagnosticAt > :now')
|
|
60
|
+
->setParameter('now', new \DateTimeImmutable())
|
|
61
|
+
->orderBy('c.diagnosticAt', 'ASC')
|
|
62
|
+
->getQuery()
|
|
63
|
+
->getResult();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public function findFreeChats() {
|
|
67
|
+
return $this->createQueryBuilder('c')
|
|
68
|
+
->andWhere('c.phone IS NOT NULL')
|
|
69
|
+
->andWhere('c.agent IS NULL')
|
|
70
|
+
->andWhere('c.role IS NULL')
|
|
71
|
+
->getQuery()
|
|
72
|
+
->getResult();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// /**
|
|
76
|
+
// * @return Chat[] Returns an array of Chat objects
|
|
77
|
+
// */
|
|
78
|
+
// public function findByExampleField($value): array
|
|
79
|
+
// {
|
|
80
|
+
// return $this->createQueryBuilder('c')
|
|
81
|
+
// ->andWhere('c.exampleField = :val')
|
|
82
|
+
// ->setParameter('val', $value)
|
|
83
|
+
// ->orderBy('c.id', 'ASC')
|
|
84
|
+
// ->setMaxResults(10)
|
|
85
|
+
// ->getQuery()
|
|
86
|
+
// ->getResult()
|
|
87
|
+
// ;
|
|
88
|
+
// }
|
|
89
|
+
|
|
90
|
+
// public function findOneBySomeField($value): ?Chat
|
|
91
|
+
// {
|
|
92
|
+
// return $this->createQueryBuilder('c')
|
|
93
|
+
// ->andWhere('c.exampleField = :val')
|
|
94
|
+
// ->setParameter('val', $value)
|
|
95
|
+
// ->getQuery()
|
|
96
|
+
// ->getOneOrNullResult()
|
|
97
|
+
// ;
|
|
98
|
+
// }
|
|
99
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace App\Repository;
|
|
4
|
+
|
|
5
|
+
use App\Entity\DialogContext;
|
|
6
|
+
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
7
|
+
use Doctrine\Persistence\ManagerRegistry;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @extends ServiceEntityRepository<DialogContext>
|
|
11
|
+
*/
|
|
12
|
+
class DialogContextRepository extends ServiceEntityRepository
|
|
13
|
+
{
|
|
14
|
+
public function __construct(ManagerRegistry $registry)
|
|
15
|
+
{
|
|
16
|
+
parent::__construct($registry, DialogContext::class);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public function add(DialogContext $token, $isFlush = false):void
|
|
20
|
+
{
|
|
21
|
+
$obj = $this->getEntityManager()->getRepository(DialogContext::class)->findOneBy(array('chat' => $token->getChat()));
|
|
22
|
+
|
|
23
|
+
if ($obj instanceof DialogContext) {
|
|
24
|
+
$this->getEntityManager()->remove($obj);
|
|
25
|
+
$this->getEntityManager()->flush();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
$this->getEntityManager()->persist($token);
|
|
29
|
+
|
|
30
|
+
if ($isFlush) {
|
|
31
|
+
$this->getEntityManager()->flush();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public function remove(DialogContext $token, $isFlush = false):void
|
|
36
|
+
{
|
|
37
|
+
$this->getEntityManager()->remove($token);
|
|
38
|
+
|
|
39
|
+
if ($isFlush) {
|
|
40
|
+
$this->getEntityManager()->flush();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// /**
|
|
45
|
+
// * @return DialogContext[] Returns an array of DialogContext objects
|
|
46
|
+
// */
|
|
47
|
+
// public function findByExampleField($value): array
|
|
48
|
+
// {
|
|
49
|
+
// return $this->createQueryBuilder('d')
|
|
50
|
+
// ->andWhere('d.exampleField = :val')
|
|
51
|
+
// ->setParameter('val', $value)
|
|
52
|
+
// ->orderBy('d.id', 'ASC')
|
|
53
|
+
// ->setMaxResults(10)
|
|
54
|
+
// ->getQuery()
|
|
55
|
+
// ->getResult()
|
|
56
|
+
// ;
|
|
57
|
+
// }
|
|
58
|
+
|
|
59
|
+
// public function findOneBySomeField($value): ?DialogContext
|
|
60
|
+
// {
|
|
61
|
+
// return $this->createQueryBuilder('d')
|
|
62
|
+
// ->andWhere('d.exampleField = :val')
|
|
63
|
+
// ->setParameter('val', $value)
|
|
64
|
+
// ->getQuery()
|
|
65
|
+
// ->getOneOrNullResult()
|
|
66
|
+
// ;
|
|
67
|
+
// }
|
|
68
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace App\Repository;
|
|
4
|
+
|
|
5
|
+
use App\Entity\Order;
|
|
6
|
+
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
7
|
+
use Doctrine\Persistence\ManagerRegistry;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @extends ServiceEntityRepository<Order>
|
|
11
|
+
*/
|
|
12
|
+
class OrderRepository extends ServiceEntityRepository
|
|
13
|
+
{
|
|
14
|
+
public function __construct(ManagerRegistry $registry)
|
|
15
|
+
{
|
|
16
|
+
parent::__construct($registry, Order::class);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// /**
|
|
20
|
+
// * @return Order[] Returns an array of Order objects
|
|
21
|
+
// */
|
|
22
|
+
// public function findByExampleField($value): array
|
|
23
|
+
// {
|
|
24
|
+
// return $this->createQueryBuilder('o')
|
|
25
|
+
// ->andWhere('o.exampleField = :val')
|
|
26
|
+
// ->setParameter('val', $value)
|
|
27
|
+
// ->orderBy('o.id', 'ASC')
|
|
28
|
+
// ->setMaxResults(10)
|
|
29
|
+
// ->getQuery()
|
|
30
|
+
// ->getResult()
|
|
31
|
+
// ;
|
|
32
|
+
// }
|
|
33
|
+
|
|
34
|
+
// public function findOneBySomeField($value): ?Order
|
|
35
|
+
// {
|
|
36
|
+
// return $this->createQueryBuilder('o')
|
|
37
|
+
// ->andWhere('o.exampleField = :val')
|
|
38
|
+
// ->setParameter('val', $value)
|
|
39
|
+
// ->getQuery()
|
|
40
|
+
// ->getOneOrNullResult()
|
|
41
|
+
// ;
|
|
42
|
+
// }
|
|
43
|
+
}
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace App\Service;
|
|
4
|
+
|
|
5
|
+
use App\Entity\Chat;
|
|
6
|
+
use App\Entity\DialogContext;
|
|
7
|
+
use App\Repository\ChatRepository;
|
|
8
|
+
use App\Repository\DialogContextRepository;
|
|
9
|
+
use Doctrine\ORM\EntityManagerInterface;
|
|
10
|
+
use Psr\Log\LoggerInterface;
|
|
11
|
+
|
|
12
|
+
class MessageProcessService
|
|
13
|
+
{
|
|
14
|
+
private ?ChatRepository $chatRepo = null;
|
|
15
|
+
private ?TelegramService $telegram = null;
|
|
16
|
+
private ?EntityManagerInterface $em = null;
|
|
17
|
+
|
|
18
|
+
private ?DialogContextRepository $dialogRepo = null;
|
|
19
|
+
private ?LoggerInterface $logger;
|
|
20
|
+
|
|
21
|
+
private $paginationCount = 1;
|
|
22
|
+
private $comission = 10;
|
|
23
|
+
|
|
24
|
+
public function __construct(EntityManagerInterface $em, ChatRepository $chatRepo, DialogContextRepository $dialogRepo, LoggerInterface $logger)
|
|
25
|
+
{
|
|
26
|
+
$this->chatRepo = $chatRepo;
|
|
27
|
+
$this->telegram = new TelegramService();
|
|
28
|
+
$this->em = $em;
|
|
29
|
+
|
|
30
|
+
$this->dialogRepo = $dialogRepo;
|
|
31
|
+
$this->logger = $logger;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public function processMessage(array $message)
|
|
35
|
+
{
|
|
36
|
+
$this->logger->info('msg', $message);
|
|
37
|
+
if (array_key_exists('message', $message)) {
|
|
38
|
+
$from = $message['message']['chat']['id'];
|
|
39
|
+
$chat = $this->chatRepo->findOneBy(array('chatId' => $from), array('id' => 'desc'));
|
|
40
|
+
$isAuth = $chat instanceof Chat && !is_null($chat->getRole());
|
|
41
|
+
|
|
42
|
+
$arr = explode(' ', array_key_exists('text', $message['message']) ? $message['message']['text'] : '');
|
|
43
|
+
|
|
44
|
+
//Comment: Это свитч для работы с командами и ручным вводом
|
|
45
|
+
switch (strtolower($arr[0])) {
|
|
46
|
+
case '/start':
|
|
47
|
+
$isInit = false;
|
|
48
|
+
if (!$chat instanceof Chat) {
|
|
49
|
+
$chat = new Chat();
|
|
50
|
+
if (array_key_exists('username', $message['message']['chat'])) $chat->setUsername($message['message']['chat']['username']);
|
|
51
|
+
if (array_key_exists('id', $message['message']['from'])) $chat->setUserId($message['message']['from']['id']);
|
|
52
|
+
$chat->setChatId($from);
|
|
53
|
+
|
|
54
|
+
$this->chatRepo->add($chat, true);
|
|
55
|
+
$isInit = true;
|
|
56
|
+
}
|
|
57
|
+
$buttons = [];
|
|
58
|
+
|
|
59
|
+
$responseText = "";
|
|
60
|
+
|
|
61
|
+
if ($isInit) $responseText = "Добрый день! Вы попали в чат для агентов компании \"Синорусс\"\r\n\r\n" .
|
|
62
|
+
"Данный бот позволит Вам удобнее предлагать нам лидов и отслежтивать статус переговоров с ними. За каждого лида будет начисляться вознаграждение, которое в дальнейшем можно будет вывести.\r\n\r\n" .
|
|
63
|
+
"Ботом могут пользоваться только авторизованные агенты. Пожалуйста, поделитесь Вашим номером телефона, используя кнопку ниже. Мы проверим, что это действительно Вы!\r\n\r\n" .
|
|
64
|
+
"Спасибо, что Вы с нами!";
|
|
65
|
+
|
|
66
|
+
$this->chatRepo->add($chat, true);
|
|
67
|
+
|
|
68
|
+
if (strlen($responseText) > 0) $resp = $this->telegram->sendMessage($responseText, $from);
|
|
69
|
+
|
|
70
|
+
if (is_null($chat->getPhone())) {
|
|
71
|
+
$resp = $this->telegram->sendKeyboardMessage("Поделиться номером телефона", $from, [
|
|
72
|
+
[['text' => 'Дать свой телефончик', 'request_contact' => true]]
|
|
73
|
+
]);
|
|
74
|
+
$this->logger->error('resp', $resp);
|
|
75
|
+
}
|
|
76
|
+
break;
|
|
77
|
+
case 'example':
|
|
78
|
+
$this->telegram->sendMessage("Fucking test", $from, [
|
|
79
|
+
[['text' => 'Ping', 'callback_data' => json_encode(array('command' => 'pong', )),]],
|
|
80
|
+
[
|
|
81
|
+
['text' => 'Ping', 'callback_data' => json_encode(array('command' => 'pong',)),],
|
|
82
|
+
['text' => 'Ping', 'callback_data' => json_encode(array('command' => 'pong', )),],
|
|
83
|
+
]
|
|
84
|
+
], ['bbLogo.png']);
|
|
85
|
+
break;
|
|
86
|
+
case 'help':
|
|
87
|
+
case '/help':
|
|
88
|
+
case '?':
|
|
89
|
+
$buttons = [];
|
|
90
|
+
if ($isAuth && $chat->getRole() === Chat::ROLE_ADMIN) {
|
|
91
|
+
$responseText = "Приветствую! Я Вас узнал) Вы из администрации Чайна Консалтинг\r\n" .
|
|
92
|
+
"1. Команда \"login <b>token</b>\" позволит Вам войти в систему, если запросите токен у Вашего администратора\r\n" .
|
|
93
|
+
"2. Чтобы посмотреть эту подсказку, нажмите в меню на пункт \"Помощь\"\r\n" .
|
|
94
|
+
"\r\nЭто все, что я хотел Вам сказать! Спасибо, что обратились ко мне!\r\n\r\n" .
|
|
95
|
+
"P.S.: бот с любовью и заботой разработан командой @yourtar";
|
|
96
|
+
$buttons[] = [['text' => '✉️ Разослать сообщение', 'callback_data' => json_encode(array('command' => 'sendingMessages', )),]];
|
|
97
|
+
} else if ($isAuth && $chat->getRole() === Chat::ROLE_AGENT) {
|
|
98
|
+
$responseText = "Приветствую! Я Вас узнал) Вы - партнер компании Чайна Консалтинг\r\n" .
|
|
99
|
+
"В данном боте Вы можете добавить новых лидов, которые заинтересованы в услугах компании Чайна Консалтинг, а также отслеживать статус переговоров с ними.\r\n" .
|
|
100
|
+
"Чтобы посмотреть эту подсказку, нажмите в меню на пункт \"Помощь\"\r\n" .
|
|
101
|
+
"\r\nЭто все, что я хотел Вам сказать! Спасибо, что обратились ко мне!\r\n\r\n" .
|
|
102
|
+
"P.S.: бот с любовью и заботой разработан командой @yourtar";
|
|
103
|
+
} else {
|
|
104
|
+
$responseText = "Приветствую, друг!\r\n\r\n" .
|
|
105
|
+
"Это бот для партнеров компании Чайна Консалтинг. Пользоваться им могут только авторизованные партнеры. Чтобы ты мог зарабатывать вместе с нами, напиши сюда: @ipvmv94\r\n\r\n" .
|
|
106
|
+
"\r\nЭто все, что я хотел Вам сказать! Спасибо, что обратились ко мне!\r\n\r\n" .
|
|
107
|
+
"P.S.: бот с любовью и заботой разработан командой @yourtar";
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
$resp = $this->telegram->sendMessage($responseText, $from, $buttons);
|
|
111
|
+
$this->logger->error('resp ', $resp);
|
|
112
|
+
break;
|
|
113
|
+
default:
|
|
114
|
+
$context = $this->dialogRepo->findOneBy(['chat' => $chat]);
|
|
115
|
+
|
|
116
|
+
if ($context instanceof DialogContext) {
|
|
117
|
+
//Comment: Это свитч для работы с контектом ввода (когда вводят ответ на вопрос бота)
|
|
118
|
+
switch ($context->getContext()['data'][0]) {
|
|
119
|
+
case 'answer':
|
|
120
|
+
if (strlen($message['message']['text']) > 2) {
|
|
121
|
+
$cd = $context->getContext();
|
|
122
|
+
$data = $context->getContext()['data'];
|
|
123
|
+
array_shift($data);
|
|
124
|
+
$cd['data'] = $data;
|
|
125
|
+
$context->setContext($cd);
|
|
126
|
+
|
|
127
|
+
$this->dialogRepo->add($context, true);
|
|
128
|
+
$this->telegram->sendMessage("Спасибо за ответ! Твое сообщение: <b>" . $message['message']['text'] . "</b>\r\n\r\nВведите ответ на вопрос 2:", $from);
|
|
129
|
+
}
|
|
130
|
+
break;
|
|
131
|
+
case 'answer2':
|
|
132
|
+
if (strlen($message['message']['text']) > 2) {
|
|
133
|
+
$this->dialogRepo->remove($context, true);
|
|
134
|
+
$this->telegram->sendMessage("Спасибо за ответ! Твое сообщение: <b>" . $message['message']['text'] . "</b>", $from);
|
|
135
|
+
}
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
} else if (array_key_exists('photo', $message['message']) && count($message['message']['photo']) > 1 && array_key_exists('media_group_id', $message['message'])) {
|
|
139
|
+
$ms = $this->em->getRepository(MessageSending::class)->findOneBy(array('photoMediaGroupId' => $message['message']['media_group_id']));
|
|
140
|
+
|
|
141
|
+
if ($ms instanceof MessageSending) {
|
|
142
|
+
$file = $this->telegram->getFile(end($message['message']['photo'])['file_id']);
|
|
143
|
+
|
|
144
|
+
$files = $ms->getImage();
|
|
145
|
+
$files[] = $file;
|
|
146
|
+
$ms->setImage($files);
|
|
147
|
+
$this->em->flush();
|
|
148
|
+
}
|
|
149
|
+
} else if (array_key_exists('document', $message['message']) && count($message['message']['document']) > 1 && array_key_exists('media_group_id', $message['message'])) {
|
|
150
|
+
$ms = $this->em->getRepository(MessageSending::class)->findOneBy(array('fileMediaGroupId' => $message['message']['media_group_id']));
|
|
151
|
+
|
|
152
|
+
if ($ms instanceof MessageSending) {
|
|
153
|
+
$file = $this->telegram->getFile($message['message']['document']['file_id']);
|
|
154
|
+
|
|
155
|
+
$files = $ms->getFiles();
|
|
156
|
+
$files[] = $file;
|
|
157
|
+
$ms->setFiles($files);
|
|
158
|
+
$this->em->flush();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
break;
|
|
162
|
+
}
|
|
163
|
+
} else if (array_key_exists('callback_query', $message)) {
|
|
164
|
+
$from = $message['callback_query']['message']['chat']['id'];
|
|
165
|
+
$chat = $this->chatRepo->findOneBy(array('chatId' => $from), array('id' => 'desc'));
|
|
166
|
+
$arr = json_decode($message['callback_query']['data'], true);
|
|
167
|
+
$isAuth = $chat instanceof Chat && !is_null($chat->getRole());
|
|
168
|
+
|
|
169
|
+
//Comment: Это свитч для работы с командами и ручным вводом
|
|
170
|
+
switch ($arr['command']) {
|
|
171
|
+
case 'pong':
|
|
172
|
+
$context = new DialogContext();
|
|
173
|
+
$context->setChat($chat);
|
|
174
|
+
$context->setContext(['data' => ['answer', 'answer2'], 'id' => 5]);
|
|
175
|
+
|
|
176
|
+
$this->dialogRepo->add($context, true);
|
|
177
|
+
|
|
178
|
+
$this->telegram->deleteMessage($message['callback_query']['message']['message_id'], $from);
|
|
179
|
+
$this->telegram->sendMessage("Введи сообщение:", $from);
|
|
180
|
+
break;
|
|
181
|
+
default:
|
|
182
|
+
break;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (array_key_exists('message', $message) && array_key_exists('contact', $message['message'])) {
|
|
187
|
+
$from = $message['message']['chat']['id'];
|
|
188
|
+
$chat = $this->chatRepo->findOneBy(array('chatId' => $from), array('id' => 'desc'));
|
|
189
|
+
$chat->setPhone($message['message']['contact']['phone_number']);
|
|
190
|
+
if ($chat->getRole() !== Chat::ROLE_ADMIN) {
|
|
191
|
+
$phone = preg_replace('/[^0-9+]/', '', $chat->getPhone());
|
|
192
|
+
$phone = substr($phone, -10);
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
$this->telegram->sendMessage("Спасибо, что поделились номером!", $from);
|
|
196
|
+
} else $this->telegram->sendMessage("Спасибо, что поделились номером! Вы уже администратор, поэтому для Вас ничего не изменилось!", $from);
|
|
197
|
+
|
|
198
|
+
$this->chatRepo->add($chat, true);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|