yourtar-cli 1.3.3 → 2.0.1

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.
Files changed (32) hide show
  1. package/bin/backTemplate/Makefile +7 -0
  2. package/bin/backTemplate/config/packages/monolog.yaml +61 -0
  3. package/bin/backTemplate/docker/config/promtail/config.yml +18 -0
  4. package/bin/backTemplate/docker/docker-compose.prod.yml +11 -0
  5. package/bin/backTemplate/docker/docker-compose.stage.yml +11 -0
  6. package/bin/backTemplate/src/Logging/YTExtraDataProcessor.php +20 -0
  7. package/bin/botTemplate/.env.dev-example +4 -2
  8. package/bin/botTemplate/.env.prod-example +4 -2
  9. package/bin/botTemplate/.env.stage-example +4 -2
  10. package/bin/botTemplate/Makefile +21 -2
  11. package/bin/botTemplate/config/packages/monolog.yaml +61 -0
  12. package/bin/botTemplate/docker/config/promtail/config.yml +18 -0
  13. package/bin/botTemplate/docker/docker-compose.prod.yml +11 -0
  14. package/bin/botTemplate/docker/docker-compose.stage.yml +11 -0
  15. package/bin/botTemplate/src/Controller/MessageController.php +74 -11
  16. package/bin/botTemplate/src/Entity/Chat.php +39 -25
  17. package/bin/botTemplate/src/Entity/DialogContext.php +1 -32
  18. package/bin/botTemplate/src/Entity/User.php +93 -0
  19. package/bin/botTemplate/src/Logging/YTExtraDataProcessor.php +20 -0
  20. package/bin/botTemplate/src/Repository/UserRepository.php +43 -0
  21. package/bin/botTemplate/src/Service/Service/MessageProcessService.php +34 -0
  22. package/bin/botTemplate/src/Service/Service/MessageThemeService/CustomMessageService.php +164 -0
  23. package/bin/botTemplate/src/Service/Service/MessageThemeService/MessageServiceTemplate.php +79 -0
  24. package/bin/botTemplate/src/Service/Service/MessageThemeService/MessageThemeInterface.php +8 -0
  25. package/bin/botTemplate/src/Service/Service/MessengerService/MaxService.php +275 -0
  26. package/bin/botTemplate/src/Service/Service/MessengerService/MessengerInterface.php +22 -0
  27. package/bin/botTemplate/src/Service/Service/MessengerService/TelegramService.php +195 -0
  28. package/bin/botTemplate/src/Service/Service/MessengerService/VkService.php +590 -0
  29. package/bin/index.js +5 -2
  30. package/package.json +1 -1
  31. package/bin/botTemplate/src/Service/MessageProcessService.php +0 -256
  32. package/bin/botTemplate/src/Service/TelegramService.php +0 -227
@@ -25,5 +25,12 @@ down:
25
25
  shell:
26
26
  cd docker && docker compose -f docker-compose.${APP_MODE}.yml run php_{{name}}_back bash
27
27
 
28
+ update:
29
+ make down
30
+ git pull
31
+ make up
32
+ sudo chmod -R 777 var/ public/
33
+ make -C ~/gateway restart
34
+
28
35
  database:
29
36
  cd docker && docker compose -f docker-compose.${APP_MODE}.yml exec mysql_{{name}}_back mysql -uroot -p$(DATABASE_PASSWORD)
