Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
EdnaRuIncomingMessage.php
1<?php
2
4
5use Bitrix\ImConnector\Input;
6use Bitrix\ImConnector\Library;
10
12{
13
14 public static function sendMessageToChat(array $message): void
15 {
16 $message = self::prepareMessageFields($message);
17
18 $portal = new Input($message);
19 $portal->reception();
20
21 self::confirmSendingMessage($message['internalId']);
22 }
23
24 public static function prepareMessageFields(array $messageFields): array
25 {
26 $messageFields['CONNECTOR'] = Library::ID_EDNA_WHATSAPP_CONNECTOR;
27
28 $messageFields['imSubject'] = $messageFields['subjectId'];
29 $messageFields['address'] = $messageFields['subscriber']['identifier'];
30 $messageFields['userName'] = $messageFields['userInfo']['userName'];
31 $messageFields['firstName'] = $messageFields['userInfo']['firstName'];
32 $messageFields['lastName'] = $messageFields['userInfo']['lastName'];
33 $messageFields['avatarUrl'] = $messageFields['userInfo']['avatarUrl'];
34 $messageFields['imType'] = 'whatsapp';
35
36 $messageFields['contentType'] = mb_strtolower($messageFields['messageContent']['type']);
37 if (isset($messageFields['messageContent']['text']))
38 {
39 $messageFields['text'] = Emoji::decode($messageFields['messageContent']['text']);
40 }
41
42 if (isset($messageFields['messageContent']['attachment']) && is_array($messageFields['messageContent']['attachment']))
43 {
44 $messageFields['attachmentUrl'] = $messageFields['messageContent']['attachment']['url'];
45 $messageFields['attachmentName'] = $messageFields['messageContent']['attachment']['name'];
46 }
47
48 if (isset($messageFields['messageContent']['caption']) && !is_null($messageFields['messageContent']['caption']))
49 {
50 $messageFields['caption'] = Emoji::decode($messageFields['messageContent']['caption']);
51 }
52
53 return $messageFields;
54 }
55
56 protected static function prepareBodyForSave(array $body): array
57 {
58 $body['messageContent']['text'] = Emoji::encode($body['messageContent']['text']);
59 $body['messageContent']['caption'] = Emoji::encode($body['messageContent']['caption']);
60
61 return $body;
62 }
63}
static encode($text)
Definition emoji.php:17
static decode($text)
Definition emoji.php:24
static confirmSendingMessage(int $internalId)