You are here

public function ApiClient::postMessage in Rocket.Chat 8

Same name and namespace in other branches
  1. 8.2 modules/rocket_chat_api/src/RocketChat/ApiClient.php \Drupal\rocket_chat_api\RocketChat\ApiClient::postMessage()

Send a Message to the rocketchat.

Parameters

string $roomId: Room ID.

string $channel: Channel Name.

string $text: Text.

string $alias: Alias.

string $emoji: Emoji.

string $avatar: Avatar link.

mixed $attachments: Attachments array.

Return value

array Result array

File

modules/rocket_chat_api/src/RocketChat/ApiClient.php, line 545

Class

ApiClient
Class ApiClient.

Namespace

Drupal\rocket_chat_api\RocketChat

Code

public function postMessage($roomId = NULL, $channel = NULL, $text = NULL, $alias = NULL, $emoji = NULL, $avatar = NULL, $attachments = NULL) {
  $params = [];
  if (!empty($roomId)) {
    $params['roomId'] = $roomId;
  }
  if (!empty($channel)) {
    $params['channel'] = $channel;
  }
  if (!empty($text)) {
    $params['text'] = $text;
  }
  if (!empty($alias)) {
    $params['alias'] = $alias;
  }
  if (!empty($emoji)) {
    $params['emoji'] = $emoji;
  }
  if (!empty($avatar)) {
    $params['avatar'] = $avatar;
  }
  if (!empty($attachments)) {
    $params['attachments'] = $attachments;
  }
  return $this
    ->postToRocketChat('chat.postMessage', [
    'json' => $params,
  ]);
}