@@ -0,0 +1,61 @@
1
+ monolog:
2
+ channels:
3
+ - deprecation # Deprecations are logged in the dedicated "deprecation" channel when it exists
4
+ - {{name}}
5
+
6
+ when@dev:
7
+ monolog:
8
+ handlers:
9
+ main:
10
+ type: stream
11
+ path: "%kernel.logs_dir%/%kernel.environment%.log"
12
+ level: debug
13
+ channels: ["!event"]
14
+ # uncomment to get logging in your browser
15
+ # you may have to allow bigger header sizes in your Web server configuration
16
+ #firephp:
17
+ # type: firephp
18
+ # level: info
19
+ #chromephp:
20
+ # type: chromephp
21
+ # level: info
22
+ console:
23
+ type: console
24
+ process_psr_3_messages: false
25
+ channels: ["!event", "!doctrine", "!console"]
26
+
27
+ when@test:
28
+ monolog:
29
+ handlers:
30
+ main:
31
+ type: fingers_crossed
32
+ action_level: error
33
+ handler: nested
34
+ excluded_http_codes: [404, 405]
35
+ channels: ["!event"]
36
+ nested:
37
+ type: stream
38
+ path: "%kernel.logs_dir%/%kernel.environment%.log"
39
+ level: debug
40
+
41
+ when@prod:
42
+ monolog:
43
+ handlers:
44
+ main:
45
+ type: stream
46
+ action_level: error
47
+ path: "%kernel.logs_dir%/%kernel.environment%.log"
48
+ level: error
49
+ channels: ["!event", "{{name}}"]
50
+ service_name: "{{name}}"
51
+ formatter: monolog.formatter.json
52
+ console:
53
+ type: console
54
+ process_psr_3_messages: false
55
+ channels: ["!event", "!doctrine"]
56
+ formatter: monolog.formatter.json
57
+ deprecation:
58
+ type: stream
59
+ channels: [deprecation]
60
+ path: php://stderr
61
+ formatter: monolog.formatter.json
@@ -0,0 +1,18 @@
1
+ server:
2
+ http_listen_port: 9080
3
+ grpc_listen_port: 0
4
+
5
+ positions:
6
+ filename: /tmp/positions.yaml
7
+
8
+ clients:
9
+ - url: http://monitor.inf.yourtar.ru:3100/loki/api/v1/push
10
+
11
+ scrape_configs:
12
+ - job_name: system
13
+ static_configs:
14
+ - targets:
15
+ - localhost
16
+ labels:
17
+ job: varlogs
18
+ __path__: /var/log/*log
@@ -82,6 +82,17 @@ services:
82
82
  # - {{name}}
83
83
  # restart: on-failure
84
84
 
85
+ # promtail_{{name}}:
86
+ # image: grafana/promtail:latest
87
+ # container_name: promtail_{{name}}
88
+ # restart: unless-stopped
89
+ # environment:
90
+ # TZ: "Europe/Moscow"
91
+ # volumes:
92
+ # - ../var/log:/var/log
93
+ # - ./config/promtail/config.yml:/etc/promtail/config.yml
94
+ # command: -config.file=/etc/promtail/config.yml
95
+
85
96
  networks:
86
97
  yourtar:
87
98
  external:
@@ -77,6 +77,17 @@ services:
77
77
  # networks:
78
78
  # - demo
79
79
 
80
+ # promtail_{{name}}:
81
+ # image: grafana/promtail:latest
82
+ # container_name: promtail_{{name}}
83
+ # restart: unless-stopped
84
+ # environment:
85
+ # TZ: "Europe/Moscow"
86
+ # volumes:
87
+ # - ../var/log:/var/log
88
+ # - ./config/promtail/config.yml:/etc/promtail/config.yml
89
+ # command: -config.file=/etc/promtail/config.yml
90
+
80
91
  networks:
81
92
  demo:
82
93
  external: true
@@ -0,0 +1,20 @@
1
+ <?php
2
+
3
+ namespace App\Logging;
4
+
5
+ use Monolog\Attribute\AsMonologProcessor;
6
+ use Monolog\LogRecord;
7
+ use Monolog\Processor\ProcessorInterface;
8
+
9
+ #[AsMonologProcessor]
10
+ class YTExtraDataProcessor implements ProcessorInterface
11
+ {
12
+ public function __invoke(LogRecord $record): LogRecord
13
+ {
14
+ // Add data to the 'extra' array
15
+ $record->extra['yourtar_log'] = true;
16
+ $record->extra['project'] = '{{name}}';
17
+
18
+ return $record;
19
+ }
20
+ }
@@ -16,8 +16,10 @@ DATABASE_HOST=mysql_{{name}}_back
16
16
  CORS_ALLOW_ORIGIN=^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$
17
17
  ###< nelmio/cors-bundle ###
18
18
 
19
- DEFAULT_URI="http://localhost:8000"
19
+ DEFAULT_URI=http://localhost:8000
20
20
 
21
21
  ###> Bot ###
22
- BOT_TOKEN=475749278:AAGxVLFFGiuymbuQYz-oHF_OoOIZhyxClA4
22
+ #TG_TOKEN=7590949811:AAEg62uBqmOMaatJXUaQueSnqRLujdokWNE
23
+ #VK_TOKEN=vk1.a.59H83PysK2tYXqAjWD1ZrSAPBht8B4cAiNmYfY_LHPuOgNnmcTBEEz_UHIOKu4k2zESyFHDKGAi4NJQAOztVbU5b3508ytakCGjRiGmpr5dUXrNMbGnSkHZW5uBVfHTGvYBwEjbBMQUP2SJkEXITDpUqluH5FCHCBn_b7DnarRs41QtKA_sEgsWQROJLRoNVZTvxcH4bL48BYkgldQ51lA
24
+ #MAX_TOKEN=f9LHodD0cOKr6uAZuM3uWU41JlGYUiPuRMBhWDYbj_hz_bVxQVCbbgG0vP6p2eeu5OmX7EOYHnFGPCxUaJKz
23
25
  ###< Bot ###
@@ -16,8 +16,10 @@ DATABASE_HOST=mysql_{{name}}_back
16
16
  CORS_ALLOW_ORIGIN=^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$
17
17
  ###< nelmio/cors-bundle ###
18
18
 
19
- DEFAULT_URI="http://localhost:8000"
19
+ DEFAULT_URI=http://localhost:8000
20
20
 
21
21
  ###> Bot ###
22
- BOT_TOKEN=475749278:AAGxVLFFGiuymbuQYz-oHF_OoOIZhyxClA4
22
+ #TG_TOKEN=7590949811:AAEg62uBqmOMaatJXUaQueSnqRLujdokWNE
23
+ #VK_TOKEN=vk1.a.59H83PysK2tYXqAjWD1ZrSAPBht8B4cAiNmYfY_LHPuOgNnmcTBEEz_UHIOKu4k2zESyFHDKGAi4NJQAOztVbU5b3508ytakCGjRiGmpr5dUXrNMbGnSkHZW5uBVfHTGvYBwEjbBMQUP2SJkEXITDpUqluH5FCHCBn_b7DnarRs41QtKA_sEgsWQROJLRoNVZTvxcH4bL48BYkgldQ51lA
24
+ #MAX_TOKEN=f9LHodD0cOKr6uAZuM3uWU41JlGYUiPuRMBhWDYbj_hz_bVxQVCbbgG0vP6p2eeu5OmX7EOYHnFGPCxUaJKz
23
25
  ###< Bot ###
@@ -16,8 +16,10 @@ DATABASE_HOST=mysql_{{name}}_back
16
16
  CORS_ALLOW_ORIGIN=^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$
17
17
  ###< nelmio/cors-bundle ###
18
18
 
19
- DEFAULT_URI="http://localhost:8000"
19
+ DEFAULT_URI=http://localhost:8000
20
20
 
21
21
  ###> Bot ###
22
- BOT_TOKEN=475749278:AAGxVLFFGiuymbuQYz-oHF_OoOIZhyxClA4
22
+ #TG_TOKEN=7590949811:AAEg62uBqmOMaatJXUaQueSnqRLujdokWNE
23
+ #VK_TOKEN=vk1.a.59H83PysK2tYXqAjWD1ZrSAPBht8B4cAiNmYfY_LHPuOgNnmcTBEEz_UHIOKu4k2zESyFHDKGAi4NJQAOztVbU5b3508ytakCGjRiGmpr5dUXrNMbGnSkHZW5uBVfHTGvYBwEjbBMQUP2SJkEXITDpUqluH5FCHCBn_b7DnarRs41QtKA_sEgsWQROJLRoNVZTvxcH4bL48BYkgldQ51lA
24
+ #MAX_TOKEN=f9LHodD0cOKr6uAZuM3uWU41JlGYUiPuRMBhWDYbj_hz_bVxQVCbbgG0vP6p2eeu5OmX7EOYHnFGPCxUaJKz
23
25
  ###< Bot ###
@@ -18,13 +18,22 @@ else
18
18
  endif
19
19
  cd docker && docker compose -f docker-compose.${APP_MODE}.yml exec php_{{name}}_back bin/console doctrine:database:create --if-not-exists
20
20
  cd docker && docker compose -f docker-compose.${APP_MODE}.yml exec php_{{name}}_back bin/console doctrine:migrations:migrate --no-interaction --allow-no-migration
21
+ make webhook
21
22
 
22
23
  down:
23
24
  cd docker && docker compose -f docker-compose.${APP_MODE}.yml down
25
+ make webhook-delete
24
26
 
25
27
  shell:
26
28
  cd docker && docker compose -f docker-compose.${APP_MODE}.yml run php_{{name}}_back bash
27
29
 
30
+ update:
31
+ make down
32
+ git pull
33
+ make up
34
+ sudo chmod -R 777 var/ public/
35
+ make -C ~/gateway restart
36
+
28
37
  database:
29
38
  cd docker && docker compose -f docker-compose.${APP_MODE}.yml exec mysql_{{name}}_back mysql -uroot -p$(DATABASE_PASSWORD)
30
39
 
@@ -32,7 +41,17 @@ commands:
32
41
  curl -X POST -H "Content-Type: application/json" -d "{\"commands\":[{\"command\":\"help\",\"description\":\"Помощь\"}]}" https://api.telegram.org/bot$(BOT_TOKEN)/setMyCommands
33
42
 
34
43
  webhook:
35
- curl https://api.telegram.org:443/bot$(BOT_TOKEN)/setWebhook?url=$(domain)/api/message/
44
+ ifndef TG_TOKEN
45
+ curl https://api.telegram.org:443/bot$(TG_TOKEN)/setWebhook?url=$(DEFAULT_URI)/api/message/tg
46
+ endif
47
+ ifndef MAX_TOKEN
48
+ curl -X POST "https://platform-api.max.ru/subscriptions" -H "Authorization: $(MAX_TOKEN)" -H "Content-Type: application/json" -d '{"url": "$(DEFAULT_URI)/api/message/max","update_types": ["message_created", "bot_started", "message_callback"],"secret": "your_secret"}'
49
+ endif
36
50
 
37
51
  webhook-delete:
38
- curl https://api.telegram.org:443/bot$(BOT_TOKEN)/deleteWebhook
52
+ ifndef TG_TOKEN
53
+ curl https://api.telegram.org:443/bot$(TG_TOKEN)/deleteWebhook
54
+ endif
55
+ ifndef MAX_TOKEN
56
+ curl -X DELETE "https://platform-api.max.ru/subscriptions?url=$(DEFAULT_URI)/api/message/max" -H "Authorization: $(MAX_TOKEN)"
57
+ endif
@@ -0,0 +1,61 @@
1
+ monolog:
2
+ channels:
3
+ - deprecation # Deprecations are logged in the dedicated "deprecation" channel when it exists
4
+ - {{name}}
5
+
6
+ when@dev:
7
+ monolog:
8
+ handlers:
9
+ main:
10
+ type: stream
11
+ path: "%kernel.logs_dir%/%kernel.environment%.log"
12
+ level: debug
13
+ channels: ["!event"]
14
+ # uncomment to get logging in your browser
15
+ # you may have to allow bigger header sizes in your Web server configuration
16
+ #firephp:
17
+ # type: firephp
18
+ # level: info
19
+ #chromephp:
20
+ # type: chromephp
21
+ # level: info
22
+ console:
23
+ type: console
24
+ process_psr_3_messages: false
25
+ channels: ["!event", "!doctrine", "!console"]
26
+
27
+ when@test:
28
+ monolog:
29
+ handlers:
30
+ main:
31
+ type: fingers_crossed
32
+ action_level: error
33
+ handler: nested
34
+ excluded_http_codes: [404, 405]
35
+ channels: ["!event"]
36
+ nested:
37
+ type: stream
38
+ path: "%kernel.logs_dir%/%kernel.environment%.log"
39
+ level: debug
40
+
41
+ when@prod:
42
+ monolog:
43
+ handlers:
44
+ main:
45
+ type: stream
46
+ action_level: error
47
+ path: "%kernel.logs_dir%/%kernel.environment%.log"
48
+ level: error
49
+ channels: ["!event", "{{name}}"]
50
+ service_name: "{{name}}"
51
+ formatter: monolog.formatter.json
52
+ console:
53
+ type: console
54
+ process_psr_3_messages: false
55
+ channels: ["!event", "!doctrine"]
56
+ formatter: monolog.formatter.json
57
+ deprecation:
58
+ type: stream
59
+ channels: [deprecation]
60
+ path: php://stderr
61
+ formatter: monolog.formatter.json
@@ -0,0 +1,18 @@
1
+ server:
2
+ http_listen_port: 9080
3
+ grpc_listen_port: 0
4
+
5
+ positions:
6
+ filename: /tmp/positions.yaml
7
+
8
+ clients:
9
+ - url: http://monitor.inf.yourtar.ru:3100/loki/api/v1/push
10
+
11
+ scrape_configs:
12
+ - job_name: system
13
+ static_configs:
14
+ - targets:
15
+ - localhost
16
+ labels:
17
+ job: varlogs
18
+ __path__: /var/log/*log
@@ -82,6 +82,17 @@ services:
82
82
  # - {{name}}
83
83
  # restart: on-failure
84
84
 
85
+ # promtail_{{name}}:
86
+ # image: grafana/promtail:latest
87
+ # container_name: promtail_{{name}}
88
+ # restart: unless-stopped
89
+ # environment:
90
+ # TZ: "Europe/Moscow"
91
+ # volumes:
92
+ # - ../var/log:/var/log
93
+ # - ./config/promtail/config.yml:/etc/promtail/config.yml
94
+ # command: -config.file=/etc/promtail/config.yml
95
+
85
96
  networks:
86
97
  yourtar:
87
98
  external:
@@ -77,6 +77,17 @@ services:
77
77
  # networks:
78
78
  # - demo
79
79
 
80
+ # promtail_{{name}}:
81
+ # image: grafana/promtail:latest
82
+ # container_name: promtail_{{name}}
83
+ # restart: unless-stopped
84
+ # environment:
85
+ # TZ: "Europe/Moscow"
86
+ # volumes:
87
+ # - ../var/log:/var/log
88
+ # - ./config/promtail/config.yml:/etc/promtail/config.yml
89
+ # command: -config.file=/etc/promtail/config.yml
90
+
80
91
  networks:
81
92
  demo:
82
93
  external: true
@@ -2,19 +2,15 @@
2
2
 
3
3
  namespace App\Controller;
4
4
 
5
- use App\Entity\Chat;
6
- use App\Entity\Lead;
7
- use App\Entity\Token;
8
- use App\Repository\ChatRepository;
9
- use App\Repository\PaymentRepository;
10
- use App\Repository\TokenRepository;
11
5
  use App\Service\MessageProcessService;
12
- use App\Service\TelegramService;
6
+ use App\Service\MessengerService\MaxService;
7
+ use App\Service\MessengerService\TelegramService;
8
+ use App\Service\MessengerService\VkService;
13
9
  use Psr\Log\LoggerInterface;
14
- use Doctrine\ORM\EntityManagerInterface;
15
10
  use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
16
11
  use Symfony\Component\HttpFoundation\JsonResponse;
17
12
  use Symfony\Component\HttpFoundation\Request;
13
+ use Symfony\Component\HttpFoundation\Response;
18
14
  use Symfony\Component\Routing\Attribute\Route;
19
15
 
20
16
  #[Route('/api/message')]
@@ -26,14 +22,81 @@ final class MessageController extends AbstractController
26
22
  {
27
23
  $this->messageService = $messageService;
28
24
  }
29
-
30
- #[Route('/', name: 'app_message_webhook')]
25
+
26
+ #[Route('/tg', name: 'app_message_webhook_tg')]
31
27
  public function index(Request $request): JsonResponse
32
28
  {
33
29
  $value = json_decode($request->getContent(), true);
34
30
 
35
- $this->messageService->processMessage($value);
31
+ $result = $this->messageService->processMessage(new TelegramService()->normalizeMessage($value));
32
+ if (!$result) return $this->json(['error' => true], 500);
33
+
34
+ return $this->json(['message' => 'OK',]);
35
+ }
36
+
37
+ // #[Route('/tg/{id}', name: 'app_message_webhook_tg_for_bot')]
38
+ // public function tgWebhookForOrg($id, Request $request): JsonResponse
39
+ // {
40
+ // $value = json_decode($request->getContent(), true);
41
+ //
42
+ // //TODO: доделать для бота
43
+ // $result = $this->messageService->processMessage(new TelegramService()->normalizeMessage($value));
44
+ // if (!$result) return $this->json(['error' => true], 500);
45
+ //
46
+ // return $this->json(['message' => 'OK',]);
47
+ // }
48
+
49
+ #[Route('/vk', name: 'app_message_webhook_vk', methods: 'post')]
50
+ public function vkWebhook(Request $request, LoggerInterface $logger)
51
+ {
52
+ $data = json_decode($request->getContent(), true);
53
+ $logger->error('VK: ' . $request->getContent());
54
+
55
+ if (array_key_exists('type', $data) && ($data['type'] === 'message_new' || $data['type'] === 'message_event')) {
56
+ $result = $this->messageService->processMessage(new VkService()->normalizeMessage($data));
57
+ if (!$result) return $this->json(['error' => true], 500);
58
+ }
59
+
60
+ if ($data['type'] === 'confirmation') return new Response('8e9b12dd');
61
+ return new Response('ok');
62
+ }
63
+
64
+ // #[Route('/vk/{id}', name: 'app_message_webhook_vk_for_bot', methods: 'post')]
65
+ // public function vkWebhookForBot($id, Request $request)
66
+ // {
67
+ // $data = json_decode($request->getContent(), true);
68
+ //
69
+ // //TODO: доделать для бота
70
+ // if (array_key_exists('type', $data) && ($data['type'] === 'message_new' || $data['type'] === 'message_event')) {
71
+ // $result = $this->messageService->processMessage(new VkService()->normalizeMessage($data));
72
+ // if (!$result) return $this->json(['error' => true], 500);
73
+ // }
74
+ //
75
+ // if ($data['type'] === 'confirmation') return new Response('b852d1d2');
76
+ // return new Response('ok');
77
+ // }
78
+
79
+ #[Route('/max', name: 'app_message_webhook_max')]
80
+ public function max(Request $request, LoggerInterface $logger): JsonResponse
81
+ {
82
+ $data = json_decode($request->getContent(), true);
83
+ // $logger->error('LOG MES ' . $request->getContent());
84
+ $data = new MaxService()->normalizeMessage($data);
85
+ $result = $this->messageService->processMessage($data);
86
+ if (!$result) return $this->json(['error' => true], 500);
36
87
 
37
88
  return $this->json(['message' => 'OK',]);
38
89
  }
90
+
91
+ // #[Route('/max', name: 'app_message_webhook_max_for_bot')]
92
+ // public function maxForBot(Request $request): JsonResponse
93
+ // {
94
+ // $data = json_decode($request->getContent(), true);
95
+ // //TODO: доделать для бота
96
+ // $data = new MaxService()->normalizeData($data);
97
+ // $result = $this->messageService->processMessage($data);
98
+ // if (!$result) return $this->json(['error' => true], 500);
99
+ //
100
+ // return $this->json(['message' => 'OK',]);
101
+ // }
39
102
  }
@@ -3,13 +3,18 @@
3
3
  namespace App\Entity;
4
4
 
5
5
  use App\Repository\ChatRepository;
6
+ use App\Service\MessengerService\MaxService;
7
+ use App\Service\MessengerService\TelegramService;
8
+ use App\Service\MessengerService\VkService;
6
9
  use Doctrine\DBAL\Types\Types;
7
10
  use Doctrine\ORM\Mapping as ORM;
8
11
 
9
12
  #[ORM\Entity(repositoryClass: ChatRepository::class)]
10
13
  class Chat
11
14
  {
12
-
15
+ public const TYPE_TG = 'telegram';
16
+ public const TYPE_VK = 'vkontakte';
17
+ public const TYPE_MAX = 'max';
13
18
  public const ROLE_ADMIN = 'admin';
14
19
 
15
20
  #[ORM\Id]
@@ -20,18 +25,22 @@ class Chat
20
25
  #[ORM\Column(length: 255)]
21
26
  private ?string $chatId = null;
22
27
 
23
- #[ORM\Column(length: 255)]
28
+ #[ORM\Column(name: 'messenger_user_id', length: 255)]
24
29
  private ?string $userId = null;
25
30
 
26
- #[ORM\Column(length: 255, nullable: true)]
27
- private ?string $role = null;
28
-
29
31
  #[ORM\Column(length: 255, nullable: true)]
30
32
  private ?string $username = null;
31
33
 
32
34
  #[ORM\Column(length: 255, nullable: true)]
33
35
  private ?string $phone = null;
34
36
 
37
+ #[ORM\Column(length: 255)]
38
+ private ?string $type = null;
39
+
40
+ #[ORM\ManyToOne(inversedBy: 'chats')]
41
+ #[ORM\JoinColumn(nullable: false)]
42
+ private ?User $user = null;
43
+
35
44
  public function getId(): ?int
36
45
  {
37
46
  return $this->id;
@@ -61,51 +70,56 @@ class Chat
61
70
  return $this;
62
71
  }
63
72
 
64
- public function getRole(): ?string
73
+ public function getUsername(): ?string
65
74
  {
66
- return $this->role;
75
+ return $this->username;
67
76
  }
68
77
 
69
- public function getRoleName(): ?string
78
+ public function setUsername(?string $username): static
70
79
  {
71
- $role = 'Роль отсутствует!';
80
+ $this->username = $username;
72
81
 
73
- switch ($this->role) {
74
- case self::ROLE_ADMIN:
75
- $role = 'Администратор (может все)';
76
- break;
77
- }
82
+ return $this;
83
+ }
78
84
 
79
- return $role;
85
+ public function getPhone(): ?string
86
+ {
87
+ return $this->phone;
80
88
  }
81
89
 
82
- public function setRole(?string $role): static
90
+ public function setPhone(?string $phone): static
83
91
  {
84
- $this->role = $role;
92
+ $this->phone = $phone;
85
93
 
86
94
  return $this;
87
95
  }
88
96
 
89
- public function getUsername(): ?string
97
+ public function getMessenger() {
98
+ if ($this->type === self::TYPE_MAX) return new MaxService($this);
99
+ if ($this->type === self::TYPE_VK) return new VkService($this);
100
+ if ($this->type === self::TYPE_TG) return new TelegramService($this);
101
+ }
102
+
103
+ public function getType(): ?string
90
104
  {
91
- return $this->username;
105
+ return $this->type;
92
106
  }
93
107
 
94
- public function setUsername(?string $username): static
108
+ public function setType(string $type): static
95
109
  {
96
- $this->username = $username;
110
+ $this->type = $type;
97
111
 
98
112
  return $this;
99
113
  }
100
114
 
101
- public function getPhone(): ?string
115
+ public function getUser(): ?User
102
116
  {
103
- return $this->phone;
117
+ return $this->user;
104
118
  }
105
119
 
106
- public function setPhone(?string $phone): static
120
+ public function setUser(?User $user): static
107
121
  {
108
- $this->phone = $phone;
122
+ $this->user = $user;
109
123
 
110
124
  return $this;
111
125
  }
@@ -18,7 +18,7 @@ class DialogContext
18
18
  #[ORM\JoinColumn(nullable: false)]
19
19
  private ?Chat $chat = null;
20
20
 
21
- #[ORM\Column(type: Types::SIMPLE_ARRAY)]
21
+ #[ORM\Column(type: Types::JSON)]
22
22
  private array $context = [];
23
23
 
24
24
  public function getId(): ?int
@@ -49,35 +49,4 @@ class DialogContext
49
49
 
50
50
  return $this;
51
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
52
  }