Skip to content
This repository was archived by the owner on Feb 7, 2025. It is now read-only.

Commit fae1e39

Browse files
authored
Merge pull request #111 from Resident234/issue#35
resolve problem #35
2 parents a0b3380 + 6a232d7 commit fae1e39

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/classes/im/im.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,47 @@ public function notify($userId, $message, $notifyType = B24ImFields::NOTIFY_TYPE
4545
);
4646
return $fullResult;
4747
}
48+
49+
50+
/**
51+
* add a message to private/public group chats
52+
* @param int $chatId
53+
* @param $message
54+
* @param string $system
55+
* @param string $userId
56+
* @return array
57+
*/
58+
public function messageAdd($chatId = 1, $message, $system = 'N', $userId = '')
59+
{
60+
if(is_null($chatId) && empty($userId))
61+
{
62+
throw new Bitrix24Exception('chat id is null and user id is empty');
63+
}
64+
elseif(is_null($message))
65+
{
66+
throw new Bitrix24Exception('message is null');
67+
}
68+
elseif(!in_array($system, array("N", "Y"), true))
69+
{
70+
throw new Bitrix24Exception('unknown system');
71+
}
72+
73+
$arAdditionalParameters = array(
74+
'message' => $message,
75+
'system' => $system
76+
);
77+
78+
if (!empty($userId)) {
79+
$arAdditionalParameters['user_id'] = $userId;
80+
} else {
81+
$arAdditionalParameters['chat_id'] = $chatId;
82+
}
83+
84+
$fullResult = $this->client->call(
85+
'im.message.add',
86+
$arAdditionalParameters
87+
);
88+
return $fullResult;
89+
}
90+
4891
}

0 commit comments

Comments
 (0)