Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
BotService.php
1<?php
2
4
5use Bitrix\Im;
8use Bitrix\Im\V2\Common\ContextCustomer;
10
12{
13 use ContextCustomer;
14
15 private SendingConfig $sendingConfig;
16
20 public function __construct(?SendingConfig $sendingConfig = null)
21 {
22 if ($sendingConfig === null)
23 {
24 $sendingConfig = new SendingConfig();
25 }
26 $this->sendingConfig = $sendingConfig;
27 }
28
34 public function runMessageCommand(Chat $chat, Message $message): void
35 {
36 $arFields = array_merge(
37 $message->toArray(),
38 $this->sendingConfig->toArray(),
39 [
40 'FROM_USER_ID' => $message->getAuthorId(),
41 'TO_USER_ID' => $chat->getType() == Chat::IM_TYPE_PRIVATE ? $chat->getOpponentId() : 0,
42 'BOT_IN_CHAT' => $chat->getType() != Chat::IM_TYPE_PRIVATE ? $chat->getBotInChat() : [],
43 'MESSAGE_TYPE' => $chat->getType(),
44 'CHAT_ENTITY_TYPE' => $chat->getEntityType(),
45 'COMMAND_CONTEXT' => 'TEXTAREA',
46 ]
47 );
48 $result = Im\Command::onCommandAdd($message->getMessageId(), $arFields);
49 if (!$result)
50 {
51 Im\Bot::onMessageAdd($message->getMessageId(), $arFields);
52 }
53 }
54}
static getType($chatData)
Definition chat.php:41
runMessageCommand(Chat $chat, Message $message)
__construct(?SendingConfig $sendingConfig=null)
const IM_TYPE_PRIVATE
Definition Chat.php:55