Skip to content

Commit

Permalink
Merge pull request #111 from Resident234/issue#35
Browse files Browse the repository at this point in the history
resolve problem #35
  • Loading branch information
mesilov committed Mar 14, 2019
2 parents a0b3380 + 6a232d7 commit fae1e39
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions src/classes/im/im.php
Expand Up @@ -45,4 +45,47 @@ public function notify($userId, $message, $notifyType = B24ImFields::NOTIFY_TYPE
);
return $fullResult;
}


/**
* add a message to private/public group chats
* @param int $chatId
* @param $message
* @param string $system
* @param string $userId
* @return array
*/
public function messageAdd($chatId = 1, $message, $system = 'N', $userId = '')
{
if(is_null($chatId) && empty($userId))
{
throw new Bitrix24Exception('chat id is null and user id is empty');
}
elseif(is_null($message))
{
throw new Bitrix24Exception('message is null');
}
elseif(!in_array($system, array("N", "Y"), true))
{
throw new Bitrix24Exception('unknown system');
}

$arAdditionalParameters = array(
'message' => $message,
'system' => $system
);

if (!empty($userId)) {
$arAdditionalParameters['user_id'] = $userId;
} else {
$arAdditionalParameters['chat_id'] = $chatId;
}

$fullResult = $this->client->call(
'im.message.add',
$arAdditionalParameters
);
return $fullResult;
}

}

0 comments on commit fae1e39

Please sign in to comment.